Magento 2 how to get get product ID in after plugin?
-
13-04-2021 - |
题
please help, I'm struggling with this.
I'm using this plugin
public function afterAddProduct($subject, $productInfo, $requestInfo = null)
I'm trying to get the product Id of the product in this way:
$productId = $subject->getId();
$productId = $productInfot->getId();
none of this works, i'm getting nothing, when I print with echo I get this:
Product ID:
I'm struggling a lot with this, I could get the product ID with beforeAddProduct in this way, but I must use afterAddProduct because is the only plugin that fits my solution.
Greetings!
解决方案
In afterAddProduct()
, you can get the product Id with $requestInfo
param. Below is the example code for getting product Id in afterAddProduct()
.
public function afterAddProduct($subject, $productInfo, $requestInfo = null)
{
$productId = $requestInfo->getEntityId();
}
Hope it helps!!!