Question

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!

Was it helpful?

Solution

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!!!

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top