Horje
magento check which user has added a product Code Example
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="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);
    }
}




Php

Related
Carbon\Traits\Units.php:69 Code Example Carbon\Traits\Units.php:69 Code Example
wordpress remove current post in sidebar php Code Example wordpress remove current post in sidebar php Code Example
login with email or username codeigniter 4 Code Example login with email or username codeigniter 4 Code Example
php include file from another folder Code Example php include file from another folder Code Example
add javascript to wordpress functions php Code Example add javascript to wordpress functions php Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10