1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Product\TierPrice\Observers\TierPriceUpdateObserver |
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 Klaas-Tido Rühl <[email protected]> |
15
|
|
|
* @author Tim Wagner <[email protected]> |
16
|
|
|
* @copyright 2019 REFUSiON GmbH <[email protected]> |
17
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
18
|
|
|
* @link https://github.com/techdivision/import-product-tier-price |
19
|
|
|
* @link https://www.techdivision.com |
20
|
|
|
* @link https://www.refusion.com |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace TechDivision\Import\Product\TierPrice\Observers; |
24
|
|
|
|
25
|
|
|
use TechDivision\Import\Product\Observers\AbstractProductImportObserver; |
26
|
|
|
use TechDivision\Import\Product\TierPrice\Utils\ValueTypesInterface; |
27
|
|
|
use TechDivision\Import\Product\TierPrice\Services\TierPriceProcessorInterface; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Observer for creating/updating/deleting tier prices from the database. |
31
|
|
|
* |
32
|
|
|
* @author Klaas-Tido Rühl <[email protected]> |
33
|
|
|
* @author Tim Wagner <[email protected]> |
34
|
|
|
* @copyright 2019 REFUSiON GmbH <[email protected]> |
35
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
36
|
|
|
* @link https://github.com/techdivision/import-product-tier-price |
37
|
|
|
* @link https://www.techdivision.com |
38
|
|
|
* @link https://www.refusion.com |
39
|
|
|
*/ |
40
|
|
|
class TierPriceObserver extends AbstractProductImportObserver |
41
|
|
|
{ |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* The trait that prepares the tier price data. |
45
|
|
|
* |
46
|
|
|
* @var \TechDivision\Import\Product\TierPrice\Observers\PrepareTierPriceTrait |
47
|
|
|
*/ |
48
|
|
|
use PrepareTierPriceTrait; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* The product tier price processor instance. |
52
|
|
|
* |
53
|
|
|
* @var \TechDivision\Import\Product\TierPrice\Services\TierPriceProcessorInterface |
54
|
|
|
*/ |
55
|
|
|
protected $tierPriceProcessor; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* The available tier price value types. |
59
|
|
|
* |
60
|
|
|
* @var \TechDivision\Import\Product\TierPrice\Utils\ValueTypesInterface |
61
|
|
|
*/ |
62
|
|
|
protected $valueTypes; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Initialize the observer with the passed product tier price processor instance. |
66
|
|
|
* |
67
|
|
|
* @param \TechDivision\Import\Product\TierPrice\Services\TierPriceProcessorInterface $tierPriceProcessor The processor instance |
68
|
|
|
* @param \TechDivision\Import\Product\TierPrice\Utils\ValueTypesInterface $valueTypes The tier price value types |
69
|
|
|
*/ |
70
|
|
|
public function __construct(TierPriceProcessorInterface $tierPriceProcessor, ValueTypesInterface $valueTypes) |
71
|
|
|
{ |
72
|
|
|
$this->tierPriceProcessor = $tierPriceProcessor; |
73
|
|
|
$this->valueTypes = $valueTypes; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Returns the product URL rewrite processor instance. |
78
|
|
|
* |
79
|
|
|
* @return \TechDivision\Import\Product\TierPrice\Services\TierPriceProcessorInterface The processor instance |
80
|
|
|
*/ |
81
|
|
|
protected function getTierPriceProcessor() |
82
|
|
|
{ |
83
|
|
|
return $this->tierPriceProcessor; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Returns the tier price value types. |
88
|
|
|
* |
89
|
|
|
* @return \TechDivision\Import\Product\TierPrice\Utils\ValueTypesInterface The tier price value types |
90
|
|
|
*/ |
91
|
|
|
protected function getValueTypes() |
92
|
|
|
{ |
93
|
|
|
return $this->valueTypes; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Process the observer's business logic. |
98
|
|
|
* |
99
|
|
|
* @return void |
100
|
|
|
* @throws \Exception |
101
|
|
|
*/ |
102
|
|
|
protected function process() |
103
|
|
|
{ |
104
|
|
|
$this->addProcessedTierPrice( |
105
|
|
|
$this->persistTierPrice($this->initializeTierPrice($this->prepareAttributes())), |
|
|
|
|
106
|
|
|
$this->getLastEntityId() |
|
|
|
|
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/**s |
111
|
|
|
* Initialize the product website with the passed attributes and returns an instance. |
112
|
|
|
* |
113
|
|
|
* @param array $attr The product website attributes |
114
|
|
|
* |
115
|
|
|
* @return array The initialized product website |
116
|
|
|
* @throws \RuntimeException Is thrown, if the attributes can not be initialized |
117
|
|
|
*/ |
118
|
|
|
protected function initializeTierPrice(array $attr) |
119
|
|
|
{ |
120
|
|
|
return $attr; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Persists the tier price with the passed data. |
125
|
|
|
* |
126
|
|
|
* @param array $row The tier price to persist |
127
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
128
|
|
|
* |
129
|
|
|
* @return string The ID of the persisted entity |
130
|
|
|
*/ |
131
|
|
|
protected function persistTierPrice(array $row, $name = null) |
132
|
|
|
{ |
133
|
|
|
return $this->getTierPriceProcessor()->persistTierPrice($row, $name); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Add the ID of the processed tier price. |
138
|
|
|
* |
139
|
|
|
* @param integer $valueId The ID of the processed tier price |
140
|
|
|
* @param integer $entityId The entity ID of the related product |
141
|
|
|
* |
142
|
|
|
* @return void |
143
|
|
|
*/ |
144
|
|
|
protected function addProcessedTierPrice($valueId, $entityId) |
145
|
|
|
{ |
146
|
|
|
$this->getSubject()->addProcessedTierPrice($valueId, $entityId); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Returns the customer group ID for the given code, if it exists. |
151
|
|
|
* |
152
|
|
|
* @param string $code The code of the requested customer group |
153
|
|
|
* |
154
|
|
|
* @return integer|null The ID of the customer group |
155
|
|
|
*/ |
156
|
|
|
protected function getCustomerGroupIdByCode($code) |
157
|
|
|
{ |
158
|
|
|
return $this->getSubject()->getCustomerGroupIdByCode($code); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Return's the store website for the passed code. |
163
|
|
|
* |
164
|
|
|
* @param string $code The code of the store website to return the ID for |
165
|
|
|
* |
166
|
|
|
* @return integer The store website ID |
167
|
|
|
* @throws \Exception Is thrown, if the store website with the requested code is not available |
168
|
|
|
*/ |
169
|
|
|
protected function getStoreWebsiteIdByCode($code) |
170
|
|
|
{ |
171
|
|
|
return $this->getSubject()->getStoreWebsiteIdByCode($code); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Query whether or not the passed value type is valid. |
176
|
|
|
* |
177
|
|
|
* @param string $valueType The value type to query for |
178
|
|
|
* |
179
|
|
|
* @return boolean TRUE if the value type is valid, else FALSE |
180
|
|
|
*/ |
181
|
|
|
protected function isValueType($valueType) |
182
|
|
|
{ |
183
|
|
|
return $this->getValueTypes()->isValueType($valueType); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Queries whether or not the passed customer group code matches all groups or not. |
188
|
|
|
* |
189
|
|
|
* @param string $code The customer group code to query for |
190
|
|
|
* |
191
|
|
|
* @return boolean TRUE if the customer group code matches, else FALSE |
192
|
|
|
*/ |
193
|
|
|
protected function isAllGroups($code) |
194
|
|
|
{ |
195
|
|
|
return $this->getSubject()->isAllGroups($code); |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|