Skip to content

Commit d54ae33

Browse files
committed
ACP2E-3993: GraphQl invalid discount calculation
1 parent 245c5c1 commit d54ae33

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

app/code/Magento/CatalogRule/Model/Indexer/ProductPriceCalculator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright 2017 Adobe
44
* All Rights Reserved.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\CatalogRule\Model\Indexer;
89

@@ -28,7 +29,7 @@ public function __construct(\Magento\Framework\Pricing\PriceCurrencyInterface $p
2829
* Calculates product price.
2930
*
3031
* @param array $ruleData
31-
* @param null $productData
32+
* @param array|null $productData
3233
* @return float
3334
*/
3435
public function calculate($ruleData, $productData = null)

app/code/Magento/CatalogRule/Pricing/Price/CatalogRulePrice.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@
1818
use Magento\Store\Model\StoreManagerInterface;
1919

2020
/**
21-
* Class CatalogRulePrice
22-
*
2321
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
2422
*/
2523
class CatalogRulePrice extends AbstractPrice implements BasePriceProviderInterface
2624
{
2725
/**
2826
* Price type identifier string
2927
*/
30-
const PRICE_CODE = 'catalog_rule_price';
28+
public const PRICE_CODE = 'catalog_rule_price';
3129

3230
/**
3331
* @var TimezoneInterface

app/code/Magento/CatalogRule/Test/Unit/Model/Indexer/ProductPriceCalculatorTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
declare(strict_types=1);
77

8-
98
namespace Magento\CatalogRule\Test\Unit\Model\Indexer;
109

1110
use Magento\CatalogRule\Model\Indexer\ProductPriceCalculator;
@@ -29,6 +28,7 @@ protected function setUp(): void
2928
{
3029
$this->priceCurrencyMock = $this->getMockBuilder(PriceCurrencyInterface::class)
3130
->disableOriginalConstructor()
31+
->addMethods(['roundPrice'])
3232
->getMockForAbstractClass();
3333
$this->model = new ProductPriceCalculator($this->priceCurrencyMock);
3434
}
@@ -44,8 +44,8 @@ public function testCalculateToFixedPrice()
4444
$productData = ['rule_price' => $rulePrice];
4545

4646
$this->priceCurrencyMock->expects($this->once())
47-
->method('round')
48-
->with($actionAmount)
47+
->method('roundPrice')
48+
->with($actionAmount, 4)
4949
->willReturn($actionAmount);
5050

5151
$this->assertEquals($actionAmount, $this->model->calculate($ruleData, $productData));
@@ -63,8 +63,8 @@ public function testCalculateToPercentPrice()
6363
$productData = ['rule_price' => $rulePrice];
6464

6565
$this->priceCurrencyMock->expects($this->once())
66-
->method('round')
67-
->with($expectedPrice)
66+
->method('roundPrice')
67+
->with($expectedPrice, 4)
6868
->willReturn($expectedPrice);
6969

7070
$this->assertEquals($expectedPrice, $this->model->calculate($ruleData, $productData));
@@ -82,8 +82,8 @@ public function testCalculateByFixedPrice()
8282
$productData = ['rule_price' => $rulePrice];
8383

8484
$this->priceCurrencyMock->expects($this->once())
85-
->method('round')
86-
->with($expectedPrice)
85+
->method('roundPrice')
86+
->with($expectedPrice, 4)
8787
->willReturn($expectedPrice);
8888

8989
$this->assertEquals($expectedPrice, $this->model->calculate($ruleData, $productData));
@@ -101,8 +101,8 @@ public function testCalculateByPercentPrice()
101101
$productData = ['rule_price' => $rulePrice];
102102

103103
$this->priceCurrencyMock->expects($this->once())
104-
->method('round')
105-
->with($expectedPrice)
104+
->method('roundPrice')
105+
->with($expectedPrice, 4)
106106
->willReturn($expectedPrice);
107107

108108
$this->assertEquals($expectedPrice, $this->model->calculate($ruleData, $productData));

app/code/Magento/CatalogRule/Test/Unit/Pricing/Price/CatalogRulePriceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function testGetValue()
142142
->willReturn($productId);
143143
$this->priceCurrencyMock->expects($this->once())
144144
->method('convertAndRound')
145-
->with($catalogRulePrice)
145+
->with($catalogRulePrice, null, null, 4)
146146
->willReturn($convertedPrice);
147147

148148
$this->assertEquals($convertedPrice, $this->object->getValue());
@@ -155,7 +155,7 @@ public function testGetValueFromData()
155155

156156
$this->priceCurrencyMock->expects($this->any())
157157
->method('convertAndRound')
158-
->with($catalogRulePrice)
158+
->with($catalogRulePrice, null, null, 4)
159159
->willReturn($convertedPrice);
160160

161161
$this->saleableItemMock->expects($this->once())->method('hasData')

app/code/Magento/Tax/Model/Calculation/UnitBaseCalculator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
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
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Tax\Model\Calculation;
79

810
use Magento\Tax\Api\Data\QuoteDetailsItemInterface;

0 commit comments

Comments
 (0)