I want to fire event observer when products are enabled from admin, I can not find any event for this please help on this.

I want to do below things

  1. Once the product is enabled or disabled need to mail admin.
  2. I want to do it from the Observer or any other method.

Please help!


For making a call on product save you can create a plugin to call it on product save.

For that, you have to add code in etc/adminhtml/di.xml

<type name="Magento\Catalog\Controller\Adminhtml\Product\Save">
    <plugin name="supplier_plugin_product_save_after" type="Vendor\Module\Plugin\Adminhtml\ProductSave" sortOrder="1" />

And in ProductSave.php file in Plugin/Adminhtml and add the code as per your need in code given below

namespace Vendor\Module\Plugin\Adminhtml;

use Magento\Catalog\Controller\Adminhtml\Product\Save;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Registry;
use Magento\Framework\Exception\LocalizedException;

class ProductSave
     * @var ManagerInterface
    private $messageManager;

     * @var RequestInterface
    private $request;

     * @var Registry
    private $registry;

    public function __construct(
        ManagerInterface $messageManager,
        RequestInterface $request,
        Registry $registry
    ) {
        $this->messageManager = $messageManager;
        $this->request = $request;
        $this->registry = $registry;

     * @param Save $subject
     * @param $result
     * @return mixed
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
    public function afterExecute(Save $subject, $result)
        $product = $this->registry->registry('current_product');

        $productId = $product->getId();

        $params = $this->request->getParams();

        /****  ADD YOUR LOGIC HERE ****/
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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