init
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\EmailPreview\Block\Adminhtml;
|
||||
|
||||
use Esun\EmailPreview\Model\TemplateTypes;
|
||||
use Magento\Backend\Block\Template;
|
||||
use Magento\Store\Model\System\Store;
|
||||
|
||||
class Preview extends Template
|
||||
{
|
||||
public function __construct(Template\Context $context, private readonly Store $systemStore, array $data = []) { parent::__construct($context, $data); }
|
||||
public function getTypes(): array { return TemplateTypes::TYPES; }
|
||||
public function getStoreOptions(): array { return $this->systemStore->getStoreValuesForForm(false, true); }
|
||||
public function getPreviewUrl(): string { return $this->getUrl('esun_email_preview/preview/render'); }
|
||||
public function getSendUrl(): string { return $this->getUrl('esun_email_preview/preview/send'); }
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\EmailPreview\Block\Order\Email\Items;
|
||||
|
||||
use Magento\Catalog\Helper\Image;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
|
||||
class DefaultItems extends \Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder
|
||||
{
|
||||
public function __construct(\Magento\Framework\View\Element\Template\Context $context, private readonly Image $imageHelper, private readonly ProductRepositoryInterface $products, array $data = []) { parent::__construct($context, $data); }
|
||||
public function getProductImageUrl(): string
|
||||
{
|
||||
$item = $this->getItem();
|
||||
try {
|
||||
$product = $item->getProductId()
|
||||
? $this->products->getById((int)$item->getProductId(), false, (int)$item->getStoreId())
|
||||
: $this->products->get((string)$item->getSku(), false, (int)$item->getStoreId());
|
||||
$image = (string)($product->getThumbnail() ?: $product->getSmallImage() ?: $product->getImage());
|
||||
if ($image === '' || $image === 'no_selection') {
|
||||
return '';
|
||||
}
|
||||
return (string)$this->imageHelper->init($product, 'product_thumbnail_image')->resize(96, 96)->getUrl();
|
||||
} catch (\Throwable) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user