Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to know who added product in magento

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 :: Get All dates of a month 
Php :: assign random to a variable in PHP 
Php :: php pass a function as a parameter 
Php :: isset php 
Php :: date comparison function in php 
Php :: magento Fatal error: Allowed memory size of 134217728 bytes exhausted 
Php :: send gmail 
Php :: laravel call a static function 
Php :: what is the use of closure function in php 
Php :: mail laravel 
Php :: email verification laravel 
Php :: php curl get body response 
Php :: create services in laravel with command line 
Php :: Convert an Integer Into a String in PHP 
Php :: php pre 
Php :: php variable constant 
Php :: error handling in laravel 
Php :: laravel available router methods 
Php :: laravel request query logger 
Php :: generate shortcode wordpress plugin 
Php :: create orphan token in vault 
Php :: findOneBy 
Php :: Remove the additional notes area from the WooCommerce checkout 
Php :: laravel count the types of users 
Php :: laravel nova create resource 
Php :: Woofood Availability checker 
Php :: Display random custom content in WooCommerce shop archive loop 
Php :: command working in terminal but working from code php 
Php :: acf advanced link 
Php :: laravel has many deep 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =