How to get the current product id.
I don't want to get the product information from id (I want to get only the current id dynamically, not by assigning some value and get through object manager).
Currently I have used something like:
Event.xml
<event name="catalog_product_delete_after">
<observer name="catalog_product_delete_after_handler" instance="Vendor\Module\Observer\SyncProductDeleteObserver"/>
</event>
Observer:
public function execute(EventObserver $observer)
{
$productdel = $observer->getEvent()->getProduct();
$this->productDelete($productdel);
return $this;
}
public function productDelete($productdel)
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productdel = $objectManager->get('Magento\Framework\Registry')->registry('current_product');
$productid=$productdel->getEntityId();
....
ERROR:
I get getEntityid() on null during product delete.
I want to use an alternative to registry()
.
Please provide any other method?