Skip to content

Commit 04420ea

Browse files
committed
BUG#AC-1084:GraphQl subtotal_with_discount_excluding_tax is calculated using discount including tax - issue fixed
1 parent f0a55cb commit 04420ea

File tree

2 files changed

+149
-2
lines changed

2 files changed

+149
-2
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/CartPrices.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Magento\Quote\Model\Quote\Address\Total;
1818
use Magento\QuoteGraphQl\Model\Cart\TotalsCollector;
1919
use Magento\Store\Model\ScopeInterface;
20-
use Magento\Tax\Model\Config;
2120

2221
/**
2322
* @inheritdoc
@@ -132,7 +131,7 @@ private function getDiscount(Total $total, string $currency)
132131
private function getSubtotalWithDiscountExcludingTax(Total $cartTotals): float
133132
{
134133
$discountIncludeTax = $this->scopeConfig->getValue(
135-
Config::CONFIG_XML_PATH_DISCOUNT_TAX,
134+
'tax/calculation/discount_tax',
136135
ScopeInterface::SCOPE_STORE
137136
) ?? 0;
138137
$discountExclTax = $discountIncludeTax ?
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\QuoteGraphQl\Test\Unit\Model\Resolver;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\GraphQl\Config\Element\Field;
13+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
14+
use Magento\GraphQl\Model\Query\Context;
15+
use Magento\Quote\Model\Quote;
16+
use Magento\Quote\Model\Quote\Address\Total;
17+
use Magento\QuoteGraphQl\Model\Cart\TotalsCollector;
18+
use Magento\QuoteGraphQl\Model\Resolver\CartPrices;
19+
use PHPUnit\Framework\TestCase;
20+
use PHPUnit\Framework\MockObject\MockObject;
21+
22+
/**
23+
* @see CartPrices
24+
*/
25+
class CartPricesTest extends TestCase
26+
{
27+
/**
28+
* @var CartPrices
29+
*/
30+
private CartPrices $cartPrices;
31+
32+
/**
33+
* @var TotalsCollector|MockObject
34+
*/
35+
private TotalsCollector $totalsCollectorMock;
36+
37+
/**
38+
* @var ScopeConfigInterface|MockObject
39+
*/
40+
private ScopeConfigInterface $scopeConfigMock;
41+
42+
/**
43+
* @var Field|MockObject
44+
*/
45+
private Field $fieldMock;
46+
47+
/**
48+
* @var ResolveInfo|MockObject
49+
*/
50+
private ResolveInfo $resolveInfoMock;
51+
52+
/**
53+
* @var Context|MockObject
54+
*/
55+
private Context $contextMock;
56+
57+
/**
58+
* @var Quote|MockObject
59+
*/
60+
private Quote $quoteMock;
61+
62+
/**
63+
* @var Total|MockObject
64+
*/
65+
private Total $totalMock;
66+
67+
/**
68+
* @var array
69+
*/
70+
private array $valueMock = [];
71+
72+
protected function setUp(): void
73+
{
74+
$this->totalsCollectorMock = $this->createMock(TotalsCollector::class);
75+
$this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
76+
$this->fieldMock = $this->createMock(Field::class);
77+
$this->resolveInfoMock = $this->createMock(ResolveInfo::class);
78+
$this->contextMock = $this->createMock(Context::class);
79+
$this->quoteMock = $this->getMockBuilder(Quote::class)
80+
->disableOriginalConstructor()
81+
->addMethods(['getQuoteCurrencyCode'])
82+
->getMock();
83+
$this->totalMock = $this->getMockBuilder(Total::class)
84+
->disableOriginalConstructor()
85+
->addMethods(
86+
[
87+
'getSubtotal',
88+
'getSubtotalInclTax',
89+
'getGrandTotal',
90+
'getDiscountTaxCompensationAmount',
91+
'getDiscountAmount',
92+
'getDiscountDescription',
93+
'getAppliedTaxes'
94+
]
95+
)
96+
->getMock();
97+
$this->cartPrices = new CartPrices(
98+
$this->totalsCollectorMock,
99+
$this->scopeConfigMock
100+
);
101+
}
102+
103+
public function testResolveWithoutModelInValueParameter(): void
104+
{
105+
$this->expectException(LocalizedException::class);
106+
$this->expectExceptionMessage('"model" value should be specified');
107+
$this->cartPrices->resolve($this->fieldMock, $this->contextMock, $this->resolveInfoMock, $this->valueMock);
108+
}
109+
110+
public function testResolve(): void
111+
{
112+
$this->valueMock = ['model' => $this->quoteMock];
113+
$this->quoteMock
114+
->expects($this->once())
115+
->method('getQuoteCurrencyCode')
116+
->willReturn('USD');
117+
$this->totalMock
118+
->expects($this->once())
119+
->method('getGrandTotal');
120+
$this->totalMock
121+
->expects($this->exactly(2))
122+
->method('getSubtotal');
123+
$this->totalMock
124+
->expects($this->once())
125+
->method('getSubtotalInclTax');
126+
$this->totalMock
127+
->expects($this->once())
128+
->method('getDiscountDescription')
129+
->willReturn('Discount Description');
130+
$this->totalMock
131+
->expects($this->once())
132+
->method('getAppliedTaxes');
133+
$this->scopeConfigMock
134+
->expects($this->once())
135+
->method('getValue')
136+
->willReturn(1);
137+
$this->totalMock
138+
->expects($this->atLeast(2))
139+
->method('getDiscountAmount');
140+
$this->totalMock
141+
->expects($this->once())
142+
->method('getDiscountTaxCompensationAmount');
143+
$this->totalsCollectorMock
144+
->method('collectQuoteTotals')
145+
->willReturn($this->totalMock);
146+
$this->cartPrices->resolve($this->fieldMock, $this->contextMock, $this->resolveInfoMock, $this->valueMock);
147+
}
148+
}

0 commit comments

Comments
 (0)