Skip to content

magento/magento2#39036: Issue with multiple percentage discounts #39683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: 2.4-develop
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?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;

class ByPercent extends AbstractDiscount
Expand Down Expand Up @@ -68,7 +69,11 @@ protected function _calculate($rule, $item, $qty, $rulePercent)
);

if (!$rule->getDiscountQty() || $rule->getDiscountQty() >= $qty) {
$discountPercent = min(100, $item->getDiscountPercent() + $rulePercent);
$previousDiscountPercent = $item->getDiscountPercent() ?: 0.0;
$totalDiscountPercent = ($rulePercent + $previousDiscountPercent) - (
($rulePercent * $previousDiscountPercent)/100
);
$discountPercent = min(100, $totalDiscountPercent);
$item->setDiscountPercent($discountPercent);
}

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.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -218,7 +218,7 @@ public static function calculateDataProvider()
'originalPrice' => 60,
'baseOriginalPrice' => 55,
],
'expectedRuleDiscountQty' => 85,
'expectedRuleDiscountQty' => 68.5,
'expectedDiscountData' => [
'amount' => 42,
'baseAmount' => 25.5,
Expand All @@ -236,7 +236,7 @@ public static function calculateDataProvider()
'originalPrice' => 60,
'baseOriginalPrice' => 55,
],
'expectedRuleDiscountQty' => 85,
'expectedRuleDiscountQty' => 68.5,
'expectedDiscountData' => [
'amount' => 72,
'baseAmount' => 52.5,
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.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -218,7 +218,7 @@ public static function calculateDataProvider()
'originalPrice' => 60,
'baseOriginalPrice' => 55,
],
'expectedRuleDiscountQty' => 100,
'expectedRuleDiscountQty' => 86.5,
'expectedDiscountData' => [
'amount' => 98,
'baseAmount' => 59.49999999999999,
Expand Down