Skip to content

#27124: Update wishlist image logic to match logic on wishlist page #27125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 51 additions & 5 deletions app/code/Magento/Wishlist/Block/Share/Email/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,73 @@
* See COPYING.txt for license details.
*/

/**
* Wishlist block customer items
*
* @author Magento Core Team <[email protected]>
*/
namespace Magento\Wishlist\Block\Share\Email;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface;
use Magento\Catalog\Model\Product\Image\UrlBuilder;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\View\ConfigInterface;
use Magento\Wishlist\Model\Item;

/**
* Wishlist share items
*
* @api
* @since 100.0.2
*/
class Items extends \Magento\Wishlist\Block\AbstractBlock
{
/**
* @var ItemResolverInterface
*/
private $itemResolver;

/**
* @var string
*/
protected $_template = 'Magento_Wishlist::email/items.phtml';

/**
* Items constructor.
*
* @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 ItemResolverInterface|null $itemResolver
*/
public function __construct(
\Magento\Catalog\Block\Product\Context $context,
\Magento\Framework\App\Http\Context $httpContext,
array $data = [],
ConfigInterface $config = null,
UrlBuilder $urlBuilder = null,
ItemResolverInterface $itemResolver = null
) {
parent::__construct($context, $httpContext, $data, $config, $urlBuilder);
$this->itemResolver = $itemResolver ?? ObjectManager::getInstance()->get(ItemResolverInterface::class);
}

/**
* Identify the product from which thumbnail should be taken.
*
* @param Item $item
*
* @return Product
*/
public function getProductForThumbnail(Item $item): Product
{
return $this->itemResolver->getFinalProduct($item);
}

/**
* Retrieve Product View URL
*
* @param \Magento\Catalog\Model\Product $product
* @param array $additional
*
* @return string
*/
public function getProductUrl($product, $additional = [])
Expand All @@ -40,6 +84,7 @@ public function getProductUrl($product, $additional = [])
*
* @param \Magento\Catalog\Model\Product $product
* @param array $additional
*
* @return string
*/
public function getAddToCartUrl($product, $additional = [])
Expand All @@ -53,6 +98,7 @@ public function getAddToCartUrl($product, $additional = [])
* Check whether wishlist item has description
*
* @param \Magento\Wishlist\Model\Item $item
*
* @return bool
*/
public function hasDescription($item)
Expand Down
23 changes: 12 additions & 11 deletions app/code/Magento/Wishlist/view/frontend/templates/email/items.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,43 @@
<table>
<tr>
<?php $i = 0;
foreach ($block->getWishlistItems() as $item) : $i++ ?>
<?php /* @var $item \Magento\Wishlist\Model\Item */ ?>
<?php /* @var $_product \Magento\Catalog\Model\Product */ ?>
foreach ($block->getWishlistItems() as $item): $i++ ?>
<?php /* @var \Magento\Wishlist\Model\Item $item */ ?>
<?php /* @var \Magento\Catalog\Model\Product $_product */ ?>
<?php $_product = $item->getProduct(); ?>
<td class="col product">
<p>
<a href="<?= $block->escapeUrl($block->getProductUrl($_product)) ?>">
<?= /* @noEscape */ $block->getImage($_product, 'product_small_image')->toHtml() ?>
<a href="<?= $block->escapeUrl($block->getProductUrl($item)) ?>">
<?php $productThumbnail = $block->getProductForThumbnail($item) ?>
<?= /* @noEscape */ $block->getImage($productThumbnail, 'product_small_image')->toHtml() ?>
</a>
</p>

<p>
<a href="<?= $block->escapeUrl($block->getProductUrl($_product)) ?>">
<a href="<?= $block->escapeUrl($block->getProductUrl($item)) ?>">
<strong><?= $block->escapeHtml($_product->getName()) ?></strong>
</a>
</p>
<?php if ($block->hasDescription($item)) : ?>
<?php if ($block->hasDescription($item)): ?>
<p>
<strong><?= $block->escapeHtml(__('Comment')) ?>:</strong>
<br/><?= /* @noEscape */ $block->getEscapedDescription($item) ?>
</p>
<?php endif; ?>
<p>
<a href="<?= $block->escapeUrl($block->getProductUrl($_product)) ?>">
<a href="<?= $block->escapeUrl($block->getProductUrl($item)) ?>">
<?= $block->escapeHtml(__('View Product')) ?>
</a>
</p>
</td>
<?php if ($i % 3 != 0) : ?>
<?php if ($i % 3 != 0): ?>
<td></td>
<?php else : ?>
<?php else: ?>
</tr>
<tr>
<td colspan="5">&nbsp;</td>
</tr>
<?php if ($i < $l) : ?>
<?php if ($i < $l): ?>
<tr>
<?php endif ?>
<?php endif ?>
Expand Down