You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
\Magento\CatalogInventory\Observer\SaveInventoryDataObserver
should be united in a single "processing" point. It could be a SaveInventoryProcessor class, like in the example below.
PAY ATTENTION: this logic is needed ONLY for BI (saving stock item data on product save). In proper way, we need to save StockItem only via StockItemRepositoryInterface
Also, we now save via stockregistry only for BI.
/** * Dockblock like as "this logic is needed ONLY for BI (saving stock item data on product save). In propel way, we need to save StockItem only via StockItemRepository" */class SaveInventoryProcessor (NOTINTERFACE)
{
/** * Saving product inventory data * * @param Product $product * @return $this * @throws LocalizedException */publicfunctionexecute(Product$product)
{
$stockItem = $this->getStockItemToBeUpdated($product);
if (null !== $stockItem) {
$stockItem->setProductId($product->getId());
$stockItem->setWebsiteId($this->stockConfiguration->getDefaultScopeId());
$this->stockItemValidator->validate($product, $stockItem);
$this->stockRegistry->updateStockItemBySku($product->getSku(), $stockItem);
}
return$this;
}
/** * Return the stock item that needs to be updated * * @param ProductInterface $product * @return StockItemInterface|null */privatefunctiongetStockItemToBeUpdated($product)
{
$stockItem = null;
$extendedAttributes = $product->getExtensionAttributes();
if ($extendedAttributes !== null) {
$stockItem = $extendedAttributes->getStockItem();
}
if ($stockItem === null) {
$stockItem = $this->stockRegistry->getStockItem($product->getId());
}
return$stockItem;
}
}
The processing logic of saving data via model and via product repository must be the same!
2. Move validation logic from ProductRepositoryPlugin to a separate class.
[Arrows] MC-33288: [2.4][MSI][MFTF] StorefrontLoggedInCustomerCreateOrderAllOptionQuantityConfigurableProductCustomStockTest fails because of bad design
Full context in documentation
[HLD] Inconsistent saving of Stock Data
Description
1. Unite logic in a single processing point
The logic of the following classes:
should be united in a single "processing" point. It could be a SaveInventoryProcessor class, like in the example below.
PAY ATTENTION: this logic is needed ONLY for BI (saving stock item data on product save). In proper way, we need to save StockItem only via StockItemRepositoryInterface
Also, we now save via stockregistry only for BI.
The processing logic of saving data via model and via product repository must be the same!
2. Move validation logic from ProductRepositoryPlugin to a separate class.
For example:
Also need to investigate about moving this logic in StockItemRepository
The text was updated successfully, but these errors were encountered: