|
11 | 11 | */
|
12 | 12 | namespace Magento\Wishlist\Block\Customer\Wishlist\Item\Column;
|
13 | 13 |
|
| 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 | + |
14 | 20 | /**
|
15 | 21 | * @api
|
16 | 22 | * @since 100.0.2
|
17 | 23 | */
|
18 | 24 | class Image extends \Magento\Wishlist\Block\Customer\Wishlist\Item\Column
|
19 | 25 | {
|
| 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 | + } |
20 | 77 | }
|
0 commit comments