Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
product_with_two_websites_rollback.php
Go to the documentation of this file.
1 <?php
8 
11  ->get(\Magento\Framework\Registry::class);
12 $registry->unregister("isSecureArea");
13 $registry->register("isSecureArea", true);
14 
16 $website = $objectManager->get(Magento\Store\Model\Website::class);
17 $website->load('second_website', 'code');
18 if ($website->getId()) {
19  $website->delete();
20 }
21 
23 $productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
24 
25 try {
26  $firstProduct = $productRepository->get('unique-simple-azaza');
27  $productRepository->delete($firstProduct);
28 } catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
29  //Product already removed
30 }
31 
32 $registry->unregister('isSecureArea');
33 $registry->register('isSecureArea', false);
34 
35 $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)->reinitStores();