Skip to content

Commit 24448d0

Browse files
committed
MAGETWO-8709: [GITHUB] Child product image should be shown in Wishist 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
1 parent f947cad commit 24448d0

File tree

3 files changed

+66
-1
lines changed
  • app/code/Magento/Wishlist

3 files changed

+66
-1
lines changed

app/code/Magento/Wishlist/Block/Customer/Wishlist/Item/Column/Image.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,67 @@
1111
*/
1212
namespace Magento\Wishlist\Block\Customer\Wishlist\Item\Column;
1313

14+
use Magento\Catalog\Model\Product\Image\UrlBuilder;
15+
use Magento\Framework\View\ConfigInterface;
16+
use Magento\Framework\App\ObjectManager;
17+
use Magento\Quote\Model\Quote\ItemFactory;
18+
use Magento\Checkout\Block\Cart\Item\Renderer;
19+
1420
/**
1521
* @api
1622
* @since 100.0.2
1723
*/
1824
class Image extends \Magento\Wishlist\Block\Customer\Wishlist\Item\Column
1925
{
26+
/** @var \Magento\Checkout\Block\Cart\Item\Renderer[] */
27+
private $renderers = [];
28+
29+
/** @var \Magento\Quote\Model\Quote\ItemFactory */
30+
private $itemFactory;
31+
32+
/**
33+
* @param \Magento\Catalog\Block\Product\Context $context
34+
* @param \Magento\Framework\App\Http\Context $httpContext
35+
* @param array $data
36+
* @param ConfigInterface|null $config
37+
* @param UrlBuilder|null $urlBuilder
38+
* @param Renderer[] $renderers
39+
* @param ItemFactory|null $itemFactory
40+
*/
41+
public function __construct(
42+
\Magento\Catalog\Block\Product\Context $context,
43+
\Magento\Framework\App\Http\Context $httpContext,
44+
array $data = [],
45+
ConfigInterface $config = null,
46+
UrlBuilder $urlBuilder = null,
47+
array $renderers = [],
48+
ItemFactory $itemFactory = null
49+
) {
50+
$this->renderers = $renderers;
51+
$this->itemFactory = $itemFactory ?? ObjectManager::getInstance()->get(ItemFactory::class);
52+
parent::__construct(
53+
$context,
54+
$httpContext,
55+
$data,
56+
$config,
57+
$urlBuilder
58+
);
59+
}
60+
61+
/**
62+
* Identify the product from which thumbnail should be taken.
63+
*
64+
* @return \Magento\Catalog\Model\Product
65+
*/
66+
public function getProductForThumbnail(\Magento\Wishlist\Model\Item $item)
67+
{
68+
$product = $product = $item->getProduct();
69+
if (isset($this->renderers[$product->getTypeId()])) {
70+
$quoteItem = $this->itemFactory->create(['data' => $item->getData()]);
71+
$quoteItem->setProduct($product);
72+
$quoteItem->setOptions($item->getOptions());
73+
return $this->renderers[$product->getTypeId()]->setItem($quoteItem)->getProductForThumbnail();
74+
}
75+
return $product;
76+
}
2077
}

app/code/Magento/Wishlist/etc/frontend/di.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,12 @@
4747
</argument>
4848
</arguments>
4949
</type>
50+
<type name="Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Image">
51+
<arguments>
52+
<argument name="renderers" xsi:type="array">
53+
<item name="configurable" xsi:type="object">Magento\ConfigurableProduct\Block\Cart\Item\Renderer\Configurable</item>
54+
<item name="grouped" xsi:type="object">Magento\GroupedProduct\Block\Cart\Item\Renderer\Grouped</item>
55+
</argument>
56+
</arguments>
57+
</type>
5058
</config>

app/code/Magento/Wishlist/view/frontend/templates/item/column/image.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ $item = $block->getItem();
1313
$product = $item->getProduct();
1414
?>
1515
<a class="product-item-photo" tabindex="-1" href="<?= $block->escapeUrl($block->getProductUrl($item)) ?>" title="<?= $block->escapeHtmlAttr($product->getName()) ?>">
16-
<?= $block->getImage($product, 'wishlist_thumbnail')->toHtml() ?>
16+
<?= $block->getImage($block->getProductForThumbnail($item), 'wishlist_thumbnail')->toHtml() ?>
1717
</a>

0 commit comments

Comments
 (0)