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