Skip to content

fix: parent product cache not clearing #37528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 2.4-develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private function getProductStockStatuses(array $productIds)

$statuses = [];
foreach ($this->getConnection()->fetchAll($select) as $item) {
$statuses[$item['product_id']] = $item;
$statuses[$item['product_id'].($item['parent_id']? '-'.$item['parent_id']: '')] = $item;
}
return $statuses;
}
Expand All @@ -142,27 +142,29 @@ private function getProductStockStatuses(array $productIds)
*/
private function getProductIdsForCacheClean(array $productStatusesBefore, array $productStatusesAfter)
{
$disabledProductsIds = array_diff(array_keys($productStatusesBefore), array_keys($productStatusesAfter));
$enabledProductsIds = array_diff(array_keys($productStatusesAfter), array_keys($productStatusesBefore));
$commonProductsIds = array_intersect(array_keys($productStatusesBefore), array_keys($productStatusesAfter));
$beforeProductIds = array_unique(array_column($productStatusesBefore, 'product_id'));
$afterProductIds = array_unique(array_column($productStatusesAfter, 'product_id'));
$disabledProductsIds = array_diff($beforeProductIds, $afterProductIds);
$enabledProductsIds = array_diff($afterProductIds, $beforeProductIds);
$commonRelations = array_intersect(array_keys($productStatusesBefore), array_keys($productStatusesAfter));
$productIds = array_merge($disabledProductsIds, $enabledProductsIds);

$stockThresholdQty = $this->stockConfiguration->getStockThresholdQty();

foreach ($commonProductsIds as $productId) {
$statusBefore = $productStatusesBefore[$productId];
$statusAfter = $productStatusesAfter[$productId];
foreach ($commonRelations as $commonRelationId) {
$statusBefore = $productStatusesBefore[$commonRelationId];
$statusAfter = $productStatusesAfter[$commonRelationId];

if ($statusBefore['stock_status'] !== $statusAfter['stock_status']
|| ($stockThresholdQty && $statusAfter['qty'] <= $stockThresholdQty)) {
$productIds[] = $productId;
$productIds[] = $statusAfter['product_id'];
if (isset($statusAfter['parent_id'])) {
$productIds[] = $statusAfter['parent_id'];
}
}
}

return array_map('intval', $productIds);
return array_unique($productIds);
}

/**
Expand Down