Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

magento check which user has added a product

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="vendormoduleObserverProductSaveAfter" />
    </event>
</config>
Add ProductSaveAfter.php at vendor/module/Observer/

<?php
namespace vendormoduleObserver;
use MagentoFrameworkEventObserverInterface;
class ProductSaveAfter implements ObserverInterface
{
    public function execute(MagentoFrameworkEventObserver $observer)
    {
        $instance = MagentoFrameworkAppObjectManager::getInstance();
        $productId = (int) $observer->getProduct()->getId();
        $user = $instance->get('MagentoBackendModelAuthSession')->getUser()->getUsername();
        $action = $instance->create('MagentoCatalogModelProductAction');
        $action->updateAttributes([$productId], array('updated_by' => $user), 0);
    }
}
 
PREVIOUS NEXT
Tagged: #magento #check #user #added #product
ADD COMMENT
Topic
Name
3+3 =