Skip to content

Commit c3b42db

Browse files
authored
ENGCOM-7062: #27124: Update wishlist image logic to match logic on wishlist page #27125
2 parents 9b5e747 + 3f4f646 commit c3b42db

File tree

2 files changed

+63
-16
lines changed

2 files changed

+63
-16
lines changed

app/code/Magento/Wishlist/Block/Share/Email/Items.php

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,73 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
/**
8-
* Wishlist block customer items
9-
*
10-
* @author Magento Core Team <[email protected]>
11-
*/
127
namespace Magento\Wishlist\Block\Share\Email;
138

9+
use Magento\Catalog\Model\Product;
10+
use Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface;
11+
use Magento\Catalog\Model\Product\Image\UrlBuilder;
12+
use Magento\Framework\App\ObjectManager;
13+
use Magento\Framework\View\ConfigInterface;
14+
use Magento\Wishlist\Model\Item;
15+
1416
/**
17+
* Wishlist share items
18+
*
1519
* @api
1620
* @since 100.0.2
1721
*/
1822
class Items extends \Magento\Wishlist\Block\AbstractBlock
1923
{
24+
/**
25+
* @var ItemResolverInterface
26+
*/
27+
private $itemResolver;
28+
2029
/**
2130
* @var string
2231
*/
2332
protected $_template = 'Magento_Wishlist::email/items.phtml';
2433

34+
/**
35+
* Items constructor.
36+
*
37+
* @param \Magento\Catalog\Block\Product\Context $context
38+
* @param \Magento\Framework\App\Http\Context $httpContext
39+
* @param array $data
40+
* @param ConfigInterface|null $config
41+
* @param UrlBuilder|null $urlBuilder
42+
* @param ItemResolverInterface|null $itemResolver
43+
*/
44+
public function __construct(
45+
\Magento\Catalog\Block\Product\Context $context,
46+
\Magento\Framework\App\Http\Context $httpContext,
47+
array $data = [],
48+
ConfigInterface $config = null,
49+
UrlBuilder $urlBuilder = null,
50+
ItemResolverInterface $itemResolver = null
51+
) {
52+
parent::__construct($context, $httpContext, $data, $config, $urlBuilder);
53+
$this->itemResolver = $itemResolver ?? ObjectManager::getInstance()->get(ItemResolverInterface::class);
54+
}
55+
56+
/**
57+
* Identify the product from which thumbnail should be taken.
58+
*
59+
* @param Item $item
60+
*
61+
* @return Product
62+
*/
63+
public function getProductForThumbnail(Item $item): Product
64+
{
65+
return $this->itemResolver->getFinalProduct($item);
66+
}
67+
2568
/**
2669
* Retrieve Product View URL
2770
*
2871
* @param \Magento\Catalog\Model\Product $product
2972
* @param array $additional
73+
*
3074
* @return string
3175
*/
3276
public function getProductUrl($product, $additional = [])
@@ -40,6 +84,7 @@ public function getProductUrl($product, $additional = [])
4084
*
4185
* @param \Magento\Catalog\Model\Product $product
4286
* @param array $additional
87+
*
4388
* @return string
4489
*/
4590
public function getAddToCartUrl($product, $additional = [])
@@ -53,6 +98,7 @@ public function getAddToCartUrl($product, $additional = [])
5398
* Check whether wishlist item has description
5499
*
55100
* @param \Magento\Wishlist\Model\Item $item
101+
*
56102
* @return bool
57103
*/
58104
public function hasDescription($item)

app/code/Magento/Wishlist/view/frontend/templates/email/items.phtml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,43 @@
1111
<table>
1212
<tr>
1313
<?php $i = 0;
14-
foreach ($block->getWishlistItems() as $item) : $i++ ?>
15-
<?php /* @var $item \Magento\Wishlist\Model\Item */ ?>
16-
<?php /* @var $_product \Magento\Catalog\Model\Product */ ?>
14+
foreach ($block->getWishlistItems() as $item): $i++ ?>
15+
<?php /* @var \Magento\Wishlist\Model\Item $item */ ?>
16+
<?php /* @var \Magento\Catalog\Model\Product $_product */ ?>
1717
<?php $_product = $item->getProduct(); ?>
1818
<td class="col product">
1919
<p>
20-
<a href="<?= $block->escapeUrl($block->getProductUrl($_product)) ?>">
21-
<?= /* @noEscape */ $block->getImage($_product, 'product_small_image')->toHtml() ?>
20+
<a href="<?= $block->escapeUrl($block->getProductUrl($item)) ?>">
21+
<?php $productThumbnail = $block->getProductForThumbnail($item) ?>
22+
<?= /* @noEscape */ $block->getImage($productThumbnail, 'product_small_image')->toHtml() ?>
2223
</a>
2324
</p>
2425

2526
<p>
26-
<a href="<?= $block->escapeUrl($block->getProductUrl($_product)) ?>">
27+
<a href="<?= $block->escapeUrl($block->getProductUrl($item)) ?>">
2728
<strong><?= $block->escapeHtml($_product->getName()) ?></strong>
2829
</a>
2930
</p>
30-
<?php if ($block->hasDescription($item)) : ?>
31+
<?php if ($block->hasDescription($item)): ?>
3132
<p>
3233
<strong><?= $block->escapeHtml(__('Comment')) ?>:</strong>
3334
<br/><?= /* @noEscape */ $block->getEscapedDescription($item) ?>
3435
</p>
3536
<?php endif; ?>
3637
<p>
37-
<a href="<?= $block->escapeUrl($block->getProductUrl($_product)) ?>">
38+
<a href="<?= $block->escapeUrl($block->getProductUrl($item)) ?>">
3839
<?= $block->escapeHtml(__('View Product')) ?>
3940
</a>
4041
</p>
4142
</td>
42-
<?php if ($i % 3 != 0) : ?>
43+
<?php if ($i % 3 != 0): ?>
4344
<td></td>
44-
<?php else : ?>
45+
<?php else: ?>
4546
</tr>
4647
<tr>
4748
<td colspan="5">&nbsp;</td>
4849
</tr>
49-
<?php if ($i < $l) : ?>
50+
<?php if ($i < $l): ?>
5051
<tr>
5152
<?php endif ?>
5253
<?php endif ?>

0 commit comments

Comments
 (0)