Open brian-labelle opened 1 month ago
This issue appears to be fixed in this commit, but it's not part of the official Magento release yet: https://github.com/magento/magento2/commit/2f79a0695b8f1e02aad5f8e31ed7bdc9cd035533
It's part of 2.4.7-develop, but not 2.4.7-p1 or 2.4.7
@brian-labelle, if you don't have concerns, I'll wait for 2.4.7-p2 to be GA and close this issue.
This is more of an issue on the Adobe Commerce side, and it took a while to trace through, but I believe it's worth reporting here because this event is used in the starter kit, and will behave inconsistently
I noticed that when the observer event
catalog_product_save_commit_after
is dispatched from on Adobe Commerce admin panel, like saving the product, the event data is successfully added to theevent_data
table and can make its way to Adobe IO.However, when the observer event
catalog_product_save_commit_after
is dispatched as the result of a REST API action, such as aPUT
to/rest/default/V1/products/{sku}
, theevent_data
record is never createdThe reason is because an exception is getting thrown by
\Magento\AdobeCommerceEventsClient\Event\Converter\EventDataConverter
, which attempts to convert an event payload into JSON to add to theevent_data
table, which will then be picked up by the cron and sent to Adobe IOThe following exception occurs:
Failed to save event data. Event code: "catalog_product_save_commit_after", Error: "Call to a member function toArray() on array"
For some reason, this doesn't happen when the item is saved in the admin panel. Something about the observer event payload must be different when called via the admin panel save vs the REST API call which triggers the ProductRepository save
The result is that we cannot get product update events triggered by REST API calls, but we can get them when the product is updated in the admin panel
Investigation
\Magento\AdobeCommerceEventsClient\Event\Converter\EventDataConverter::convertArray
calls the following method:\Magento\Catalog\Model\Product::toArray
\Magento\Catalog\Model\Product::toArray
has the following code:The problem is,
$data['stock_item'] = $stock->toArray();
failed because, at least in this context,$stock
is actually already an array, so it cannot calltoArray
on it. Perhaps in the conversion process it was already converted? Perhaps when called from the REST API context,stock_item
behaves differently?Strangely, when saving this exact same product from the admin panel -- both from the All Stores context as well as a specific store-view context --
$stock = $this->getStockItem();
returnsnull
, so the error does not occurI have been able to reproduce this behavior on
2.4.7-p1
as well as2.4.6-p3