Skip to content

Commit 08ba757

Browse files
committed
MC-37884: [GraphQL] Cart Price Rule for the Whole Cart with coupon does not apply
1 parent a1e5689 commit 08ba757

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Quote\Model\Quote;
1515
use Magento\Quote\Model\Quote\Address\Total;
1616
use Magento\Quote\Model\Quote\TotalsCollector;
17+
use Magento\SalesRule\Model\Spi\QuoteResetAppliedRulesInterface;
1718

1819
/**
1920
* @inheritdoc
@@ -25,13 +26,21 @@ class CartPrices implements ResolverInterface
2526
*/
2627
private $totalsCollector;
2728

29+
/**
30+
* @var QuoteResetAppliedRulesInterface
31+
*/
32+
private $resetAppliedRules;
33+
2834
/**
2935
* @param TotalsCollector $totalsCollector
36+
* @param QuoteResetAppliedRulesInterface $resetAppliedRules
3037
*/
3138
public function __construct(
32-
TotalsCollector $totalsCollector
39+
TotalsCollector $totalsCollector,
40+
QuoteResetAppliedRulesInterface $resetAppliedRules
3341
) {
3442
$this->totalsCollector = $totalsCollector;
43+
$this->resetAppliedRules = $resetAppliedRules;
3544
}
3645

3746
/**
@@ -45,6 +54,12 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
4554

4655
/** @var Quote $quote */
4756
$quote = $value['model'];
57+
/**
58+
* To calculate a right discount value
59+
* before calculate totals
60+
* need to reset Cart Fixed Rules in the quote
61+
*/
62+
$this->resetAppliedRules->execute($quote);
4863
$cartTotals = $this->totalsCollector->collectQuoteTotals($quote);
4964
$currency = $quote->getQuoteCurrencyCode();
5065

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/ApplyCouponsToCartTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class ApplyCouponsToCartTest extends GraphQlAbstract
2121
*/
2222
private $getMaskedQuoteIdByReservedOrderId;
2323

24+
/**
25+
* @inheritdoc
26+
*/
2427
protected function setUp(): void
2528
{
2629
$objectManager = Bootstrap::getObjectManager();
@@ -36,12 +39,17 @@ protected function setUp(): void
3639
public function testApplyCouponsToCart()
3740
{
3841
$couponCode = '2?ds5!2d';
42+
$expectedGrandTotal = 15.00;
3943
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
4044
$query = $this->getQuery($maskedQuoteId, $couponCode);
4145
$response = $this->graphQlMutation($query);
4246

4347
self::assertArrayHasKey('applyCouponToCart', $response);
4448
self::assertEquals($couponCode, $response['applyCouponToCart']['cart']['applied_coupons'][0]['code']);
49+
self::assertEquals(
50+
$expectedGrandTotal,
51+
$response['applyCouponToCart']['cart']['prices']['grand_total']['value']
52+
);
4553
}
4654

4755
/**
@@ -146,6 +154,11 @@ private function getQuery(string $maskedQuoteId, string $couponCode): string
146154
applied_coupons {
147155
code
148156
}
157+
prices {
158+
grand_total {
159+
value
160+
}
161+
}
149162
}
150163
}
151164
}

0 commit comments

Comments
 (0)