Skip to content

Commit f7564e0

Browse files
committed
Merge remote-tracking branch 'origin/MC-25098' into 2.4-develop-pr3
2 parents 204484d + ae8cb2c commit f7564e0

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

app/code/Magento/Checkout/Model/Session.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ public function getQuote()
272272
*/
273273
$quote = $this->quoteRepository->get($this->getQuoteId());
274274
}
275+
276+
if ($quote->getTotalsCollectedFlag() === false) {
277+
$quote->collectTotals();
278+
}
275279
} catch (NoSuchEntityException $e) {
276280
$this->setQuoteId(null);
277281
}

dev/tests/integration/testsuite/Magento/Checkout/Model/SessionTest.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Catalog\Api\Data\ProductTierPriceInterface;
99
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
1011
use Magento\Customer\Api\CustomerRepositoryInterface;
1112
use Magento\Customer\Model\Session as CustomerSession;
1213
use Magento\Framework\Api\FilterBuilder;
@@ -17,7 +18,7 @@
1718
use Magento\TestFramework\Helper\Bootstrap;
1819

1920
/**
20-
* Class SessionTest
21+
* Checkout Session model test.
2122
*
2223
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2324
*/
@@ -54,6 +55,35 @@ protected function setUp()
5455
$this->checkoutSession = $this->objectManager->create(Session::class);
5556
}
5657

58+
/**
59+
* Tests that quote items and totals are correct when product becomes unavailable.
60+
*
61+
* @magentoDataFixture Magento/Customer/_files/customer.php
62+
* @magentoDataFixture Magento/Sales/_files/quote.php
63+
* @magentoAppIsolation enabled
64+
*/
65+
public function testGetQuoteWithUnavailableProduct()
66+
{
67+
$reservedOrderId = 'test01';
68+
$quoteGrandTotal = 10;
69+
70+
$quote = $this->getQuote($reservedOrderId);
71+
$this->assertEquals(1, $quote->getItemsCount());
72+
$this->assertCount(1, $quote->getItems());
73+
$this->assertEquals($quoteGrandTotal, $quote->getShippingAddress()->getBaseGrandTotal());
74+
75+
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
76+
$product = $productRepository->get('simple');
77+
$product->setStatus(Status::STATUS_DISABLED);
78+
$productRepository->save($product);
79+
$this->checkoutSession->setQuoteId($quote->getId());
80+
$quote = $this->checkoutSession->getQuote();
81+
82+
$this->assertEquals(0, $quote->getItemsCount());
83+
$this->assertEmpty($quote->getItems());
84+
$this->assertEquals(0, $quote->getShippingAddress()->getBaseGrandTotal());
85+
}
86+
5787
/**
5888
* Test covers case when quote is not yet initialized and customer data is set to checkout session model.
5989
*

0 commit comments

Comments
 (0)