@@ -85,6 +85,16 @@ class QuoteRepositoryTest extends TestCase
85
85
*/
86
86
private $ quote ;
87
87
88
+ /**
89
+ * @var \Magento\Quote\Model\QuoteFactory
90
+ */
91
+ private $ quoteFactorys ;
92
+
93
+ /**
94
+ * @var \Magento\Store\Model\Store
95
+ */
96
+ private $ store ;
97
+
88
98
/**
89
99
* @inheritdoc
90
100
*/
@@ -101,6 +111,8 @@ protected function setUp(): void
101
111
$ this ->addressFactory = $ this ->objectManager ->get (AddressInterfaceFactory::class);
102
112
$ this ->quoteFactory = $ this ->objectManager ->get (CartInterfaceFactory::class);
103
113
$ 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);
104
116
}
105
117
106
118
/**
@@ -278,4 +290,71 @@ private function performAssertions(CartSearchResultsInterface $searchResult): vo
278
290
$ this ->assertEquals ($ expectedExtensionAttributes ['lastname ' ], $ testAttribute ->getLastName ());
279
291
$ this ->assertEquals ($ expectedExtensionAttributes ['email ' ], $ testAttribute ->getEmail ());
280
292
}
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
+ }
281
360
}
0 commit comments