From f244e62dcaad08acdee320e3ae3cbb42ce415f9b Mon Sep 17 00:00:00 2001 From: Jasper Zeinstra Date: Tue, 20 Nov 2018 13:00:32 +0100 Subject: [PATCH] Add child identities to product indenties instead of parent identities --- app/code/Magento/Bundle/Model/Plugin/Product.php | 11 ++++++++--- .../Model/Plugin/ProductIdentitiesExtender.php | 9 +++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Bundle/Model/Plugin/Product.php b/app/code/Magento/Bundle/Model/Plugin/Product.php index b0f8d1af32fc2..4a7303641cb0d 100644 --- a/app/code/Magento/Bundle/Model/Plugin/Product.php +++ b/app/code/Magento/Bundle/Model/Plugin/Product.php @@ -24,6 +24,8 @@ public function __construct(Type $type) } /** + * Add child identities to product identities + * * @param CatalogProduct $product * @param array $identities * @return string[] @@ -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); } } diff --git a/app/code/Magento/ConfigurableProduct/Model/Plugin/ProductIdentitiesExtender.php b/app/code/Magento/ConfigurableProduct/Model/Plugin/ProductIdentitiesExtender.php index 68c574194817c..52f7bffdf536b 100644 --- a/app/code/Magento/ConfigurableProduct/Model/Plugin/ProductIdentitiesExtender.php +++ b/app/code/Magento/ConfigurableProduct/Model/Plugin/ProductIdentitiesExtender.php @@ -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 @@ -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);