Skip to content

Commit c20f7d5

Browse files
committed
MAGETWO-8709: [GITHUB] Child product image should be shown in Wishist if options are selected for configurable product #8168
- fix section
1 parent 24448d0 commit c20f7d5

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

app/code/Magento/Wishlist/CustomerData/Wishlist.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Magento\Catalog\Model\Product\Image\NotLoadInfoImageException;
99
use Magento\Customer\CustomerData\SectionSourceInterface;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Image;
1012

1113
/**
1214
* Wishlist section
@@ -38,22 +40,30 @@ class Wishlist implements SectionSourceInterface
3840
*/
3941
protected $block;
4042

43+
/**
44+
* @var \Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Image
45+
*/
46+
private $image;
47+
4148
/**
4249
* @param \Magento\Wishlist\Helper\Data $wishlistHelper
4350
* @param \Magento\Wishlist\Block\Customer\Sidebar $block
4451
* @param \Magento\Catalog\Helper\ImageFactory $imageHelperFactory
4552
* @param \Magento\Framework\App\ViewInterface $view
53+
* @param Image|null $image
4654
*/
4755
public function __construct(
4856
\Magento\Wishlist\Helper\Data $wishlistHelper,
4957
\Magento\Wishlist\Block\Customer\Sidebar $block,
5058
\Magento\Catalog\Helper\ImageFactory $imageHelperFactory,
51-
\Magento\Framework\App\ViewInterface $view
59+
\Magento\Framework\App\ViewInterface $view,
60+
Image $image = null
5261
) {
5362
$this->wishlistHelper = $wishlistHelper;
5463
$this->imageHelperFactory = $imageHelperFactory;
5564
$this->block = $block;
5665
$this->view = $view;
66+
$this->image = $image ?? ObjectManager::getInstance()->get(Image::class);
5767
}
5868

5969
/**
@@ -122,7 +132,7 @@ protected function getItemData(\Magento\Wishlist\Model\Item $wishlistItem)
122132
{
123133
$product = $wishlistItem->getProduct();
124134
return [
125-
'image' => $this->getImageData($product),
135+
'image' => $this->getImageData($this->image->getProductForThumbnail($wishlistItem)),
126136
'product_sku' => $product->getSku(),
127137
'product_id' => $product->getId(),
128138
'product_url' => $this->wishlistHelper->getProductUrl($wishlistItem),
@@ -149,14 +159,6 @@ protected function getItemData(\Magento\Wishlist\Model\Item $wishlistItem)
149159
*/
150160
protected function getImageData($product)
151161
{
152-
/*Set variant product if it is configurable product.
153-
It will show variant product image in sidebar instead of configurable product image.*/
154-
$simpleOption = $product->getCustomOption('simple_product');
155-
if ($simpleOption !== null) {
156-
$optionProduct = $simpleOption->getProduct();
157-
$product = $optionProduct;
158-
}
159-
160162
/** @var \Magento\Catalog\Helper\Image $helper */
161163
$helper = $this->imageHelperFactory->create()
162164
->init($product, 'wishlist_sidebar_block');

0 commit comments

Comments
 (0)