0

I have multi websites site. I have multiple users with different user roles. Is there any way to save and check which admin user has added the product in admin panel backend.

2 Answers 2

1

By default, Its not possible to track which Admin user added the Products. There are two way to achive this:

  1. Third Part Extension: You can use Advanced Permission Third Party extension that provide this feature and many other features as well.

  2. Customization: Create One Product attribute Or Field in Catalog_Product_entity table While Saving the Product from backend Create Observer for event catalog_product_save_before to save logged in user Id OR user name with Product If its creating OR updating as per requirement.

5
  • Thank u. Where can i get this event catalog_product_save_before???
    – Nafsss
    Commented Mar 2, 2020 at 7:25
  • I got that. Can u tell me how can i store the details if i am using custom attribute
    – Nafsss
    Commented Mar 2, 2020 at 7:27
  • here is one example .. same way you can set values in Product meetanshi.com/blog/… Commented Mar 2, 2020 at 7:30
  • Sorry didn;t get that. I did not find it relative to my requirements.
    – Nafsss
    Commented Mar 2, 2020 at 7:35
  • Create a table for admin log and add event after each controller to track the log of admin user either it is save, edit or view for all modules not only for product. Commented Mar 2, 2020 at 7:53
0

First of all create a custom attribute called : "updated_by" from magento backend and don't forget to drag that into default attribute set otherwise it will not work!!

Add events.xml file to vendor/module/etc/adminhtml/

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="catalog_product_save_after">
        <observer name="observer_name" instance="vendor\module\Observer\ProductSaveAfter" />
    </event>
</config>

Add ProductSaveAfter.php at vendor/module/Observer/

<?php
namespace vendor\module\Observer;
use Magento\Framework\Event\ObserverInterface;
class ProductSaveAfter implements ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $instance = \Magento\Framework\App\ObjectManager::getInstance();
        $productId = (int) $observer->getProduct()->getId();
        $user = $instance->get('Magento\Backend\Model\Auth\Session')->getUser()->getUsername();
        $action = $instance->create('Magento\Catalog\Model\Product\Action');
        $action->updateAttributes([$productId], array('updated_by' => $user), 0);
    }
}

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.