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;
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
add a comment |
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
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
add a comment |
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
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
magento2 eav
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered 1 hour ago
Keyur ShahKeyur Shah
13.6k24165
13.6k24165
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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