Completed
Push — master ( e5b919...026cf7 )
by Tim
05:11
created

EeMediaGalleryObserver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 45
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A prepareProductMediaGalleryValueToEntityAttributes() 0 11 1
A mapParentSku() 0 4 1
A mapSkuToRowId() 0 4 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Media\Ee\Observers\EeMediaGalleryObserver
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-product-media-ee
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Media\Ee\Observers;
22
23
use TechDivision\Import\Product\Media\Observers\MediaGalleryObserver;
24
use TechDivision\Import\Product\Media\Ee\Utils\MemberNames;
25
26
/**
27
 * Observer that provides extended mapping functionality to map a SKU to a row ID (EE Feature).
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2016 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/techdivision/import-product-media-ee
33
 * @link      http://www.techdivision.com
34
 */
35
class EeMediaGalleryObserver extends MediaGalleryObserver
36
{
37
38
    /**
39
     * Prepare the product media gallery value to entity that has to be persisted.
40
     *
41
     * @return array The prepared product media gallery value to entity attributes
42
     */
43
    protected function prepareProductMediaGalleryValueToEntityAttributes()
44
    {
45
46
        // initialize and return the entity
47
        return $this->initializeEntity(
48
            array(
49
                MemberNames::VALUE_ID  => $this->valueId,
50
                MemberNames::ROW_ID    => $this->parentId
51
            )
52
        );
53
    }
54
55
    /**
56
     * Map's the passed SKU of the parent product to it's PK.
57
     *
58
     * @param string $parentSku The SKU of the parent product
59
     *
60
     * @return integer The primary key used to create relations
61
     */
62
    protected function mapParentSku($parentSku)
63
    {
64
        return $this->mapSkuToRowId($parentSku);
65
    }
66
67
    /**
68
     * Return the row ID for the passed SKU.
69
     *
70
     * @param string $sku The SKU to return the row ID for
71
     *
72
     * @return integer The mapped row ID
73
     * @throws \Exception Is thrown if the SKU is not mapped yet
74
     */
75
    protected function mapSkuToRowId($sku)
76
    {
77
        return $this->getSubject()->mapSkuToRowId($sku);
78
    }
79
}
80