1 | <?php |
||
34 | class CatalogAttributeUpdateObserver extends CatalogAttributeObserver |
||
35 | { |
||
36 | |||
37 | /** |
||
38 | * Initialize the attribute with the passed attributes and returns an instance. |
||
39 | * |
||
40 | * @param array $attr The attribute attributes |
||
41 | * |
||
42 | * @return array The initialized attribute |
||
43 | */ |
||
44 | 2 | protected function initializeAttribute(array $attr) |
|
45 | { |
||
46 | |||
47 | // try to load the EAV catalog attribute with the attribute code |
||
48 | 2 | if ($attribute = $this->loadCatalogAttribute($attr[MemberNames::ATTRIBUTE_ID])) { |
|
49 | // unserialize the additional data value if available |
||
50 | 2 | if (is_array($attribute[MemberNames::ADDITIONAL_DATA]) && $attribute[MemberNames::ADDITIONAL_DATA] !== null) { |
|
51 | // merge the additional data if available |
||
52 | $attribute[MemberNames::ADDITIONAL_DATA] = array_merge( |
||
53 | $attr[MemberNames::ADDITIONAL_DATA], |
||
54 | json_decode($attribute[MemberNames::ADDITIONAL_DATA]) |
||
55 | ); |
||
56 | 2 | } elseif (!is_array($attribute[MemberNames::ADDITIONAL_DATA]) && $attribute[MemberNames::ADDITIONAL_DATA] !== null) { |
|
57 | // unserialize and override the additional data |
||
58 | 2 | $attribute[MemberNames::ADDITIONAL_DATA] = json_decode($attribute[MemberNames::ADDITIONAL_DATA]); |
|
59 | 2 | } else { |
|
60 | // nothing here |
||
61 | } |
||
62 | |||
63 | // merge the attributes into the entity |
||
64 | 2 | return $this->serializeAdditionalData($this->mergeEntity($attribute, $attr)); |
|
65 | } |
||
66 | |||
67 | // serialize the additional data and return the attributes |
||
68 | return parent::initializeAttribute($attr); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Load's and return's the EAV catalog attribute with the passed attribute ID. |
||
73 | * |
||
74 | * @param string $attributeId The ID of the EAV catalog attribute to load |
||
75 | * |
||
76 | * @return array The EAV catalog attribute |
||
77 | */ |
||
78 | 2 | protected function loadCatalogAttribute($attributeId) |
|
82 | } |
||
83 |