1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Product\Variant\Observers\VariantSuperAttributeUpdateObserver |
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-product-variant |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Product\Variant\Observers; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Product\Variant\Utils\TableNames; |
24
|
|
|
use TechDivision\Import\Product\Variant\Utils\MemberNames; |
25
|
|
|
use TechDivision\Import\Product\Variant\Utils\EntityTypeCodes; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Oberserver that provides functionality for the product variant super attribute labels add/update operation. |
29
|
|
|
* |
30
|
|
|
* @author Tim Wagner <[email protected]> |
31
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
33
|
|
|
* @link https://github.com/techdivision/import-product-variant |
34
|
|
|
* @link http://www.techdivision.com |
35
|
|
|
*/ |
36
|
|
|
class VariantSuperAttributeUpdateObserver extends VariantSuperAttributeObserver |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Initialize the product super attribute with the passed attributes and returns an instance. |
41
|
|
|
* |
42
|
|
|
* @param array $attr The product super attribute attributes |
43
|
|
|
* |
44
|
|
|
* @return array The initialized product super attribute |
45
|
|
|
*/ |
46
|
|
|
protected function initializeProductSuperAttribute(array $attr) |
47
|
|
|
{ |
48
|
|
|
|
49
|
|
|
// load product/attribute ID |
50
|
|
|
$productId = $attr[MemberNames::PRODUCT_ID]; |
51
|
|
|
$attributeId = $attr[MemberNames::ATTRIBUTE_ID]; |
52
|
|
|
|
53
|
|
|
// query whether or not, the product super attribute already exists |
54
|
|
|
if ($entity = $this->loadProductSuperAttribute($productId, $attributeId)) { |
55
|
|
|
return $this->mergeProductSuperAttribute($entity, $attr); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// simply return the attributes |
59
|
|
|
return $attr; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Initialize the product super attribute label with the passed attributes and returns an instance. |
64
|
|
|
* |
65
|
|
|
* @param array $attr The product super attribute label attributes |
66
|
|
|
* |
67
|
|
|
* @return array The initialized product super attribute label |
68
|
|
|
*/ |
69
|
|
|
protected function initializeProductSuperAttributeLabel(array $attr) |
70
|
|
|
{ |
71
|
|
|
|
72
|
|
|
// load product super attribute/store ID |
73
|
|
|
$storeId = $attr[MemberNames::STORE_ID]; |
74
|
|
|
$productSuperAttributeId = $attr[MemberNames::PRODUCT_SUPER_ATTRIBUTE_ID]; |
75
|
|
|
|
76
|
|
|
// query whether or not, the product super attribute label already exists |
77
|
|
|
if ($entity = $this->loadProductSuperAttributeLabel($productSuperAttributeId, $storeId)) { |
78
|
|
|
return $this->mergeEntity($entity, $attr, TableNames::CATALOG_PRODUCT_SUPER_ATTRIBUTE_LABEL, EntityTypeCodes::CATALOG_PRODUCT_SUPER_ATTRIBUTE_LABEL); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
// simply return the attributes |
82
|
|
|
return $attr; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Merge's and return's the product super attribute entity with the passed attributes and set's the |
87
|
|
|
* status to 'update'. |
88
|
|
|
* |
89
|
|
|
* @param array $entity The entity to merge the attributes into |
90
|
|
|
* @param array $attr The attributes to be merged |
91
|
|
|
* |
92
|
|
|
* @return array The merged entity |
93
|
|
|
*/ |
94
|
|
|
protected function mergeProductSuperAttribute(array $entity, array $attr) |
95
|
|
|
{ |
96
|
|
|
|
97
|
|
|
// temporary persist the super attribute ID |
98
|
|
|
$this->setProductSuperAttributeId($entity[MemberNames::PRODUCT_SUPER_ATTRIBUTE_ID]); |
99
|
|
|
|
100
|
|
|
// merge and return the entity |
101
|
|
|
return $this->mergeEntity($entity, $attr, TableNames::CATALOG_PRODUCT_SUPER_ATTRIBUTE, EntityTypeCodes::CATALOG_PRODUCT_SUPER_ATTRIBUTE); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Load's the product super attribute with the passed product/attribute ID. |
106
|
|
|
* |
107
|
|
|
* @param integer $productId The entity ID of the product super attribute's product |
108
|
|
|
* @param integer $attributeId The attribute ID of the product super attributes attribute |
109
|
|
|
* |
110
|
|
|
* @return array The product super attribute |
111
|
|
|
*/ |
112
|
|
|
protected function loadProductSuperAttribute($productId, $attributeId) |
113
|
|
|
{ |
114
|
|
|
return $this->getProductVariantProcessor()->loadProductSuperAttribute($productId, $attributeId); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Load's the product super attribute label with the passed product super attribute/store ID. |
119
|
|
|
* |
120
|
|
|
* @param integer $productSuperAttributeId The product super attribute ID of the product super attribute label |
121
|
|
|
* @param integer $storeId The store ID of the product super attribute label |
122
|
|
|
* |
123
|
|
|
* @return array The product super attribute label |
124
|
|
|
*/ |
125
|
|
|
protected function loadProductSuperAttributeLabel($productSuperAttributeId, $storeId) |
126
|
|
|
{ |
127
|
|
|
return $this->getProductVariantProcessor()->loadProductSuperAttributeLabel($productSuperAttributeId, $storeId); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|