Completed
Pull Request — master (#17)
by Tim
03:58
created

initializeAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 23
c 0
b 0
f 0
ccs 0
cts 12
cp 0
rs 9.0856
cc 2
eloc 9
nc 2
nop 1
crap 6
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
    public function initializeAttribute(array $attr)
45
    {
46
47
        // load the supported backend types
48
        $backendTypes = $this->getBackendTypes();
49
50
        // initialize the persist method for the found backend type
51
        list (, $loadMethod) = $backendTypes[$this->getBackendType()];
52
53
        // load store/entity/attribute ID
54
        $storeId = $attr[MemberNames::STORE_ID];
55
        $entityId = $attr[MemberNames::ENTITY_ID];
56
        $attributeId = $attr[MemberNames::ATTRIBUTE_ID];
57
58
        // try to load the attribute with the passed entity/attribute/store ID
59
        // and merge it with the attributes
60
        if ($entity = $this->$loadMethod($entityId, $attributeId, $storeId)) {
61
            return $this->mergeEntity($entity, $attr);
62
        }
63
64
        // otherwise simply return the attributes
65
        return $attr;
66
    }
67
68
    /**
69
     * Load's and return's the datetime attribute with the passed entity/attribute/store ID.
70
     *
71
     * @param integer $entityId    The entity ID of the attribute
72
     * @param integer $attributeId The attribute ID of the attribute
73
     * @param integer $storeId     The store ID of the attribute
74
     *
75
     * @return array|null The datetime attribute
76
     */
77
    public function loadProductDatetimeAttribute($entityId, $attributeId, $storeId)
78
    {
79
        return $this->getSubject()->loadProductDatetimeAttribute($entityId, $attributeId, $storeId);
80
    }
81
82
    /**
83
     * Load's and return's the decimal attribute with the passed entity/attribute/store ID.
84
     *
85
     * @param integer $entityId    The entity ID of the attribute
86
     * @param integer $attributeId The attribute ID of the attribute
87
     * @param integer $storeId     The store ID of the attribute
88
     *
89
     * @return array|null The decimal attribute
90
     */
91
    public function loadProductDecimalAttribute($entityId, $attributeId, $storeId)
92
    {
93
        return $this->getSubject()->loadProductDecimalAttribute($entityId, $attributeId, $storeId);
94
    }
95
96
    /**
97
     * Load's and return's the integer attribute with the passed entity/attribute/store ID.
98
     *
99
     * @param integer $entityId    The entity ID of the attribute
100
     * @param integer $attributeId The attribute ID of the attribute
101
     * @param integer $storeId     The store ID of the attribute
102
     *
103
     * @return array|null The integer attribute
104
     */
105
    public function loadProductIntAttribute($entityId, $attributeId, $storeId)
106
    {
107
        return $this->getSubject()->loadProductIntAttribute($entityId, $attributeId, $storeId);
108
    }
109
110
    /**
111
     * Load's and return's the text attribute with the passed entity/attribute/store ID.
112
     *
113
     * @param integer $entityId    The entity ID of the attribute
114
     * @param integer $attributeId The attribute ID of the attribute
115
     * @param integer $storeId     The store ID of the attribute
116
     *
117
     * @return array|null The text attribute
118
     */
119
    public function loadProductTextAttribute($entityId, $attributeId, $storeId)
120
    {
121
        return $this->getSubject()->loadProductTextAttribute($entityId, $attributeId, $storeId);
122
    }
123
124
    /**
125
     * Load's and return's the varchar attribute with the passed entity/attribute/store ID.
126
     *
127
     * @param integer $entityId    The entity ID of the attribute
128
     * @param integer $attributeId The attribute ID of the attribute
129
     * @param integer $storeId     The store ID of the attribute
130
     *
131
     * @return array|null The varchar attribute
132
     */
133
    public function loadProductVarcharAttribute($entityId, $attributeId, $storeId)
134
    {
135
        return $this->getSubject()->loadProductVarcharAttribute($entityId, $attributeId, $storeId);
136
    }
137
}
138