From 24448d01e8afbf9cc698b32fad1c4c6a1446527a Mon Sep 17 00:00:00 2001 From: Cristian Partica Date: Mon, 2 Jul 2018 10:15:35 -0500 Subject: [PATCH] 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 --- .../Customer/Wishlist/Item/Column/Image.php | 57 +++++++++++++++++++ app/code/Magento/Wishlist/etc/frontend/di.xml | 8 +++ .../templates/item/column/image.phtml | 2 +- 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Wishlist/Block/Customer/Wishlist/Item/Column/Image.php b/app/code/Magento/Wishlist/Block/Customer/Wishlist/Item/Column/Image.php index 02a897d44b3c6..f76543527e0fd 100644 --- a/app/code/Magento/Wishlist/Block/Customer/Wishlist/Item/Column/Image.php +++ b/app/code/Magento/Wishlist/Block/Customer/Wishlist/Item/Column/Image.php @@ -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; + } } diff --git a/app/code/Magento/Wishlist/etc/frontend/di.xml b/app/code/Magento/Wishlist/etc/frontend/di.xml index 00642b132bfdf..802f3612f2c9b 100644 --- a/app/code/Magento/Wishlist/etc/frontend/di.xml +++ b/app/code/Magento/Wishlist/etc/frontend/di.xml @@ -47,4 +47,12 @@ + + + + Magento\ConfigurableProduct\Block\Cart\Item\Renderer\Configurable + Magento\GroupedProduct\Block\Cart\Item\Renderer\Grouped + + + diff --git a/app/code/Magento/Wishlist/view/frontend/templates/item/column/image.phtml b/app/code/Magento/Wishlist/view/frontend/templates/item/column/image.phtml index 1008f5f377df5..2eb4664991e99 100644 --- a/app/code/Magento/Wishlist/view/frontend/templates/item/column/image.phtml +++ b/app/code/Magento/Wishlist/view/frontend/templates/item/column/image.phtml @@ -13,5 +13,5 @@ $item = $block->getItem(); $product = $item->getProduct(); ?> - getImage($product, 'wishlist_thumbnail')->toHtml() ?> + getImage($block->getProductForThumbnail($item), 'wishlist_thumbnail')->toHtml() ?>