Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
quote_with_bundle_rollback.php
Go to the documentation of this file.
1 <?php
9 $registry = $objectManager->get(\Magento\Framework\Registry::class);
10 $registry->unregister('isSecureArea');
11 $registry->register('isSecureArea', true);
12 
13 // Delete quote
15 $quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
16 $quote->load('test01', 'reserved_order_id');
17 if ($quote->getId()) {
18  $quote->delete();
19 }
20 // Delete products
21 $productSkus = ['simple-1', 'simple-2', 'bundle-product'];
23 $productRepository = $objectManager->get(Magento\Catalog\Api\ProductRepositoryInterface::class);
24 foreach ($productSkus as $sku) {
25  try {
26  $product = $productRepository->get($sku, false, null, true);
28  } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
29  //Product already removed
30  }
31 }
32 
33 $registry->unregister('isSecureArea');
34 $registry->register('isSecureArea', false);
if($quote->getId()) $productSkus