Skip to content

Commit 0457d78

Browse files
Merge branch '2.4-develop' into Hammer-Plateform-Health-05Nov24
2 parents 1895c7e + 0b488dd commit 0457d78

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

app/code/Magento/Quote/Model/Quote/Item/AbstractItem.php

+5-6
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\Quote\Model\Quote\Item;
77

@@ -18,6 +18,7 @@
1818
* - custom_price - new price that can be declared by user and recalculated during calculation process
1919
* - original_custom_price - original defined value of custom price without any conversion
2020
*
21+
* phpcs:disable Magento2.Classes.AbstractApi
2122
* @api
2223
* @method float getDiscountAmount()
2324
* @method \Magento\Quote\Model\Quote\Item\AbstractItem setDiscountAmount(float $amount)
@@ -255,7 +256,7 @@ public function setMessage($messages)
255256
/**
256257
* Add message of quote item to array of messages
257258
*
258-
* @param string $message
259+
* @param mixed $message
259260
* @return $this
260261
*/
261262
public function addMessage($message)
@@ -678,9 +679,7 @@ public function getTotalDiscountAmount()
678679
foreach ($children as $child) {
679680
$totalDiscountAmount += $child->getDiscountAmount();
680681
}
681-
} else {
682-
$totalDiscountAmount = $this->getDiscountAmount();
683682
}
684-
return $totalDiscountAmount;
683+
return $totalDiscountAmount + $this->getDiscountAmount();
685684
}
686685
}

app/code/Magento/Quote/Test/Unit/Model/Quote/Item/AbstractItemTest.php

+7-5
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 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -50,7 +50,8 @@ public function testGetTotalDiscountAmount($expectedDiscountAmount, $children, $
5050
$this->assertEquals($expectedDiscountAmount, $totalDiscountAmount);
5151
}
5252

53-
protected function getMockForAbstractItem($childDiscountAmount) {
53+
protected function getMockForAbstractItem($childDiscountAmount)
54+
{
5455
$childItemMock = $this->getMockForAbstractClass(
5556
AbstractItem::class,
5657
[],
@@ -82,6 +83,7 @@ public static function dataProviderGetTotalDiscountAmount()
8283
$testCase->getMockForAbstractItem($childTwoDiscountAmount);
8384

8485
$valueHasNoEffect = 0;
86+
$parentDiscountAmount = 10;
8587

8688
$data = [
8789
'no_children' => [
@@ -97,10 +99,10 @@ public static function dataProviderGetTotalDiscountAmount()
9799
10,
98100
],
99101
'one_kid' => [
100-
$childOneDiscountAmount,
102+
$childOneDiscountAmount + $parentDiscountAmount,
101103
[$childOneItemMock],
102104
true,
103-
$valueHasNoEffect,
105+
$parentDiscountAmount,
104106
],
105107
'two_kids' => [
106108
$childOneDiscountAmount + $childTwoDiscountAmount,

app/code/Magento/SalesRule/Model/Quote/Discount.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ public function collect(
188188
$items = $this->calculator->sortItemsByPriority($items, $address);
189189
$itemsToApplyRules = $items;
190190
$rules = $this->calculator->getRules($address);
191-
$totalDiscount = [];
192191
$address->setBaseDiscountAmount(0);
193192
/** @var Rule $rule */
194193
foreach ($rules as $rule) {
194+
$ruleTotalDiscount = 0;
195195
/** @var Item $item */
196196
foreach ($itemsToApplyRules as $key => $item) {
197197
if ($item->getNoDiscount() || !$this->calculator->canApplyDiscount($item) || $item->getParentItem()) {
@@ -222,16 +222,13 @@ public function collect(
222222
}
223223

224224
if ($item->getChildren() && $item->isChildrenCalculated()) {
225-
$childTotal = 0;
226225
foreach ($item->getChildren() as $child) {
227-
$childTotal += $child->getBaseDiscountAmount();
226+
$ruleTotalDiscount += $child->getBaseDiscountAmount();
228227
}
229-
$totalDiscount[$item->getId()] = $childTotal;
230-
} else {
231-
$totalDiscount[$item->getId()] = $item->getBaseDiscountAmount();
232228
}
229+
$ruleTotalDiscount += $item->getBaseDiscountAmount();
233230
}
234-
$address->setBaseDiscountAmount(array_sum(array_values($totalDiscount)));
231+
$address->setBaseDiscountAmount($ruleTotalDiscount);
235232
}
236233
$this->calculator->initTotals($items, $address);
237234
foreach ($items as $item) {

app/code/Magento/SalesRule/Model/Rule/Action/Discount/CartFixed.php

+7-2
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 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\SalesRule\Model\Rule\Action\Discount;
77

@@ -141,6 +141,9 @@ public function calculate($rule, $item, $qty)
141141
$baseDiscountAmount = min($baseItemPrice * $qty, $baseDiscountAmount);
142142
if ($ruleItemsCount <= 1) {
143143
$this->deltaPriceRound->reset($discountType);
144+
if ($baseDiscountAmount > $availableDiscountAmount) {
145+
$baseDiscountAmount = $availableDiscountAmount;
146+
}
144147
} else {
145148
$this->validator->decrementRuleItemTotalsCount($rule->getId());
146149
}
@@ -191,6 +194,7 @@ public function calculate($rule, $item, $qty)
191194
* Set information about usage cart fixed rule by quote address
192195
*
193196
* @deprecated 101.2.0 should be removed as it is not longer used
197+
* @see Nothing
194198
* @param int $ruleId
195199
* @param int $itemId
196200
* @return void
@@ -204,6 +208,7 @@ protected function setCartFixedRuleUsedForAddress($ruleId, $itemId)
204208
* Retrieve information about usage cart fixed rule by quote address
205209
*
206210
* @deprecated 101.2.0 should be removed as it is not longer used
211+
* @see Nothing
207212
* @param int $ruleId
208213
* @return int|null
209214
*/

0 commit comments

Comments
 (0)