Magento 2 : How to know who admin_user added a product?Magento 2 import bulk products with custom attributeIs it possible to save attribute value per store in custom eav based model?Magento 2 - Best practice for extending customer entityForeignkey integrity error while configurable product import magento 2Foreign key constraint fails Entity_Type_IDHow to add a foreign key with onUpdate Cascade in an M2 installer script?Magento2.2 How to get userContext into ScopeConfigHow to add new field to Admin User Info in Magento 2?Set programmatically added attributes to productMagento 2 : Foreing key constraint issueShould MagentoEavModelAttributeRepository save 'used_in_forms' attribute value?

A Paper Record is What I Hamper

What is meant by "Prämie" in this letter? Do I have to pay it or it is just a reminder?

What was Apollo 13's "Little Jolt" after MECO?

How come there are so many candidates for the 2020 Democratic party presidential nomination?

Who is the character that appears at the end of Endgame?

Magical attacks and overcoming damage resistance

Covering null sets by a finite number of intervals

Mistake in years of experience in resume?

How to fry ground beef so it is well-browned

Why did C use the -> operator instead of reusing the . operator?

What is the most expensive material in the world that could be used to create Pun-Pun's lute?

Was Dennis Ritchie being too modest in this quote about C and Pascal?

How does Captain America channel this power?

Who was the lone kid in the line of people at the lake at the end of Avengers: Endgame?

How to have a sharp product image?

Farming on the moon

Why do games have consumables?

Was there a Viking Exchange as well as a Columbian one?

All ASCII characters with a given bit count

Pulling the rope with one hand is as heavy as with two hands?

Why do distances seem to matter in the Foundation world?

What happens to the Infinity Stones?

Check if a string is entirely made of the same substring

Can I criticise the more senior developers around me for not writing clean code?



Magento 2 : How to know who admin_user added a product?


Magento 2 import bulk products with custom attributeIs it possible to save attribute value per store in custom eav based model?Magento 2 - Best practice for extending customer entityForeignkey integrity error while configurable product import magento 2Foreign key constraint fails Entity_Type_IDHow to add a foreign key with onUpdate Cascade in an M2 installer script?Magento2.2 How to get userContext into ScopeConfigHow to add new field to Admin User Info in Magento 2?Set programmatically added attributes to productMagento 2 : Foreing key constraint issueShould MagentoEavModelAttributeRepository save 'used_in_forms' attribute value?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I created a new admin_user role, this role has access to the products page and can add a new product.



So, I want to save the ID of the current admin_user to know who's added the product.



The first method I think about is to add a new foreign key to catalog_product_website table on DB with the ID of admin_user table.



And after that, I will use an event to save the ID on this table, on save the product.



But with some search, I found there's EAV method.



So, it's better to use the first method? Or it's better to use EAV and create attribute not visibly and save on it the ID of the current user?










share|improve this question






















  • EAV should not be used here. please read the docs on what EAV does/when it's used

    – Philipp Sander
    1 hour ago











  • Possible duplicate of Magento 2 import bulk products with custom attribute

    – ABHISHEK TRIPATHI
    58 mins ago

















0















I created a new admin_user role, this role has access to the products page and can add a new product.



So, I want to save the ID of the current admin_user to know who's added the product.



The first method I think about is to add a new foreign key to catalog_product_website table on DB with the ID of admin_user table.



And after that, I will use an event to save the ID on this table, on save the product.



But with some search, I found there's EAV method.



So, it's better to use the first method? Or it's better to use EAV and create attribute not visibly and save on it the ID of the current user?










share|improve this question






















  • EAV should not be used here. please read the docs on what EAV does/when it's used

    – Philipp Sander
    1 hour ago











  • Possible duplicate of Magento 2 import bulk products with custom attribute

    – ABHISHEK TRIPATHI
    58 mins ago













0












0








0








I created a new admin_user role, this role has access to the products page and can add a new product.



So, I want to save the ID of the current admin_user to know who's added the product.



The first method I think about is to add a new foreign key to catalog_product_website table on DB with the ID of admin_user table.



And after that, I will use an event to save the ID on this table, on save the product.



But with some search, I found there's EAV method.



So, it's better to use the first method? Or it's better to use EAV and create attribute not visibly and save on it the ID of the current user?










share|improve this question














I created a new admin_user role, this role has access to the products page and can add a new product.



So, I want to save the ID of the current admin_user to know who's added the product.



The first method I think about is to add a new foreign key to catalog_product_website table on DB with the ID of admin_user table.



And after that, I will use an event to save the ID on this table, on save the product.



But with some search, I found there's EAV method.



So, it's better to use the first method? Or it's better to use EAV and create attribute not visibly and save on it the ID of the current user?







magento2 eav






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









sayousayou

1378




1378












  • EAV should not be used here. please read the docs on what EAV does/when it's used

    – Philipp Sander
    1 hour ago











  • Possible duplicate of Magento 2 import bulk products with custom attribute

    – ABHISHEK TRIPATHI
    58 mins ago

















  • EAV should not be used here. please read the docs on what EAV does/when it's used

    – Philipp Sander
    1 hour ago











  • Possible duplicate of Magento 2 import bulk products with custom attribute

    – ABHISHEK TRIPATHI
    58 mins ago
















EAV should not be used here. please read the docs on what EAV does/when it's used

– Philipp Sander
1 hour ago





EAV should not be used here. please read the docs on what EAV does/when it's used

– Philipp Sander
1 hour ago













Possible duplicate of Magento 2 import bulk products with custom attribute

– ABHISHEK TRIPATHI
58 mins ago





Possible duplicate of Magento 2 import bulk products with custom attribute

– ABHISHEK TRIPATHI
58 mins ago










1 Answer
1






active

oldest

votes


















0














You can achieve by creating a new product attribute. let say admin_user_id. now you need to feel this value on product saving from backend by using Magento events. If you are not familiar with Magento events and observer please read this from the Magento DevDocs.



In your case, you should use catalog_product_save_before event. this event is executing before saving the product. In this event, you will get a product object so you can use this object and set the current admin user Id(you can get it from current admin session). For example,



Create events.xml under etc/adminhtml/events.xml



 <event name="catalog_product_save_before">
<observer name="assign_admin_user_id_on_save" instance="ExampleSampleObserverAssignAdminIdOnSave"/>
</event>


Now you need to create an observer class which should implement MagentoFrameworkEventObserverInterface



<?php

namespace ExampleSampleObserver;

use MagentoFrameworkEventObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoBackendModelAuthSession as adminSession;

class AssignAdminIdOnSave implements ObserverInterface

/**
* @var adminSession
*/
private $adminSession;

/**
* AssignAdminIdOnSave constructor.
* @param adminSession $adminSession
*/
public function __construct(
adminSession $adminSession
)

$this->adminSession = $adminSession;


public function execute(Observer $observer)

$product = $observer->getProduct();
$adminId=$this->adminSession->getUser()->getId();
$product->setAdminUserId($adminId) ;




Please note that this will work only when you are creating/saving the product from the backend.



If you also want admin user Id on product import then you need to create another observer for catalog_product_save_before. I already wrote the answer for this so you can check from this link






share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f272584%2fmagento-2-how-to-know-who-admin-user-added-a-product%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You can achieve by creating a new product attribute. let say admin_user_id. now you need to feel this value on product saving from backend by using Magento events. If you are not familiar with Magento events and observer please read this from the Magento DevDocs.



    In your case, you should use catalog_product_save_before event. this event is executing before saving the product. In this event, you will get a product object so you can use this object and set the current admin user Id(you can get it from current admin session). For example,



    Create events.xml under etc/adminhtml/events.xml



     <event name="catalog_product_save_before">
    <observer name="assign_admin_user_id_on_save" instance="ExampleSampleObserverAssignAdminIdOnSave"/>
    </event>


    Now you need to create an observer class which should implement MagentoFrameworkEventObserverInterface



    <?php

    namespace ExampleSampleObserver;

    use MagentoFrameworkEventObserver;
    use MagentoFrameworkEventObserverInterface;
    use MagentoBackendModelAuthSession as adminSession;

    class AssignAdminIdOnSave implements ObserverInterface

    /**
    * @var adminSession
    */
    private $adminSession;

    /**
    * AssignAdminIdOnSave constructor.
    * @param adminSession $adminSession
    */
    public function __construct(
    adminSession $adminSession
    )

    $this->adminSession = $adminSession;


    public function execute(Observer $observer)

    $product = $observer->getProduct();
    $adminId=$this->adminSession->getUser()->getId();
    $product->setAdminUserId($adminId) ;




    Please note that this will work only when you are creating/saving the product from the backend.



    If you also want admin user Id on product import then you need to create another observer for catalog_product_save_before. I already wrote the answer for this so you can check from this link






    share|improve this answer



























      0














      You can achieve by creating a new product attribute. let say admin_user_id. now you need to feel this value on product saving from backend by using Magento events. If you are not familiar with Magento events and observer please read this from the Magento DevDocs.



      In your case, you should use catalog_product_save_before event. this event is executing before saving the product. In this event, you will get a product object so you can use this object and set the current admin user Id(you can get it from current admin session). For example,



      Create events.xml under etc/adminhtml/events.xml



       <event name="catalog_product_save_before">
      <observer name="assign_admin_user_id_on_save" instance="ExampleSampleObserverAssignAdminIdOnSave"/>
      </event>


      Now you need to create an observer class which should implement MagentoFrameworkEventObserverInterface



      <?php

      namespace ExampleSampleObserver;

      use MagentoFrameworkEventObserver;
      use MagentoFrameworkEventObserverInterface;
      use MagentoBackendModelAuthSession as adminSession;

      class AssignAdminIdOnSave implements ObserverInterface

      /**
      * @var adminSession
      */
      private $adminSession;

      /**
      * AssignAdminIdOnSave constructor.
      * @param adminSession $adminSession
      */
      public function __construct(
      adminSession $adminSession
      )

      $this->adminSession = $adminSession;


      public function execute(Observer $observer)

      $product = $observer->getProduct();
      $adminId=$this->adminSession->getUser()->getId();
      $product->setAdminUserId($adminId) ;




      Please note that this will work only when you are creating/saving the product from the backend.



      If you also want admin user Id on product import then you need to create another observer for catalog_product_save_before. I already wrote the answer for this so you can check from this link






      share|improve this answer

























        0












        0








        0







        You can achieve by creating a new product attribute. let say admin_user_id. now you need to feel this value on product saving from backend by using Magento events. If you are not familiar with Magento events and observer please read this from the Magento DevDocs.



        In your case, you should use catalog_product_save_before event. this event is executing before saving the product. In this event, you will get a product object so you can use this object and set the current admin user Id(you can get it from current admin session). For example,



        Create events.xml under etc/adminhtml/events.xml



         <event name="catalog_product_save_before">
        <observer name="assign_admin_user_id_on_save" instance="ExampleSampleObserverAssignAdminIdOnSave"/>
        </event>


        Now you need to create an observer class which should implement MagentoFrameworkEventObserverInterface



        <?php

        namespace ExampleSampleObserver;

        use MagentoFrameworkEventObserver;
        use MagentoFrameworkEventObserverInterface;
        use MagentoBackendModelAuthSession as adminSession;

        class AssignAdminIdOnSave implements ObserverInterface

        /**
        * @var adminSession
        */
        private $adminSession;

        /**
        * AssignAdminIdOnSave constructor.
        * @param adminSession $adminSession
        */
        public function __construct(
        adminSession $adminSession
        )

        $this->adminSession = $adminSession;


        public function execute(Observer $observer)

        $product = $observer->getProduct();
        $adminId=$this->adminSession->getUser()->getId();
        $product->setAdminUserId($adminId) ;




        Please note that this will work only when you are creating/saving the product from the backend.



        If you also want admin user Id on product import then you need to create another observer for catalog_product_save_before. I already wrote the answer for this so you can check from this link






        share|improve this answer













        You can achieve by creating a new product attribute. let say admin_user_id. now you need to feel this value on product saving from backend by using Magento events. If you are not familiar with Magento events and observer please read this from the Magento DevDocs.



        In your case, you should use catalog_product_save_before event. this event is executing before saving the product. In this event, you will get a product object so you can use this object and set the current admin user Id(you can get it from current admin session). For example,



        Create events.xml under etc/adminhtml/events.xml



         <event name="catalog_product_save_before">
        <observer name="assign_admin_user_id_on_save" instance="ExampleSampleObserverAssignAdminIdOnSave"/>
        </event>


        Now you need to create an observer class which should implement MagentoFrameworkEventObserverInterface



        <?php

        namespace ExampleSampleObserver;

        use MagentoFrameworkEventObserver;
        use MagentoFrameworkEventObserverInterface;
        use MagentoBackendModelAuthSession as adminSession;

        class AssignAdminIdOnSave implements ObserverInterface

        /**
        * @var adminSession
        */
        private $adminSession;

        /**
        * AssignAdminIdOnSave constructor.
        * @param adminSession $adminSession
        */
        public function __construct(
        adminSession $adminSession
        )

        $this->adminSession = $adminSession;


        public function execute(Observer $observer)

        $product = $observer->getProduct();
        $adminId=$this->adminSession->getUser()->getId();
        $product->setAdminUserId($adminId) ;




        Please note that this will work only when you are creating/saving the product from the backend.



        If you also want admin user Id on product import then you need to create another observer for catalog_product_save_before. I already wrote the answer for this so you can check from this link







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 1 hour ago









        Keyur ShahKeyur Shah

        13.6k24165




        13.6k24165



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f272584%2fmagento-2-how-to-know-who-admin-user-added-a-product%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            کانن (شرکت) محتویات تاریخچه[ویرایش] بخشی از تولیدات موفق این شرکت[ویرایش] در رده APS-C[ویرایش] گزارش محیط زیست[ویرایش] رده‌بندی محصولات[ویرایش] منابع[ویرایش] پانویس[ویرایش] پیوند به بیرون[ویرایش] منوی ناوبریwww.canon.comموزه آنلاین دوربین‌های کانننمودار تاریخچه سهام کاننوبگاه رسمی شرکت کاننوووووIDC Worldwide Hardcopy 2013

            Rest API with Magento using PHP with example. Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?How to update product using magento client library for PHP?Oauth Error while extending Magento Rest APINot showing my custom api in wsdl(url) and web service list?Using Magento API(REST) via IXMLHTTPRequest COM ObjectHow to login in Magento website using REST APIREST api call for Guest userMagento API calling using HTML and javascriptUse API rest media management by storeView code (admin)Magento REST API Example ErrorsHow to log all rest api calls in magento2?How to update product using magento client library for PHP?

            Magento 2 - Auto login with specific URL Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Customer can't login - Page refreshes but nothing happensCustom Login page redirectURL to login with redirect URL after completionCustomer login is case sensitiveLogin with phone number or email address - Magento 1.9Magento 2: Set Customer Account Confirmation StatusCustomer auto connect from URLHow to call customer login form in the custom module action magento 2?Change of customer login error message magento2Referrer URL in modal login form