Skip to content

Commit 0a935ad

Browse files
committed
Merge remote-tracking branch 'act4/ACP2E-3193-1' into PR_13_OCT_2024
2 parents 28d239a + 829e6a3 commit 0a935ad

File tree

11 files changed

+329
-59
lines changed

11 files changed

+329
-59
lines changed

app/code/Magento/Weee/Helper/Data.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Weee\Helper;
77

@@ -352,7 +352,7 @@ public function getBaseWeeeTaxAppliedRowAmount($item)
352352
protected function getRecursiveNumericAmount($item, $functionName)
353353
{
354354
if ($item instanceof QuoteAbstractItem || $item instanceof OrderItem) {
355-
if ($item->getHasChildren() && $item->isChildrenCalculated()) {
355+
if ($item->getHasChildren()) {
356356
$result = 0;
357357
$children = $item instanceof OrderItem ? $item->getChildrenItems() : $item->getChildren();
358358
foreach ($children as $child) {
@@ -382,7 +382,7 @@ protected function getRecursiveNumericAmount($item, $functionName)
382382
public function getApplied($item)
383383
{
384384
if ($item instanceof QuoteAbstractItem) {
385-
if ($item->getHasChildren() && $item->isChildrenCalculated()) {
385+
if ($item->getHasChildren()) {
386386
$result = [];
387387
foreach ($item->getChildren() as $child) {
388388
$childData = $this->getApplied($child);

app/code/Magento/Weee/Model/Tax.php

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Weee\Model;
77

88
use Magento\Catalog\Model\Product;
9+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
910
use Magento\Framework\Pricing\PriceCurrencyInterface;
1011
use Magento\Store\Model\Website;
11-
use Magento\Tax\Model\Calculation;
1212
use Magento\Customer\Api\AccountManagementInterface;
1313
use Magento\Catalog\Model\Product\Type;
1414

1515
/**
1616
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
17+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1718
* @api
1819
* @since 100.0.2
1920
*/
@@ -22,31 +23,29 @@ class Tax extends \Magento\Framework\Model\AbstractModel
2223
/**
2324
* Including FPT only
2425
*/
25-
const DISPLAY_INCL = 0;
26+
public const DISPLAY_INCL = 0;
2627

2728
/**
2829
* Including FPT and FPT description
2930
*/
30-
const DISPLAY_INCL_DESCR = 1;
31+
public const DISPLAY_INCL_DESCR = 1;
3132

3233
/**
3334
* Excluding FPT. Including FPT description and final price
3435
*/
35-
const DISPLAY_EXCL_DESCR_INCL = 2;
36+
public const DISPLAY_EXCL_DESCR_INCL = 2;
3637

3738
/**
3839
* Excluding FPT
3940
*/
40-
const DISPLAY_EXCL = 3;
41+
public const DISPLAY_EXCL = 3;
4142

4243
/**
4344
* @var array|null
4445
*/
4546
protected $_allAttributes = null;
4647

4748
/**
48-
* Tax data
49-
*
5049
* @var \Magento\Tax\Helper\Data
5150
*/
5251
protected $_taxData = null;
@@ -71,9 +70,7 @@ class Tax extends \Magento\Framework\Model\AbstractModel
7170
*/
7271
protected $_customerSession;
7372

74-
/**
75-
* Weee config
76-
*
73+
/**s
7774
* @var \Magento\Weee\Model\Config
7875
*/
7976
protected $weeeConfig;
@@ -141,6 +138,8 @@ protected function _construct()
141138
}
142139

143140
/**
141+
* Retrieve Weee Attribute amount
142+
*
144143
* @param Product $product
145144
* @param null|false|\Magento\Framework\DataObject $shipping
146145
* @param null|false|\Magento\Framework\DataObject $billing
@@ -170,6 +169,8 @@ public function getWeeeAmount(
170169
}
171170

172171
/**
172+
* Retrieve Weee attribute amount excluding tax
173+
*
173174
* @param Product $product
174175
* @param null|false|\Magento\Framework\DataObject $shipping
175176
* @param null|false|\Magento\Framework\DataObject $billing
@@ -182,24 +183,32 @@ public function getWeeeAmountExclTax(
182183
$billing = null,
183184
$website = null
184185
) {
186+
$attributes = [];
185187
$amountExclTax = 0;
186-
$attributes = $this->getProductWeeeAttributes(
187-
$product,
188-
$shipping,
189-
$billing,
190-
$website,
191-
true,
192-
false
193-
);
188+
189+
if ($product->getTypeId() !== Configurable::TYPE_CODE) {
190+
$attributes = $this->getProductWeeeAttributes(
191+
$product,
192+
$shipping,
193+
$billing,
194+
$website,
195+
true,
196+
false
197+
);
198+
}
199+
194200
if (Type::TYPE_BUNDLE !== $product->getTypeId() || $product->getPriceType()) {
195201
foreach ($attributes as $attribute) {
196202
$amountExclTax += $attribute->getAmountExclTax();
197203
}
198204
}
205+
199206
return $amountExclTax;
200207
}
201208

202209
/**
210+
* Retrieve Weee Attribute Codes
211+
*
203212
* @param bool $forceEnabled
204213
* @return array
205214
*/
@@ -209,7 +218,7 @@ public function getWeeeAttributeCodes($forceEnabled = false)
209218
}
210219

211220
/**
212-
* Retrieve Wee tax attribute codes
221+
* Retrieve Weee tax attribute codes
213222
*
214223
* @param null|string|bool|int|Store $store
215224
* @param bool $forceEnabled
@@ -228,6 +237,8 @@ public function getWeeeTaxAttributeCodes($store = null, $forceEnabled = false)
228237
}
229238

230239
/**
240+
* Retrieve product Weee attribute
241+
*
231242
* @param Product $product
232243
* @param null|false|\Magento\Quote\Model\Quote\Address $shipping
233244
* @param null|false|\Magento\Quote\Model\Quote\Address $billing
@@ -238,6 +249,7 @@ public function getWeeeTaxAttributeCodes($store = null, $forceEnabled = false)
238249
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
239250
* @SuppressWarnings(PHPMD.NPathComplexity)
240251
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
252+
* phpcs:disable Generic.Metrics.NestingLevel
241253
*/
242254
public function getProductWeeeAttributes(
243255
$product,
@@ -374,6 +386,8 @@ public function getProductWeeeAttributes(
374386
}
375387

376388
/**
389+
* Check if Weee is in location
390+
*
377391
* @param int $countryId
378392
* @param int $regionId
379393
* @param int $websiteId

app/code/Magento/Weee/Model/Total/Quote/Weee.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
55
*/
6-
76
namespace Magento\Weee\Model\Total\Quote;
87

98
use Magento\Framework\Pricing\PriceCurrencyInterface;
@@ -129,12 +128,13 @@ public function collect(
129128
continue;
130129
}
131130
$this->resetItemData($item);
132-
if ($item->getHasChildren() && $item->isChildrenCalculated()) {
131+
if ($item->getHasChildren()) {
132+
$child = null;
133133
foreach ($item->getChildren() as $child) {
134134
$this->resetItemData($child);
135135
$this->process($address, $total, $child);
136136
}
137-
$this->recalculateParent($item);
137+
$this->recalculateParent($item, $child);
138138
} else {
139139
$this->process($address, $total, $item);
140140
}
@@ -315,17 +315,22 @@ protected function getNextIncrement()
315315
* Recalculate parent item amounts based on children results
316316
*
317317
* @param AbstractItem $item
318+
* @param AbstractItem|null $childItem
318319
* @return void
319-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
320320
*/
321-
protected function recalculateParent(AbstractItem $item)
321+
protected function recalculateParent(AbstractItem $item, AbstractItem $childItem = null)
322322
{
323323
$associatedTaxables = [];
324324
foreach ($item->getChildren() as $child) {
325325
$associatedTaxables[] = $child->getAssociatedTaxables();
326326
}
327327
$associatedTaxables = array_merge([], ...$associatedTaxables);
328328
$item->setAssociatedTaxables($associatedTaxables);
329+
330+
if (isset($childItem)) {
331+
$item->setWeeeTaxApplied($childItem->getWeeeTaxApplied());
332+
$item->setWeeeTaxAppliedAmount($childItem->getWeeeTaxAppliedAmount());
333+
}
329334
}
330335

331336
/**
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Weee\Plugin\Catalog\ResourceModel\Product;
9+
10+
use Magento\Catalog\Model\ResourceModel\Product\Indexer\LinkedProductSelectBuilderByIndexPrice;
11+
use Magento\Framework\App\ResourceConnection;
12+
use Magento\Framework\DB\Select;
13+
14+
class WeeeAttributeProductSort
15+
{
16+
/**
17+
* @var ResourceConnection
18+
*/
19+
private ResourceConnection $resourceConnection;
20+
21+
/**
22+
* @param ResourceConnection $resourceConnection
23+
*/
24+
public function __construct(
25+
ResourceConnection $resourceConnection
26+
) {
27+
$this->resourceConnection = $resourceConnection;
28+
}
29+
30+
/**
31+
* Add weee attribute to products sorting query
32+
*
33+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
34+
*
35+
* @param LinkedProductSelectBuilderByIndexPrice $subject
36+
* @param array $result
37+
* @param int $productId
38+
* @param int $storeId
39+
* @return array
40+
*/
41+
public function afterBuild(
42+
LinkedProductSelectBuilderByIndexPrice $subject,
43+
array $result,
44+
int $productId,
45+
int $storeId
46+
):array {
47+
$select = $this->resourceConnection->getConnection()->select();
48+
49+
foreach ($result as $select) {
50+
$select->columns(
51+
[
52+
'weee_min_price' => new \Zend_Db_Expr(
53+
'(t.min_price + IFNULL(weee_child.value, IFNULL(weee_parent.value, 0)))'
54+
)
55+
]
56+
)->joinLeft(
57+
['weee_child' => $this->resourceConnection->getTableName('weee_tax')],
58+
'weee_child.entity_id = child.entity_id'
59+
)->joinLeft(
60+
['weee_parent' => $this->resourceConnection->getTableName('weee_tax')],
61+
'weee_parent.entity_id = parent.entity_id'
62+
)->reset(Select::ORDER)->order('weee_min_price ASC')->limit(1);
63+
}
64+
65+
return [$select];
66+
}
67+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Weee\Plugin\ConfigurableProduct\Pricing;
9+
10+
use Magento\Catalog\Pricing\Price\FinalPrice as CatalogFinalPrice;
11+
use Magento\ConfigurableProduct\Pricing\Price\FinalPriceResolver as ConfigurableProductFinalPriceResolver;
12+
use Magento\Framework\Pricing\SaleableInterface;
13+
use Magento\Weee\Helper\Data as WeeeHelperData;
14+
15+
class FinalPriceResolver
16+
{
17+
/**
18+
* @var WeeeHelperData
19+
*/
20+
public WeeeHelperData $weeeHelperData;
21+
22+
/**
23+
* @param WeeeHelperData $weeeHelperData
24+
*/
25+
public function __construct(
26+
WeeeHelperData $weeeHelperData,
27+
) {
28+
$this->weeeHelperData = $weeeHelperData;
29+
}
30+
31+
/**
32+
* Display price with weee attribute included
33+
*
34+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
35+
*
36+
* @param ConfigurableProductFinalPriceResolver $subject
37+
* @param float $result
38+
* @param SaleableInterface $product
39+
* @return float
40+
*/
41+
public function afterResolvePrice(
42+
ConfigurableProductFinalPriceResolver $subject,
43+
float $result,
44+
SaleableInterface $product
45+
):float {
46+
return $this->weeePriceDisplay()
47+
? $product->getPriceInfo()->getPrice(CatalogFinalPrice::PRICE_CODE)->getAmount()->getValue()
48+
: $product->getPriceInfo()->getPrice(CatalogFinalPrice::PRICE_CODE)->getValue();
49+
}
50+
51+
/**
52+
* Weee including price display
53+
*
54+
* @return bool
55+
*/
56+
private function weeePriceDisplay():bool
57+
{
58+
return $this->weeeHelperData->isDisplayIncl() || $this->weeeHelperData->isDisplayInclDesc();
59+
}
60+
}

0 commit comments

Comments
 (0)