Skip to content

Commit

Permalink
Merge pull request #9337 from adobe-commerce-tier-4/PR_05_NOV_2024
Browse files Browse the repository at this point in the history
[Support Tier-4 aplapana] 11-05-2024 Regular delivery of bugfixes and improvements
  • Loading branch information
2 parents c1677a3 + 17e28b0 commit 0b488dd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
11 changes: 5 additions & 6 deletions app/code/Magento/Quote/Model/Quote/Item/AbstractItem.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2011 Adobe
* All Rights Reserved.
*/
namespace Magento\Quote\Model\Quote\Item;

Expand All @@ -18,6 +18,7 @@
* - custom_price - new price that can be declared by user and recalculated during calculation process
* - original_custom_price - original defined value of custom price without any conversion
*
* phpcs:disable Magento2.Classes.AbstractApi
* @api
* @method float getDiscountAmount()
* @method \Magento\Quote\Model\Quote\Item\AbstractItem setDiscountAmount(float $amount)
Expand Down Expand Up @@ -255,7 +256,7 @@ public function setMessage($messages)
/**
* Add message of quote item to array of messages
*
* @param string $message
* @param mixed $message
* @return $this
*/
public function addMessage($message)
Expand Down Expand Up @@ -678,9 +679,7 @@ public function getTotalDiscountAmount()
foreach ($children as $child) {
$totalDiscountAmount += $child->getDiscountAmount();
}
} else {
$totalDiscountAmount = $this->getDiscountAmount();
}
return $totalDiscountAmount;
return $totalDiscountAmount + $this->getDiscountAmount();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2014 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -50,7 +50,8 @@ public function testGetTotalDiscountAmount($expectedDiscountAmount, $children, $
$this->assertEquals($expectedDiscountAmount, $totalDiscountAmount);
}

protected function getMockForAbstractItem($childDiscountAmount) {
protected function getMockForAbstractItem($childDiscountAmount)
{
$childItemMock = $this->getMockForAbstractClass(
AbstractItem::class,
[],
Expand Down Expand Up @@ -82,6 +83,7 @@ public static function dataProviderGetTotalDiscountAmount()
$testCase->getMockForAbstractItem($childTwoDiscountAmount);

$valueHasNoEffect = 0;
$parentDiscountAmount = 10;

$data = [
'no_children' => [
Expand All @@ -97,10 +99,10 @@ public static function dataProviderGetTotalDiscountAmount()
10,
],
'one_kid' => [
$childOneDiscountAmount,
$childOneDiscountAmount + $parentDiscountAmount,
[$childOneItemMock],
true,
$valueHasNoEffect,
$parentDiscountAmount,
],
'two_kids' => [
$childOneDiscountAmount + $childTwoDiscountAmount,
Expand Down
11 changes: 4 additions & 7 deletions app/code/Magento/SalesRule/Model/Quote/Discount.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ public function collect(
$items = $this->calculator->sortItemsByPriority($items, $address);
$itemsToApplyRules = $items;
$rules = $this->calculator->getRules($address);
$totalDiscount = [];
$address->setBaseDiscountAmount(0);
/** @var Rule $rule */
foreach ($rules as $rule) {
$ruleTotalDiscount = 0;
/** @var Item $item */
foreach ($itemsToApplyRules as $key => $item) {
if ($item->getNoDiscount() || !$this->calculator->canApplyDiscount($item) || $item->getParentItem()) {
Expand Down Expand Up @@ -222,16 +222,13 @@ public function collect(
}

if ($item->getChildren() && $item->isChildrenCalculated()) {
$childTotal = 0;
foreach ($item->getChildren() as $child) {
$childTotal += $child->getBaseDiscountAmount();
$ruleTotalDiscount += $child->getBaseDiscountAmount();
}
$totalDiscount[$item->getId()] = $childTotal;
} else {
$totalDiscount[$item->getId()] = $item->getBaseDiscountAmount();
}
$ruleTotalDiscount += $item->getBaseDiscountAmount();
}
$address->setBaseDiscountAmount(array_sum(array_values($totalDiscount)));
$address->setBaseDiscountAmount($ruleTotalDiscount);
}
$this->calculator->initTotals($items, $address);
foreach ($items as $item) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2014 Adobe
* All Rights Reserved.
*/
namespace Magento\SalesRule\Model\Rule\Action\Discount;

Expand Down Expand Up @@ -141,6 +141,9 @@ public function calculate($rule, $item, $qty)
$baseDiscountAmount = min($baseItemPrice * $qty, $baseDiscountAmount);
if ($ruleItemsCount <= 1) {
$this->deltaPriceRound->reset($discountType);
if ($baseDiscountAmount > $availableDiscountAmount) {
$baseDiscountAmount = $availableDiscountAmount;
}
} else {
$this->validator->decrementRuleItemTotalsCount($rule->getId());
}
Expand Down Expand Up @@ -191,6 +194,7 @@ public function calculate($rule, $item, $qty)
* Set information about usage cart fixed rule by quote address
*
* @deprecated 101.2.0 should be removed as it is not longer used
* @see Nothing
* @param int $ruleId
* @param int $itemId
* @return void
Expand All @@ -204,6 +208,7 @@ protected function setCartFixedRuleUsedForAddress($ruleId, $itemId)
* Retrieve information about usage cart fixed rule by quote address
*
* @deprecated 101.2.0 should be removed as it is not longer used
* @see Nothing
* @param int $ruleId
* @return int|null
*/
Expand Down

0 comments on commit 0b488dd

Please sign in to comment.