Completed
Pull Request — master (#114)
by Tim
10:48
created

ProductAttributeUpdateObserver::loadDatetimeAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Observers\ProductAttributeUpdateObserver
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
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Observers;
22
23
use TechDivision\Import\Product\Utils\MemberNames;
24
25
/**
26
 * Observer that creates/updates the product's attributes.
27
 *
28
 * @author    Tim Wagner <[email protected]>
29
 * @copyright 2016 TechDivision GmbH <[email protected]>
30
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
 * @link      https://github.com/techdivision/import-product
32
 * @link      http://www.techdivision.com
33
 */
34
class ProductAttributeUpdateObserver extends ProductAttributeObserver
35
{
36
37
    /**
38
     * Initialize the category product with the passed attributes and returns an instance.
39
     *
40
     * @param array $attr The category product attributes
41
     *
42
     * @return array The initialized category product
43
     */
44
    protected function initializeAttribute(array $attr)
45
    {
46
47
        // try to load the attribute with the passed attribute ID and merge it with the attributes
48
        if (isset($this->attributes[$attributeId = (integer) $attr[MemberNames::ATTRIBUTE_ID]])) {
49
            return $this->mergeEntity($this->attributes[$attributeId], $attr);
50
        }
51
52
        // otherwise simply return the attributes
53
        return $attr;
54
    }
55
56
    /**
57
     * Intializes the existing attributes for the entity with the passed primary key.
58
     *
59
     * @param string  $pk      The primary key of the entity to load the attributes for
60
     * @param integer $storeId The ID of the store view to load the attributes for
61
     *
62
     * @return array The entity attributes
63
     */
64
    protected function getAttributesByPrimaryKeyAndStoreId($pk, $storeId)
65
    {
66
        $this->attributes = $this->getProductBunchProcessor()->getProductAttributesByPrimaryKeyAndStoreId($pk, $storeId);
67
    }
68
}
69