7
7
8
8
namespace Magento \Quote \Model ;
9
9
10
+ use Magento \Customer \Api \CustomerRepositoryInterface ;
10
11
use Magento \Framework \Api \FilterBuilder ;
11
12
use Magento \Framework \Api \SearchCriteria ;
12
13
use Magento \Framework \Api \SearchCriteriaBuilder ;
@@ -85,6 +86,21 @@ class QuoteRepositoryTest extends TestCase
85
86
*/
86
87
private $ quote ;
87
88
89
+ /**
90
+ * @var \Magento\Quote\Model\QuoteFactory
91
+ */
92
+ private $ quoteFactorys ;
93
+
94
+ /**
95
+ * @var \Magento\Store\Model\Store
96
+ */
97
+ private $ store ;
98
+
99
+ /**
100
+ * @var CustomerRepositoryInterface
101
+ */
102
+ private $ customerRepository ;
103
+
88
104
/**
89
105
* @inheritdoc
90
106
*/
@@ -101,6 +117,9 @@ protected function setUp(): void
101
117
$ this ->addressFactory = $ this ->objectManager ->get (AddressInterfaceFactory::class);
102
118
$ this ->quoteFactory = $ this ->objectManager ->get (CartInterfaceFactory::class);
103
119
$ this ->itemFactory = $ this ->objectManager ->get (CartItemInterfaceFactory::class);
120
+ $ this ->quoteFactorys = $ this ->objectManager ->get (\Magento \Quote \Model \QuoteFactory::class);
121
+ $ this ->store = $ this ->objectManager ->get (\Magento \Store \Model \Store::class);
122
+ $ this ->customerRepository = $ this ->objectManager ->get (CustomerRepositoryInterface::class);
104
123
}
105
124
106
125
/**
@@ -278,4 +297,88 @@ private function performAssertions(CartSearchResultsInterface $searchResult): vo
278
297
$ this ->assertEquals ($ expectedExtensionAttributes ['lastname ' ], $ testAttribute ->getLastName ());
279
298
$ this ->assertEquals ($ expectedExtensionAttributes ['email ' ], $ testAttribute ->getEmail ());
280
299
}
300
+
301
+ /**
302
+ * @magentoDataFixture Magento/Customer/_files/customer.php
303
+ * @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product.php
304
+ * @magentoDbIsolation disabled
305
+ * @return void
306
+ * @throws \Exception
307
+ */
308
+ public function testDeleteAllQuotesOnStoreViewDeletion (): void
309
+ {
310
+ $ storeData = [
311
+ [
312
+ 'code ' => 'store1 ' ,
313
+ 'website_id ' => 1 ,
314
+ 'group_id ' => 1 ,
315
+ 'name ' => 'Store 1 ' ,
316
+ 'sort_order ' => 0 ,
317
+ 'is_active ' => 1 ,
318
+ ],
319
+ [
320
+ 'code ' => 'store2 ' ,
321
+ 'website_id ' => 1 ,
322
+ 'group_id ' => 1 ,
323
+ 'name ' => 'Store 2 ' ,
324
+ 'sort_order ' => 1 ,
325
+ 'is_active ' => 1 ,
326
+ ],
327
+ ];
328
+
329
+ foreach ($ storeData as $ storeInfo ) {
330
+ $ this ->objectManager ->create (\Magento \Store \Model \Store::class)
331
+ ->setData ($ storeInfo )
332
+ ->save ();
333
+ }
334
+
335
+ // Fetching the store id
336
+ $ firstStoreId = $ this ->store ->load ('store1 ' )->getId ();
337
+ $ secondStoreId = $ this ->store ->load ('store2 ' )->getId ();
338
+
339
+ // Create a quote for guest user with store id 2
340
+ $ quote = $ this ->quoteFactorys ->create ();
341
+ $ quote ->setStoreId ($ firstStoreId );
342
+ $ quote ->save ();
343
+
344
+ // Assert that quote is created successfully.
345
+ $ this ->assertNotNull ($ quote ->getId ());
346
+
347
+ // Create a quote for guest user with store id 3
348
+ $ secondQuote = $ this ->quoteFactorys ->create ();
349
+ $ secondQuote ->setStoreId ($ secondStoreId );
350
+ $ secondQuote ->save ();
351
+
352
+ // Assert that second quote is created successfully.
353
+ $ this ->assertNotNull ($ secondQuote ->getId ());
354
+
355
+ // load customer by id
356
+ $ customer = $ this ->customerRepository ->getById (1 );
357
+
358
+ // Create a quote for customer with store id 3
359
+ $ thirdQuote = $ this ->quoteFactorys ->create ();
360
+ $ thirdQuote ->setStoreId ($ secondStoreId );
361
+ $ thirdQuote ->setCustomer ($ customer );
362
+ $ thirdQuote ->save ();
363
+
364
+ // Loading the second store from the data fixture
365
+ $ this ->store ->load ('store2 ' , 'code ' );
366
+ /** @var \Magento\TestFramework\Helper\Bootstrap $registry */
367
+ $ registry = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
368
+ \Magento \Framework \Registry::class
369
+ );
370
+ $ registry ->unregister ('isSecureArea ' );
371
+ $ registry ->register ('isSecureArea ' , true );
372
+
373
+ // Deleting the second store.
374
+ $ this ->store ->delete ();
375
+
376
+ // asserting that quote associated with guest user is also deleted when store is deleted
377
+ $ afterDeletionQuote = $ this ->quoteFactorys ->create ()->load ($ secondQuote ->getId ());
378
+ $ this ->assertNull ($ afterDeletionQuote ->getId ());
379
+
380
+ // asserting that quote associated with customer is also deleted when store is deleted
381
+ $ afterDeletionQuote = $ this ->quoteFactorys ->create ()->load ($ thirdQuote ->getId ());
382
+ $ this ->assertNull ($ afterDeletionQuote ->getId ());
383
+ }
281
384
}
0 commit comments