Skip to content

Commit 445209c

Browse files
committed
Merge branch 'ACP2E-3463' of https://github.com/adobe-commerce-tier-4/magento2ce into PR-VK-2024-11-27-CE
2 parents b7d01c3 + b1584a1 commit 445209c

File tree

2 files changed

+92
-4
lines changed

2 files changed

+92
-4
lines changed

app/code/Magento/SalesRule/Helper/CartFixedDiscount.php

Lines changed: 4 additions & 4 deletions
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 2020 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -137,9 +137,9 @@ public function getDiscountedAmountProportionally(
137137
): float {
138138
$baseItemPriceTotal = $baseItemPrice * $qty - $baseItemDiscountAmount;
139139
$ratio = $baseRuleTotalsDiscount != 0 ? $baseItemPriceTotal / $baseRuleTotalsDiscount : 0;
140-
$discountAmount = $this->deltaPriceRound->round($ruleDiscount * $ratio, $discountType);
140+
$ratio = min($ratio, 1);
141141

142-
return $discountAmount;
142+
return $this->deltaPriceRound->round($ruleDiscount * $ratio, $discountType);
143143
}
144144

145145
/**
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SalesRule\Test\Unit\Helper;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\Pricing\PriceCurrencyInterface;
12+
use Magento\Quote\Model\Cart\ShippingMethodConverter;
13+
use Magento\SalesRule\Helper\CartFixedDiscount;
14+
use Magento\SalesRule\Model\DeltaPriceRound;
15+
use PHPUnit\Framework\TestCase;
16+
use PHPUnit\Framework\MockObject\MockObject;
17+
18+
class CartFixedDiscountTest extends TestCase
19+
{
20+
/**
21+
* @var DeltaPriceRound|MockObject
22+
*/
23+
private DeltaPriceRound $deltaPriceRound;
24+
25+
/**
26+
* @var PriceCurrencyInterface|MockObject
27+
*/
28+
private PriceCurrencyInterface $priceCurrency;
29+
30+
/**
31+
* @var ShippingMethodConverter|MockObject
32+
*/
33+
private ShippingMethodConverter $shippingMethodConverter;
34+
35+
/**
36+
* @var ScopeConfigInterface|MockObject
37+
*/
38+
private ScopeConfigInterface $scopeConfig;
39+
40+
/**
41+
* @inhertidoc
42+
*/
43+
protected function setUp(): void
44+
{
45+
parent::setUp();
46+
47+
$this->deltaPriceRound = $this->createMock(DeltaPriceRound::class);
48+
$this->priceCurrency = $this->createMock(PriceCurrencyInterface::class);
49+
$this->shippingMethodConverter = $this->createMock(ShippingMethodConverter::class);
50+
$this->scopeConfig = $this->createMock(ScopeConfigInterface::class);
51+
}
52+
53+
/**
54+
* @return void
55+
*/
56+
public function testGetDiscountedAmountProportionally(): void
57+
{
58+
$ruleDiscount = 5;
59+
$qty = 2.0;
60+
$baseItemPrice = 10.0;
61+
$baseItemDiscountAmount = 0.0;
62+
$baseRuleTotalsDiscount = 10;
63+
$discountType = 'fixed';
64+
$expected = 5.0;
65+
66+
$cartFixedDiscount = new CartFixedDiscount(
67+
$this->deltaPriceRound,
68+
$this->priceCurrency,
69+
$this->shippingMethodConverter,
70+
$this->scopeConfig
71+
);
72+
$this->deltaPriceRound->expects($this->once())
73+
->method('round')
74+
->with(5, $discountType)
75+
->willReturn($expected);
76+
$this->assertSame(
77+
$expected,
78+
$cartFixedDiscount->getDiscountedAmountProportionally(
79+
$ruleDiscount,
80+
$qty,
81+
$baseItemPrice,
82+
$baseItemDiscountAmount,
83+
$baseRuleTotalsDiscount,
84+
$discountType
85+
)
86+
);
87+
}
88+
}

0 commit comments

Comments
 (0)