Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
products_bundle_rollback.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
10 use Magento\CatalogInventory\Api\StockStatusCriteriaInterfaceFactory;
15 
16 $objectManager = Bootstrap::getObjectManager();
18 $productRepository = $objectManager->create(ProductRepositoryInterface::class);
20 $registry = $objectManager->get(Registry::class);
22 $stockStatusRepository = $objectManager->create(StockStatusRepositoryInterface::class);
24 $stockStatusCriteriaFactory = $objectManager->create(StockStatusCriteriaInterfaceFactory::class);
26 $searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class);
28  ProductInterface::SKU,
29  ['SKU-BUNDLE-2', 'SKU-BUNDLE-3'],
30  'in'
31 )->create();
37 if (!empty($products)) {
38  $currentArea = $registry->registry('isSecureArea');
39  $registry->unregister('isSecureArea');
40  $registry->register('isSecureArea', true);
41  foreach ($products as $product) {
42  $criteria = $stockStatusCriteriaFactory->create();
43  $criteria->setProductsFilter($product->getId());
44  $result = $stockStatusRepository->getList($criteria);
45  if ($result->getTotalCount()) {
46  $stockStatus = current($result->getItems());
47  $stockStatusRepository->delete($stockStatus);
48  }
50  }
51  $registry->unregister('isSecureArea');
52  $registry->register('isSecureArea', $currentArea);
53 }
$stockStatusCriteriaFactory