Skip to content

Commit

Permalink
bugfix:
Browse files Browse the repository at this point in the history
- Add init totals into foreach rules loop to allow for total calculation after each rules apply on Discount.php

- remove logic for adding item discount to address base discount on Discount.php

- on CartFixed.php now use validator to calculate current valid items total discount for rule on proporcional discount calculation.

refs: magento#38694
  • Loading branch information
jlopezsumma committed Oct 1, 2024
1 parent 1819fe7 commit 52a9de5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 1 addition & 4 deletions app/code/Magento/SalesRule/Model/Quote/Discount.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ public function collect(
$items = $this->calculator->sortItemsByPriority($items, $address);
$itemsToApplyRules = $items;
$rules = $this->calculator->getRules($address);
$totalDiscount = 0;
$address->setBaseDiscountAmount(0);
/** @var Rule $rule */
foreach ($rules as $rule) {
Expand Down Expand Up @@ -221,11 +220,9 @@ public function collect(
unset($itemsToApplyRules[$key]);
}

$totalDiscount += $item->getBaseDiscountAmount();
}
$address->setBaseDiscountAmount($totalDiscount);
$this->calculator->initTotals($items, $address);
}
$this->calculator->initTotals($items, $address);
foreach ($items as $item) {
if (!isset($itemsAggregate[$item->getId()])) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public function calculate($rule, $item, $qty)
$ruleTotals = $this->validator->getRuleItemTotalsInfo($rule->getId());
$baseRuleTotals = $ruleTotals['base_items_price'] ?? 0.0;
$ruleItemsCount = $ruleTotals['items_count'] ?? 0;
$ruleItemsBaseDiscount = $ruleTotals['base_items_discount_amount'] ?? 0.0;


$address = $item->getAddress();
$quote = $item->getQuote();
Expand Down Expand Up @@ -133,7 +135,7 @@ public function calculate($rule, $item, $qty)
$qty,
$baseItemPrice,
$baseItemDiscountAmount,
$baseRuleTotals - $address->getBaseDiscountAmount(),
$baseRuleTotals - $ruleItemsBaseDiscount,
$discountType
);
}
Expand Down

0 comments on commit 52a9de5

Please sign in to comment.