1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Attribute\Observers\AttributeUpdateObserver |
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 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 AttributeUpdateObserver extends AttributeObserver |
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
|
|
|
protected function initializeAttribute(array $attr) |
45
|
|
|
{ |
46
|
|
|
|
47
|
|
|
// try to load the EAV attribute with the attribute code |
48
|
|
|
if ($attribute = $this->loadAttributeByAttributeCode($attr[MemberNames::ATTRIBUTE_CODE])) { |
49
|
|
|
return $this->mergeEntity($attribute, $attr); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
// simply return the attributes |
53
|
|
|
return $attr; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Load's and return's the EAV attribute with the passed code. |
58
|
|
|
* |
59
|
|
|
* @param string $attributeCode The code of the EAV attribute to load |
60
|
|
|
* |
61
|
|
|
* @return array The EAV attribute |
62
|
|
|
*/ |
63
|
|
|
protected function loadAttributeByAttributeCode($attributeCode) |
64
|
|
|
{ |
65
|
|
|
return $this->getAttributeBunchProcessor()->loadAttributeByAttributeCode($attributeCode); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|