1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Attribute\Set\Observers\AttributeGroupUpdateObserver |
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 add/update's the EAV attribute group itself. |
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 AttributeGroupUpdateObserver extends AttributeGroupObserver |
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 initializeAttribute(array $attr) |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
// load the entity type code |
42
|
|
|
$entityTypeCode = $this->getEntityTypeCode(); |
43
|
|
|
|
44
|
|
|
// load the last attribute set name |
45
|
|
|
$attributeSet = $this->getLastAttributeSet(); |
46
|
|
|
$attributeSetName = $attributeSet[MemberNames::ATTRIBUTE_SET_NAME]; |
47
|
|
|
|
48
|
|
|
// load the attribute group name |
49
|
|
|
$attributeGroupName = $attr[MemberNames::ATTRIBUTE_GROUP_NAME]; |
50
|
|
|
|
51
|
|
|
// query whether or not an EAV attribute group with the given params already exists |
52
|
|
|
if ($entity = $this->loadAttributeGroupByEntityTypeCodeAndAttributeSetNameAndAttributeGroupName($entityTypeCode, $attributeSetName, $attributeGroupName)) { |
53
|
|
|
return $this->mergeEntity($entity, $attr); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// if not, simply return the attributes |
57
|
|
|
return $attr; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Return's the EAV attribute group with the passed entity type code, attribute set and attribute group name. |
62
|
|
|
* |
63
|
|
|
* @param string $entityTypeCode The entity type code of the EAV attribute group to return |
64
|
|
|
* @param string $attributeSetName The attribute set name of the EAV attribute group to return |
65
|
|
|
* @param string $attributeGroupName The attribute group name of the EAV attribute group to return |
66
|
|
|
* |
67
|
|
|
* @return array The EAV attribute group |
68
|
|
|
*/ |
69
|
|
|
protected function loadAttributeGroupByEntityTypeCodeAndAttributeSetNameAndAttributeGroupName($entityTypeCode, $attributeSetName, $attributeGroupName) |
70
|
|
|
{ |
71
|
|
|
return $this->getAttributeSetBunchProcessor()->loadAttributeGroupByEntityTypeCodeAndAttributeSetNameAndAttributeGroupName($entityTypeCode, $attributeSetName, $attributeGroupName); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|