Sharing some useful tips, solutions and notes for Geeks.

Tuesday, October 17, 2017

Magento PHP Fatal error: Uncaught exception 'Mage_Core_Exception' with message 'Cannot complete this operation from non-admin area.

Yesterday when i was trying to write a custom code for deleting product, i got stuck with a problem.

"PHP Fatal error:  Uncaught exception 'Mage_Core_Exception' with message 'Cannot complete this operation from non-admin area."


$product->delete();

This along wont works and simply will return above error in frontend. So to fix the issue just wrap with below code,


Mage::register('isSecureArea', true);
$product->delete();
Mage::unregister('isSecureArea');


We all know products are to be deleted from admin. What we are telling here is we are deleting product from secure area. Once we deleted that product, we set it back to normal.

How wonderful it is, right?

No comments: