Search
 
SCRIPT & CODE EXAMPLE
 

PHP

magento show which user updated the 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 :: assign random to a variable in PHP 
Php :: how to get private images in s3 laravel 
Php :: php array_pop with key 
Php :: what is php file 
Php :: laravel blade @if 3 varabile 
Php :: Make livewire component 
Php :: pass variable to blade laravel 
Php :: php return multiple variables from function 
Php :: What is the purpose of an abstract? 
Php :: laravel mail 
Php :: php loopthrough object 
Php :: In PackageManifest.phpIn PackageManifest.php line 122: Undefined index: name line 122: Undefined index: name 
Php :: delete rows by migration laravel 
Php :: PHP if...else...elseif Statements 
Php :: Code to check Check whether a year is leap year or not 
Php :: Basic HTTP Authentication example 
Php :: string operator in php 
Php :: how to execute php in linux 
Php :: join multiple query in laravel 
Php :: cache for php website 
Php :: PHP Example - AJAX and XML 
Php :: In PackageManifest.php line 131: Undefined index: name 
Php :: IgasterLaravel ThemeExceptions heme Already Exists 
Php :: laravel How do I chain multiple where and orWhere clause in laravel from an Array [duplicate] 
Php :: php auto reset score 
Php :: woocommerce status change date 
Php :: snippet php symfony route 
Php :: laravel 7 link to another page with language prefix 
Php :: wordpress custom post type url not working 
Php :: Unable to open sqlite DB file from js axios.get request 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =