Skip to content

Commit 45730f6

Browse files
akaashakaash
authored andcommitted
ACQE-5313 | All quotes related to custom store should be deleted if we delete the store view
1 parent 824661b commit 45730f6

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

dev/tests/integration/testsuite/Magento/Quote/Model/QuoteRepositoryTest.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ class QuoteRepositoryTest extends TestCase
8585
*/
8686
private $quote;
8787

88+
/**
89+
* @var \Magento\Quote\Model\QuoteFactory
90+
*/
91+
private $quoteFactorys;
92+
93+
/**
94+
* @var \Magento\Store\Model\Store
95+
*/
96+
private $store;
97+
8898
/**
8999
* @inheritdoc
90100
*/
@@ -101,6 +111,8 @@ protected function setUp(): void
101111
$this->addressFactory = $this->objectManager->get(AddressInterfaceFactory::class);
102112
$this->quoteFactory = $this->objectManager->get(CartInterfaceFactory::class);
103113
$this->itemFactory = $this->objectManager->get(CartItemInterfaceFactory::class);
114+
$this->quoteFactorys = $this->objectManager->get(\Magento\Quote\Model\QuoteFactory::class);
115+
$this->store = $this->objectManager->get(\Magento\Store\Model\Store::class);
104116
}
105117

106118
/**
@@ -278,4 +290,71 @@ private function performAssertions(CartSearchResultsInterface $searchResult): vo
278290
$this->assertEquals($expectedExtensionAttributes['lastname'], $testAttribute->getLastName());
279291
$this->assertEquals($expectedExtensionAttributes['email'], $testAttribute->getEmail());
280292
}
293+
294+
/**
295+
* @magentoDataFixture Magento/Customer/_files/customer.php
296+
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product.php
297+
* @magentoDbIsolation disabled
298+
* @return void
299+
* @throws \Exception
300+
*/
301+
public function testDeleteAllQuotesRelatedToCustomerIfWeDeleteStoreView(): void
302+
{
303+
$storeData = [
304+
[
305+
'code' => 'store1',
306+
'website_id' => 1,
307+
'group_id' => 1,
308+
'name' => 'Store 1',
309+
'sort_order' => 0,
310+
'is_active' => 1,
311+
],
312+
[
313+
'code' => 'store2',
314+
'website_id' => 1,
315+
'group_id' => 1,
316+
'name' => 'Store 2',
317+
'sort_order' => 1,
318+
'is_active' => 1,
319+
],
320+
];
321+
322+
foreach ($storeData as $storeInfo) {
323+
$this->objectManager->create(\Magento\Store\Model\Store::class)
324+
->setData($storeInfo)
325+
->save();
326+
}
327+
328+
// Create a quote with store id 2
329+
$quote = $this->quoteFactorys->create();
330+
$quote->setStoreId(2);
331+
$quote->save();
332+
333+
// Assert that quote is created successfully.
334+
$this->assertNotNull($quote->getId());
335+
336+
// Create a quote with store id 3
337+
$secondQuote = $this->quoteFactorys->create();
338+
$secondQuote->setStoreId(3);
339+
$secondQuote->save();
340+
341+
// Assert that second quote is created successfully.
342+
$this->assertNotNull($secondQuote->getId());
343+
344+
// Loading the second store from the data fixture
345+
$this->store->load('store2', 'code');
346+
/** @var \Magento\TestFramework\Helper\Bootstrap $registry */
347+
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
348+
\Magento\Framework\Registry::class
349+
);
350+
$registry->unregister('isSecureArea');
351+
$registry->register('isSecureArea', true);
352+
353+
// Deleting the second store.
354+
$this->store->delete();
355+
356+
// asserting that quote is also deleted when store is deleted
357+
$afterDeletionQuote = $this->quoteFactorys->create()->load($secondQuote->getId());
358+
$this->assertNull($afterDeletionQuote->getId());
359+
}
281360
}

0 commit comments

Comments
 (0)