-
Notifications
You must be signed in to change notification settings - Fork 254
Open
Labels
Issue: ready for confirmationTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject itIssue related to Developer Experience and needs help with Triage to Confirm or Reject it
Description
You are setting and deleting the cache at the same time
$this->stockItemDataCacheStorage->set(Stock::DEFAULT_STOCK_ID, $product->getSku(), $stockCache);
$this->stockItemDataCacheStorage->delete(Stock::DEFAULT_STOCK_ID, $product->getSku());
public function execute(Observer $observer)
{
/** @var Collection $productCollection */
$productCollection = $observer->getData('collection');
/** @var Product $product */
foreach ($productCollection->getItems() as $product) {
$this->productTypesBySkusStorage->set((string) $product->getSku(), (string) $product->getTypeId());
$this->productIdsBySkusStorage->set((string) $product->getSku(), (int) $product->getId());
$this->productSkusByIdsStorage->set((int) $product->getId(), (string) $product->getSku());
$stockData = $this->stockRegistry->getStockItemBySku($product->getSku());
$stockCache = ['quantity' => $stockData->getQty(), 'is_salable' => $stockData->getIsInStock()];
$this->stockItemDataCacheStorage->set(Stock::DEFAULT_STOCK_ID, $product->getSku(), $stockCache);
$this->stockItemDataCacheStorage->delete(Stock::DEFAULT_STOCK_ID, $product->getSku());
$this->cacheStorage->delete(Stock::DEFAULT_STOCK_ID, $product->getSku());
}
$productIds = array_keys($productCollection->getItems());
if ($productIds) {
$this->legacyStockStatusCache->execute($productIds);
}
}
For full code: https://github.com/magento/inventory/blob/develop/InventoryCatalog/Observer/PreloadCache.php#L105-L106
Metadata
Metadata
Assignees
Labels
Issue: ready for confirmationTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject itIssue related to Developer Experience and needs help with Triage to Confirm or Reject it