1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Attribute\Observers\CatalogAttributeUpdateObserver |
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-attribute |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Attribute\Observers; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Attribute\Utils\MemberNames; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Observer that add/update's the EAV catalog attribute itself. |
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-attribute |
32
|
|
|
* @link http://www.techdivision.com |
33
|
|
|
*/ |
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
|
|
|
unserialize($attribute[MemberNames::ADDITIONAL_DATA]) |
55
|
|
|
); |
56
|
|
|
|
57
|
2 |
|
} elseif (!is_array($attribute[MemberNames::ADDITIONAL_DATA]) && $attribute[MemberNames::ADDITIONAL_DATA] !== null) { |
58
|
|
|
// unserialize and override the additional data |
59
|
2 |
|
$attribute[MemberNames::ADDITIONAL_DATA] = unserialize($attribute[MemberNames::ADDITIONAL_DATA]); |
60
|
|
|
} else { |
|
|
|
|
61
|
|
|
// nothing here |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// merge the attributes into the entity |
65
|
2 |
|
return $this->serializeAdditionalData($this->mergeEntity($attribute, $attr)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
// serialize the additional data and return the attributes |
69
|
|
|
return parent::initializeAttribute($attr); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Load's and return's the EAV catalog attribute with the passed attribute ID. |
74
|
|
|
* |
75
|
|
|
* @param string $attributeId The ID of the EAV catalog attribute to load |
76
|
|
|
* |
77
|
|
|
* @return array The EAV catalog attribute |
78
|
|
|
*/ |
79
|
2 |
|
protected function loadCatalogAttribute($attributeId) |
80
|
|
|
{ |
81
|
2 |
|
return $this->getAttributeBunchProcessor()->loadCatalogAttribute($attributeId); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
This check looks for the
else
branches ofif
statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
else
branches can be removed.could be turned into
This is much more concise to read.