Skip to content

Commit

Permalink
MAGETWO-8709: [GITHUB] Child product image should be shown in Wishist…
Browse files Browse the repository at this point in the history
… if options are selected for configurable product #8168

- fix section
  • Loading branch information
cpartica committed Jul 5, 2018
1 parent 24448d0 commit c20f7d5
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions app/code/Magento/Wishlist/CustomerData/Wishlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

use Magento\Catalog\Model\Product\Image\NotLoadInfoImageException;
use Magento\Customer\CustomerData\SectionSourceInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Image;

/**
* Wishlist section
Expand Down Expand Up @@ -38,22 +40,30 @@ class Wishlist implements SectionSourceInterface
*/
protected $block;

/**
* @var \Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Image
*/
private $image;

/**
* @param \Magento\Wishlist\Helper\Data $wishlistHelper
* @param \Magento\Wishlist\Block\Customer\Sidebar $block
* @param \Magento\Catalog\Helper\ImageFactory $imageHelperFactory
* @param \Magento\Framework\App\ViewInterface $view
* @param Image|null $image
*/
public function __construct(
\Magento\Wishlist\Helper\Data $wishlistHelper,
\Magento\Wishlist\Block\Customer\Sidebar $block,
\Magento\Catalog\Helper\ImageFactory $imageHelperFactory,
\Magento\Framework\App\ViewInterface $view
\Magento\Framework\App\ViewInterface $view,
Image $image = null
) {
$this->wishlistHelper = $wishlistHelper;
$this->imageHelperFactory = $imageHelperFactory;
$this->block = $block;
$this->view = $view;
$this->image = $image ?? ObjectManager::getInstance()->get(Image::class);
}

/**
Expand Down Expand Up @@ -122,7 +132,7 @@ protected function getItemData(\Magento\Wishlist\Model\Item $wishlistItem)
{
$product = $wishlistItem->getProduct();
return [
'image' => $this->getImageData($product),
'image' => $this->getImageData($this->image->getProductForThumbnail($wishlistItem)),
'product_sku' => $product->getSku(),
'product_id' => $product->getId(),
'product_url' => $this->wishlistHelper->getProductUrl($wishlistItem),
Expand All @@ -149,14 +159,6 @@ protected function getItemData(\Magento\Wishlist\Model\Item $wishlistItem)
*/
protected function getImageData($product)
{
/*Set variant product if it is configurable product.
It will show variant product image in sidebar instead of configurable product image.*/
$simpleOption = $product->getCustomOption('simple_product');
if ($simpleOption !== null) {
$optionProduct = $simpleOption->getProduct();
$product = $optionProduct;
}

/** @var \Magento\Catalog\Helper\Image $helper */
$helper = $this->imageHelperFactory->create()
->init($product, 'wishlist_sidebar_block');
Expand Down

0 comments on commit c20f7d5

Please sign in to comment.