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

- relying on item from cart as it has a setting in the admin that wishlist should have it too
  • Loading branch information
cpartica committed Jul 2, 2018
1 parent f947cad commit 24448d0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,67 @@
*/
namespace Magento\Wishlist\Block\Customer\Wishlist\Item\Column;

use Magento\Catalog\Model\Product\Image\UrlBuilder;
use Magento\Framework\View\ConfigInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Quote\Model\Quote\ItemFactory;
use Magento\Checkout\Block\Cart\Item\Renderer;

/**
* @api
* @since 100.0.2
*/
class Image extends \Magento\Wishlist\Block\Customer\Wishlist\Item\Column
{
/** @var \Magento\Checkout\Block\Cart\Item\Renderer[] */
private $renderers = [];

/** @var \Magento\Quote\Model\Quote\ItemFactory */
private $itemFactory;

/**
* @param \Magento\Catalog\Block\Product\Context $context
* @param \Magento\Framework\App\Http\Context $httpContext
* @param array $data
* @param ConfigInterface|null $config
* @param UrlBuilder|null $urlBuilder
* @param Renderer[] $renderers
* @param ItemFactory|null $itemFactory
*/
public function __construct(
\Magento\Catalog\Block\Product\Context $context,
\Magento\Framework\App\Http\Context $httpContext,
array $data = [],
ConfigInterface $config = null,
UrlBuilder $urlBuilder = null,
array $renderers = [],
ItemFactory $itemFactory = null
) {
$this->renderers = $renderers;
$this->itemFactory = $itemFactory ?? ObjectManager::getInstance()->get(ItemFactory::class);
parent::__construct(
$context,
$httpContext,
$data,
$config,
$urlBuilder
);
}

/**
* Identify the product from which thumbnail should be taken.
*
* @return \Magento\Catalog\Model\Product
*/
public function getProductForThumbnail(\Magento\Wishlist\Model\Item $item)
{
$product = $product = $item->getProduct();
if (isset($this->renderers[$product->getTypeId()])) {
$quoteItem = $this->itemFactory->create(['data' => $item->getData()]);
$quoteItem->setProduct($product);
$quoteItem->setOptions($item->getOptions());
return $this->renderers[$product->getTypeId()]->setItem($quoteItem)->getProductForThumbnail();
}
return $product;
}
}
8 changes: 8 additions & 0 deletions app/code/Magento/Wishlist/etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,12 @@
</argument>
</arguments>
</type>
<type name="Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Image">
<arguments>
<argument name="renderers" xsi:type="array">
<item name="configurable" xsi:type="object">Magento\ConfigurableProduct\Block\Cart\Item\Renderer\Configurable</item>
<item name="grouped" xsi:type="object">Magento\GroupedProduct\Block\Cart\Item\Renderer\Grouped</item>
</argument>
</arguments>
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ $item = $block->getItem();
$product = $item->getProduct();
?>
<a class="product-item-photo" tabindex="-1" href="<?= $block->escapeUrl($block->getProductUrl($item)) ?>" title="<?= $block->escapeHtmlAttr($product->getName()) ?>">
<?= $block->getImage($product, 'wishlist_thumbnail')->toHtml() ?>
<?= $block->getImage($block->getProductForThumbnail($item), 'wishlist_thumbnail')->toHtml() ?>
</a>

0 comments on commit 24448d0

Please sign in to comment.