0

I want to delete the products from frontend side, but using object manager. I does not want to using any registry object.

1
  • Did you try anything? Post your code here.
    – Sohel Rana
    May 9, 2017 at 11:43

2 Answers 2

4
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$product = $objectManager->create('Magento\Catalog\Model\Product');
$product->load($productID)->delete();
7
  • it doesn't work May 9, 2017 at 11:58
  • What is the error ? May 9, 2017 at 12:01
  • this code does't shows any error May 9, 2017 at 12:03
  • Ok. Product is deleted ? May 9, 2017 at 12:10
  • 1
    This works for now, but the delete method is deprecated and it will go away at one point.
    – Marius
    May 9, 2017 at 12:50
0
//get product id
$productID = 10;

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 

$product = $objectManager->get('Magento\Framework\Registry');

//set isSecureArea code here

$product->registry('isSecureArea',true);

$product->delete();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.