1 | <?php |
||
2 | |||
3 | /** |
||
4 | * TechDivision\Import\Attribute\Set\Observers\CopyParentAttributeSetUpdateObserver |
||
5 | * |
||
6 | * PHP version 7 |
||
7 | * |
||
8 | * @author Tim Wagner <[email protected]> |
||
9 | * @copyright 2019 TechDivision GmbH <[email protected]> |
||
10 | * @license https://opensource.org/licenses/MIT |
||
11 | * @link https://github.com/techdivision/import-attribute-set |
||
12 | * @link http://www.techdivision.com |
||
13 | */ |
||
14 | |||
15 | namespace TechDivision\Import\Attribute\Set\Observers; |
||
16 | |||
17 | use TechDivision\Import\Attribute\Set\Utils\MemberNames; |
||
18 | |||
19 | /** |
||
20 | * Observer that copies the EAV attribute groups and attribute relations from the parent in update mode. |
||
21 | * |
||
22 | * @author Tim Wagner <[email protected]> |
||
23 | * @copyright 2019 TechDivision GmbH <[email protected]> |
||
24 | * @license https://opensource.org/licenses/MIT |
||
25 | * @link https://github.com/techdivision/import-attribute-set |
||
26 | * @link http://www.techdivision.com |
||
27 | */ |
||
28 | class CopyParentAttributeSetUpdateObserver extends CopyParentAttributeSetObserver |
||
29 | { |
||
30 | |||
31 | /** |
||
32 | * Initialize the attribute with the passed attributes and returns an instance. |
||
33 | * |
||
34 | * @param array $attr The attribute attributes |
||
35 | * |
||
36 | * @return array The initialized attribute |
||
37 | */ |
||
38 | protected function initializeAttributeForAttributeGroup(array $attr) |
||
39 | { |
||
40 | |||
41 | // load the attribute set + attribute group code |
||
42 | $attributeSetId = $attr[MemberNames::ATTRIBUTE_SET_ID]; |
||
43 | $attributeGroupCode = $attr[MemberNames::ATTRIBUTE_GROUP_CODE]; |
||
44 | |||
45 | // load the attribute group entity |
||
46 | if ($entity = $this->loadAttributeGroupByAttributeSetIdAndAttributeGroupCode($attributeSetId, $attributeGroupCode)) { |
||
47 | return $this->mergeEntity($entity, $attr); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
48 | } |
||
49 | |||
50 | // simply return the attributes |
||
51 | return $attr; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Initialize the attribute with the passed attributes and returns an instance. |
||
56 | * |
||
57 | * @param array $attr The attribute attributes |
||
58 | * |
||
59 | * @return array The initialized attribute |
||
60 | */ |
||
61 | protected function initializeAttributeForEntityAttribute(array $attr) |
||
62 | { |
||
63 | |||
64 | // load the attribute + attribute set ID from the passed attributes |
||
65 | $attributeId = $attr[MemberNames::ATTRIBUTE_ID]; |
||
66 | $attributeSetId = $attr[MemberNames::ATTRIBUTE_SET_ID]; |
||
67 | |||
68 | // load the attribute entity attribute |
||
69 | if ($entity = $this->loadEntityAttributeByAttributeIdAndAttributeSetId($attributeId, $attributeSetId)) { |
||
70 | return $this->mergeEntity($entity, $attr); |
||
71 | } |
||
72 | |||
73 | // simply return the attributes |
||
74 | return $attr; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Return's the EAV entity attribute with the passed attribute and attribute set ID. |
||
79 | * |
||
80 | * @param integer $attributeId The ID of the EAV entity attribute's attribute to return |
||
81 | * @param integer $attributeSetId The ID of the EAV entity attribute's attribute set to return |
||
82 | * |
||
83 | * @return array The EAV entity attribute |
||
84 | */ |
||
85 | protected function loadEntityAttributeByAttributeIdAndAttributeSetId($attributeId, $attributeSetId) |
||
86 | { |
||
87 | return $this->getAttributeSetBunchProcessor()->loadEntityAttributeByAttributeIdAndAttributeSetId($attributeId, $attributeSetId); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Return's the attribute group for the passed attribute set ID and attribute group code. |
||
92 | * |
||
93 | * @param integer $attributeSetId The EAV attribute set ID to return the attribute group for |
||
94 | * @param string $attributeGroupCode The EAV attribute group code to load the attribute group for |
||
95 | * |
||
96 | * @return array|boolean The EAV attribute group for the passed attribute set ID and attribute group code |
||
97 | */ |
||
98 | protected function loadAttributeGroupByAttributeSetIdAndAttributeGroupCode($attributeSetId, $attributeGroupCode) |
||
99 | { |
||
100 | return $this->getAttributeSetBunchProcessor()->loadAttributeGroupByAttributeSetIdAndAttributeGroupCode($attributeSetId, $attributeGroupCode); |
||
101 | } |
||
102 | } |
||
103 |