diff --git a/vendor/magento/module-weee/Model/Total/Quote/WeeeTax.php b/vendor/magento/module-weee/Model/Total/Quote/WeeeTax.php index 7429f875eda..bc96b93274d 100644 --- a/vendor/magento/module-weee/Model/Total/Quote/WeeeTax.php +++ b/vendor/magento/module-weee/Model/Total/Quote/WeeeTax.php @@ -68,13 +68,20 @@ class WeeeTax extends Weee $weeeCodeToWeeeTaxDetailsMap[$weeeCode] = $weeeTaxDetails; } } - $productTaxes = []; + //Process each item that has taxable weee foreach ($itemToWeeeCodeMap as $mapping) { + $itemWeeTaxDetails = array_intersect_key( + $weeeCodeToWeeeTaxDetailsMap, + array_fill_keys($mapping['weeeCodes'], null) + ); + if (empty($itemWeeTaxDetails)) { + continue; + } $item = $mapping['item']; $this->weeeData->setApplied($item, []); - + $productTaxes = $this->weeeData->getApplied($item); $totalValueInclTax = 0; $baseTotalValueInclTax = 0; $totalRowValueInclTax = 0; @@ -86,12 +93,7 @@ class WeeeTax extends Weee $baseTotalRowValueExclTax = 0; //Process each taxed weee attribute of an item - foreach ($mapping['weeeCodes'] as $weeeCode) { - if (!array_key_exists($weeeCode, $weeeCodeToWeeeTaxDetailsMap)) { - //Need to ensure that everyone is in sync for which weee code to process - continue; - } - $weeeTaxDetails = $weeeCodeToWeeeTaxDetailsMap[$weeeCode]; + foreach ($itemWeeTaxDetails as $weeeCode => $weeeTaxDetails) { $attributeCode = explode('-', $weeeCode)[1]; $valueExclTax = $weeeTaxDetails[CommonTaxCollector::KEY_TAX_DETAILS_PRICE_EXCL_TAX]; @@ -115,17 +117,15 @@ class WeeeTax extends Weee $baseTotalRowValueExclTax += $baseRowValueExclTax; $productTaxes[] = [ - [ - 'title' => $attributeCode, //TODO: fix this - 'base_amount' => $baseValueExclTax, - 'amount' => $valueExclTax, - 'row_amount' => $rowValueExclTax, - 'base_row_amount' => $baseRowValueExclTax, - 'base_amount_incl_tax' => $baseValueInclTax, - 'amount_incl_tax' => $valueInclTax, - 'row_amount_incl_tax' => $rowValueInclTax, - 'base_row_amount_incl_tax' => $baseRowValueInclTax, - ], + 'title' => $attributeCode, //TODO: fix this + 'base_amount' => $baseValueExclTax, + 'amount' => $valueExclTax, + 'row_amount' => $rowValueExclTax, + 'base_row_amount' => $baseRowValueExclTax, + 'base_amount_incl_tax' => $baseValueInclTax, + 'amount_incl_tax' => $valueInclTax, + 'row_amount_incl_tax' => $rowValueInclTax, + 'base_row_amount_incl_tax' => $baseRowValueInclTax, ]; } @@ -147,11 +147,11 @@ class WeeeTax extends Weee $baseTotalRowValueInclTax ); + $this->weeeData->setApplied( + $item, + $productTaxes + ); } - $this->weeeData->setApplied( - $item, - array_merge($this->weeeData->getApplied($item), ...$productTaxes) - ); } return $this; } @@ -239,7 +239,7 @@ class WeeeTax extends Weee */ public function fetch(Quote $quote, Total $total) { - $items = $total['quote_items'] ?? []; + $items = $total['address_quote_items'] ?? []; $weeeTotal = $this->weeeData->getTotalAmounts($items, $quote->getStore()); if ($weeeTotal) {