Skip to content

Commit 29f0417

Browse files
author
Mastiuhin Olexandr
committed
MC-25098: Product is not deleted from minicart if not included in shared catalog
1 parent 1ad65a3 commit 29f0417

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
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: 30 additions & 0 deletions
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;
@@ -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)