I have created interceptor for catalog product controller’s save action
<type name="MagentoCatalogControllerAdminhtmlProductSave">
<plugin name="ricky_catalog_save_product"
type="RickyCatalogPluginProductSave" sortOrder="10"
/>
</type>
My plugin class is below
namespace RickyCatalogPluginProduct;
class Save {
public function afterExecute(
MagentoCatalogControllerAdminhtmlProductSave $subject,
$result)
{
$productId = $subject->productId; // This is not working
/** $productId is provided in excute method in Save class
in MagentoCatalogControllerAdminhtmlProductSave **/
}
}
For some reasons I have to use Plugin (Interceptor Design Pattern), I know I can get newly created prouduct id by using observer for catalog_product_save_after event. But please provide solution for plugins.
Thanks for help 🙂
2
Answers
If you are accessing the property $subject->productId, that means it should be defined in the class
There is no class variable defined with name productId.
You can override the controller and define one more public class variable
and assign product id somewhere in the execute() method:-
Now in your plugin use it as:-
Tested and working..!!
You can get the product Id in this way
Hope this helps !! Happy Coding