Skip to content
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

Add child identities to products instead of parent identities #19281

Closed
Show file tree
Hide file tree
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
11 changes: 8 additions & 3 deletions app/code/Magento/Bundle/Model/Plugin/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function __construct(Type $type)
}

/**
* Add child identities to product identities
*
* @param CatalogProduct $product
* @param array $identities
* @return string[]
Expand All @@ -32,9 +34,12 @@ public function afterGetIdentities(
CatalogProduct $product,
array $identities
) {
foreach ($this->type->getParentIdsByChild($product->getEntityId()) as $parentId) {
$identities[] = CatalogProduct::CACHE_TAG . '_' . $parentId;
foreach ($this->type->getChildrenIds($product->getEntityId()) as $optionId => $childIds) {
foreach ($childIds as $childId) {
$identities[] = CatalogProduct::CACHE_TAG . '_' . $childId;
}
}
return $identities;

return array_unique($identities);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(Configurable $configurableType, ProductRepositoryInt
}

/**
* Add parent identities to product identities
* Add child identities to product identities
*
* @param Product $subject
* @param array $identities
Expand All @@ -48,9 +48,10 @@ public function afterGetIdentities(Product $subject, array $identities): array
{
$identities = (array) $identities;

foreach ($this->configurableType->getParentIdsByChild($subject->getId()) as $parentId) {
$parentProduct = $this->productRepository->getById($parentId);
$identities = array_merge($identities, (array) $parentProduct->getIdentities());
foreach ($this->configurableType->getChildrenIds($subject->getId()) as $key => $childIds) {
foreach ($childIds as $childId) {
$identities[] = Product::CACHE_TAG . '_' . $childId;
}
}

return array_unique($identities);
Expand Down