Skip to content

Commit dc056bf

Browse files
committed
MAGETWO-8709: [GITHUB] Child product image should be shown in Wishist if options are selected for configurable product #8168
- adding optimization
1 parent c1a3261 commit dc056bf

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

app/code/Magento/ConfigurableProduct/Model/Product/Configuration/Item/ItemProductResolver.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,19 @@ public function getFinalProduct(ItemInterface $item) : ProductInterface
4747
* or if child thumbnail is not available.
4848
*/
4949
$parentProduct = $item->getProduct();
50-
$configValue = $this->scopeConfig->getValue(
51-
self::CONFIG_THUMBNAIL_SOURCE,
52-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
53-
);
54-
50+
$finalProduct = $parentProduct;
5551
$childProduct = $this->getChildProduct($item);
56-
$childThumb = $childProduct->getData('thumbnail');
57-
$finalProduct =
58-
($configValue == Thumbnail::OPTION_USE_PARENT_IMAGE) || (!$childThumb || $childThumb == 'no_selection')
59-
? $parentProduct
60-
: $childProduct;
52+
if ($childProduct !== $parentProduct) {
53+
$configValue = $this->scopeConfig->getValue(
54+
self::CONFIG_THUMBNAIL_SOURCE,
55+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
56+
);
57+
$childThumb = $childProduct->getData('thumbnail');
58+
$finalProduct =
59+
($configValue == Thumbnail::OPTION_USE_PARENT_IMAGE) || (!$childThumb || $childThumb == 'no_selection')
60+
? $parentProduct
61+
: $childProduct;
62+
}
6163
return $finalProduct;
6264
}
6365

app/code/Magento/GroupedProduct/Model/Product/Configuration/Item/ItemProductResolver.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,22 @@ public function getFinalProduct(ItemInterface $item) : ProductInterface
4646
* Show grouped product thumbnail if it must be always shown according to the related setting in system config
4747
* or if child product thumbnail is not available.
4848
*/
49-
$configValue = $this->scopeConfig->getValue(
50-
self::CONFIG_THUMBNAIL_SOURCE,
51-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
52-
);
49+
5350
$childProduct = $item->getProduct();
54-
$childThumb = $childProduct->getData('thumbnail');
51+
$finalProduct = $childProduct;
52+
$parentProduct = $this->getParentProduct($item);
53+
if ($childProduct !== $parentProduct) {
54+
$configValue = $this->scopeConfig->getValue(
55+
self::CONFIG_THUMBNAIL_SOURCE,
56+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
57+
);
58+
$childThumb = $childProduct->getData('thumbnail');
5559

56-
$finalProduct =
57-
($configValue == Thumbnail::OPTION_USE_PARENT_IMAGE) || (!$childThumb || $childThumb == 'no_selection')
58-
? $this->getParentProduct($item)
59-
: $childProduct;
60+
$finalProduct =
61+
($configValue == Thumbnail::OPTION_USE_PARENT_IMAGE) || (!$childThumb || $childThumb == 'no_selection')
62+
? $parentProduct
63+
: $childProduct;
64+
}
6065
return $finalProduct;
6166
}
6267

0 commit comments

Comments
 (0)