Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
products_related_rollback.php
Go to the documentation of this file.
1 <?php
8 
11 
12 $registry->unregister('isSecureArea');
13 $registry->register('isSecureArea', true);
14 
16 $productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
17 
18 try {
19  $firstProduct = $productRepository->get('simple', false, null, true);
20  $productRepository->delete($firstProduct);
21 } catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
22  //Product already removed
23 }
24 
25 try {
26  $secondProduct = $productRepository->get('simple_with_cross', false, null, true);
27  $productRepository->delete($secondProduct);
28 } catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
29  //Product already removed
30 }
31 
32 $registry->unregister('isSecureArea');
33 $registry->register('isSecureArea', false);