10
10
*/
11
11
class Observer extends \Magento \Framework \Model \AbstractModel
12
12
{
13
+ /**
14
+ * Tax data
15
+ *
16
+ * @var \Magento\Tax\Helper\Data
17
+ */
18
+ protected $ _taxData ;
19
+
13
20
/**
14
21
* @var \Magento\Catalog\Model\Product\Type
15
22
*/
@@ -43,6 +50,7 @@ class Observer extends \Magento\Framework\Model\AbstractModel
43
50
* @param \Magento\Framework\View\LayoutInterface $layout
44
51
* @param Tax $weeeTax
45
52
* @param \Magento\Weee\Helper\Data $weeeData
53
+ * @param \Magento\Tax\Helper\Data $taxData
46
54
* @param \Magento\Catalog\Model\Product\Type $productType
47
55
* @param \Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypeConfig
48
56
* @param \Magento\Framework\Model\Resource\AbstractResource $resource
@@ -56,6 +64,7 @@ public function __construct(
56
64
\Magento \Framework \View \LayoutInterface $ layout ,
57
65
Tax $ weeeTax ,
58
66
\Magento \Weee \Helper \Data $ weeeData ,
67
+ \Magento \Tax \Helper \Data $ taxData ,
59
68
\Magento \Catalog \Model \Product \Type $ productType ,
60
69
\Magento \Catalog \Model \ProductTypes \ConfigInterface $ productTypeConfig ,
61
70
\Magento \Framework \Model \Resource \AbstractResource $ resource = null ,
@@ -64,6 +73,7 @@ public function __construct(
64
73
) {
65
74
$ this ->_layout = $ layout ;
66
75
$ this ->_weeeTax = $ weeeTax ;
76
+ $ this ->_taxData = $ taxData ;
67
77
$ this ->_productType = $ productType ;
68
78
$ this ->_weeeData = $ weeeData ;
69
79
$ this ->productTypeConfig = $ productTypeConfig ;
@@ -200,30 +210,43 @@ public function updateElementTypes(\Magento\Framework\Event\Observer $observer)
200
210
*
201
211
* @param \Magento\Framework\Event\Observer $observer
202
212
* @return $this
213
+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
203
214
*/
204
215
public function getPriceConfiguration (\Magento \Framework \Event \Observer $ observer )
205
216
{
206
217
if ($ this ->_weeeData ->isEnabled ()) {
207
218
$ priceConfigObj =$ observer ->getData ('configObj ' );
208
219
$ priceConfig =$ priceConfigObj ->getConfig ();
209
- if (is_array ($ priceConfig )) {
210
- foreach ($ priceConfig as $ keyConfigs => $ configs ) {
211
- if (is_array ($ configs )) {
212
- if (array_key_exists ('prices ' , $ configs )) {
213
- $ priceConfig [$ keyConfigs ]['prices ' ]['weeePrice ' ] = [
214
- 'amount ' => $ configs ['prices ' ]['finalPrice ' ]['amount ' ],
215
- ];
216
- } else {
220
+ try {
221
+ if (is_array ($ priceConfig )) {
222
+ foreach ($ priceConfig as $ keyConfigs => $ configs ) {
223
+ if (is_array ($ configs )) {
217
224
foreach ($ configs as $ keyConfig => $ config ) {
218
- $ priceConfig [$ keyConfigs ][$ keyConfig ]['prices ' ]['weeePrice ' ] = [
219
- 'amount ' => $ config ['prices ' ]['finalPrice ' ]['amount ' ],
220
- ];
225
+ $ calcPrice = 'finalPrice ' ;
226
+ if ($ this ->_taxData ->priceIncludesTax () &&
227
+ $ this ->_taxData ->displayPriceExcludingTax ()
228
+ ) {
229
+ $ calcPrice = 'basePrice ' ;
230
+ }
231
+ if (array_key_exists ('prices ' , $ configs )) {
232
+ $ priceConfig [$ keyConfigs ]['prices ' ]['weeePrice ' ] = [
233
+ 'amount ' => $ configs ['prices ' ][$ calcPrice ]['amount ' ],
234
+ ];
235
+ } else {
236
+ foreach ($ configs as $ keyConfig => $ config ) {
237
+ $ priceConfig [$ keyConfigs ][$ keyConfig ]['prices ' ]['weeePrice ' ] = [
238
+ 'amount ' => $ config ['prices ' ][$ calcPrice ]['amount ' ],
239
+ ];
240
+ }
241
+ }
221
242
}
222
243
}
223
244
}
224
245
}
246
+ $ priceConfigObj ->setConfig ($ priceConfig );
247
+ } catch (Exception $ e ) {
248
+ return $ this ;
225
249
}
226
- $ priceConfigObj ->setConfig ($ priceConfig );
227
250
}
228
251
return $ this ;
229
252
}
0 commit comments