Skip to content

Commit ff39d2a

Browse files
committed
ACP2E-964: grand_total and base_grand_total have different values, although we have only ONE currency
- moved total without tax calculated back to the js, from where it was transferred long time ago as a part of large improvement, which led to the current issue
1 parent cd826aa commit ff39d2a

File tree

4 files changed

+55
-9
lines changed

4 files changed

+55
-9
lines changed

app/code/Magento/Quote/Model/Cart/CartTotalRepository.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ class CartTotalRepository implements CartTotalRepositoryInterface
3232
private $totalsFactory;
3333

3434
/**
35-
* Quote repository.
36-
*
3735
* @var \Magento\Quote\Api\CartRepositoryInterface
3836
*/
3937
private $quoteRepository;
@@ -109,11 +107,7 @@ public function get($cartId): QuoteTotalsInterface
109107
$items = array_map([$this->itemConverter, 'modelToDataObject'], $quote->getAllVisibleItems());
110108
$calculatedTotals = $this->totalsConverter->process($addressTotals);
111109
$quoteTotals->setTotalSegments($calculatedTotals);
112-
113-
$amount = $quoteTotals->getGrandTotal() - $quoteTotals->getTaxAmount();
114-
$amount = $amount > 0 ? $amount : 0;
115110
$quoteTotals->setCouponCode($this->couponService->get($cartId));
116-
$quoteTotals->setGrandTotal($amount);
117111
$quoteTotals->setItems($items);
118112
$quoteTotals->setItemsQty($quote->getItemsQty());
119113
$quoteTotals->setBaseCurrencyCode($quote->getBaseCurrencyCode());

app/code/Magento/Quote/Test/Unit/Model/Cart/CartTotalRepositoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public function testGetCartTotal($isVirtual, $getAddressType): void
231231
->method('setCouponCode')
232232
->with(self::STUB_COUPON)
233233
->willReturnSelf();
234-
$totalsMock->expects($this->once())
234+
$totalsMock->expects($this->never())
235235
->method('setGrandTotal')
236236
->willReturnSelf();
237237
$totalsMock->expects($this->once())

app/code/Magento/Tax/view/frontend/web/js/view/checkout/summary/grand-total.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,20 @@ define([
6060
* @return {*}
6161
*/
6262
getGrandTotalExclTax: function () {
63-
var total = this.totals();
63+
var total = this.totals(),
64+
amount;
6465

6566
if (!total) {
6667
return 0;
6768
}
6869

69-
return this.getFormattedPrice(total['grand_total']);
70+
amount = this.getFormattedPrice(total['grand_total'] - total['tax_amount']);
71+
72+
if (amount < 0) {
73+
return 0;
74+
}
75+
76+
return amount;
7077
},
7178

7279
/**

dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,23 @@
66
*/
77
namespace Magento\Quote\Api;
88

9+
use Magento\Catalog\Model\Indexer\Product\Category\Processor;
10+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
11+
use Magento\Checkout\Test\Fixture\SetBillingAddress as SetBillingAddressFixture;
12+
use Magento\Checkout\Test\Fixture\SetDeliveryMethod as SetDeliveryMethodFixture;
13+
use Magento\Checkout\Test\Fixture\SetGuestEmail as SetGuestEmailFixture;
14+
use Magento\Checkout\Test\Fixture\SetPaymentMethod as SetPaymentMethodFixture;
15+
use Magento\Checkout\Test\Fixture\SetShippingAddress as SetShippingAddressFixture;
16+
use Magento\Quote\Api\Data\AddressInterface;
917
use Magento\Quote\Model\Cart\Totals;
1018
use Magento\Quote\Model\Cart\Totals\Item as ItemTotals;
1119
use Magento\Framework\Api\FilterBuilder;
1220
use Magento\Framework\Api\SearchCriteriaBuilder;
21+
use Magento\Quote\Test\Fixture\AddProductToCart as AddProductToCartFixture;
22+
use Magento\Quote\Test\Fixture\GuestCart as GuestCartFixture;
23+
use Magento\Tax\Test\Fixture\TaxRule as TaxRule;
24+
use Magento\TestFramework\Fixture\DataFixture;
25+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
1326
use Magento\TestFramework\ObjectManager;
1427
use Magento\TestFramework\TestCase\WebapiAbstract;
1528
use Magento\Quote\Model\Quote;
@@ -22,6 +35,11 @@ class CartTotalRepositoryTest extends WebapiAbstract
2235
*/
2336
private $objectManager;
2437

38+
/**
39+
* @var Processor
40+
*/
41+
private $indexer;
42+
2543
/**
2644
* @var SearchCriteriaBuilder
2745
*/
@@ -41,6 +59,7 @@ protected function setUp(): void
4159
$this->filterBuilder = $this->objectManager->create(
4260
\Magento\Framework\Api\FilterBuilder::class
4361
);
62+
$this->fixtures = $this->objectManager->get(DataFixtureStorageManager::class)->getStorage();
4463
}
4564

4665
/**
@@ -73,6 +92,32 @@ public function testGetTotals()
7392
$this->assertEquals($data, $actual);
7493
}
7594

95+
/**
96+
* @magentoConfigFixture default_store tax/defaults/region 43
97+
* @magentoConfigFixture default_store tax/defaults/postcode 10036
98+
* @magentoConfigFixture default_store shipping/origin/region_id 43
99+
* @magentoConfigFixture default_store shipping/origin/postcode 10011
100+
*/
101+
#[
102+
DataFixture(TaxRule::class, ['tax_rate_ids' => [2], 'product_tax_class_ids' => [2], 'customer_tax_class_ids' => [3], 'code' => 'TaxRule1'], 'tax_rule'),
103+
DataFixture(ProductFixture::class, ['price'=>5], 'product'),
104+
DataFixture(GuestCartFixture::class, as: 'cart'),
105+
DataFixture(AddProductToCartFixture::class, ['cart_id' => '$cart.id$', 'product_id' => '$product.id$']),
106+
DataFixture(SetBillingAddressFixture::class, ['cart_id' => '$cart.id$', 'address' => [AddressInterface::KEY_POSTCODE => 10036, AddressInterface::KEY_CITY => 'New York', AddressInterface::KEY_REGION_ID => 43] ]),
107+
DataFixture(SetShippingAddressFixture::class, ['cart_id' => '$cart.id$', 'address' => [AddressInterface::KEY_POSTCODE => 10036, AddressInterface::KEY_CITY => 'New York', AddressInterface::KEY_REGION_ID => 43] ]),
108+
DataFixture(SetGuestEmailFixture::class, ['cart_id' => '$cart.id$']),
109+
DataFixture(SetDeliveryMethodFixture::class, ['cart_id' => '$cart.id$']),
110+
DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$cart.id$']),
111+
]
112+
public function testGetGrandTotalsWithIncludedTaxAndSameCurrency()
113+
{
114+
$cart = $this->fixtures->get('cart');
115+
$cartId = $cart->getid();
116+
$requestData = ['cartId' => $cartId];
117+
$actual = $this->_webApiCall($this->getServiceInfoForTotalsService($cartId), $requestData);
118+
$this->assertEquals($actual['base_grand_total'], $actual['grand_total']);
119+
}
120+
76121
/**
77122
*/
78123
public function testGetTotalsWithAbsentQuote()

0 commit comments

Comments
 (0)