Search
 
SCRIPT & CODE EXAMPLE
 

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);
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: how to know who added product in magento 
Php :: magento show which user updated the product 
Php :: what is Trustproxies handle in laravel 
Php :: php array_pop with key 
Php :: create middleware laravel 
Php :: assert symfony 
Php :: restart php service windows 
Php :: laravel excel 
Php :: spatie/laravel-activitylog display only changed data 
Php :: php fn closure 
Php :: laravel package development 
Php :: create controller codeigniter 3 
Php :: laravel route namespace 
Php :: php remove directory only if empty 
Php :: php backend generator 
Php :: https://ubuntu.com/tutorials/install-and-configure-wordpress#3-install-wordpress 
Php :: php ?? vs ?: 
Php :: wordpress add action 
Php :: open phpstorm from terminal 
Php :: preg_match in php 
Php :: sendmail folder missing in xampp 
Php :: data XML 
Php :: magento 2 add cc transportbuilder 
Php :: menyimpan get di laravel 
Php :: php file handling 
Php :: php count words in string 
Php :: laravel how to address to git repo for develop packages 
Php :: Laravel FileManager Display Blank pop up page 
Php :: php code to display a div with background fade 
Php :: php thorwable vs exception 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =