module.xml
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> <module name="Magetrend_Custom" schema_version="2.0.0" setup_version="2.0.0"> <sequence> <module name="Magetrend_Email"/> </sequence> </module> </config>
registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Magetrend_Custom',
__DIR__
);
event file C:\xampp\htdocs\myshop\app\code\Magetrend\Custom\etc events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="magetrend_email_collect_additional_vars">
<observer name="mtemail_custom_var" instance="Magetrend\Custom\Observer\CustomVar"/>
</event>
</config>
observer file C:\xampp\htdocs\myshop\app\code\Magetrend\Custom\Observer CustomVar.php
<?php
namespace Magetrend\Custom\Observer;
class CustomVar implements \Magento\Framework\Event\ObserverInterface { protected $order;
public function __construct(
\Magento\Sales\Model\Order $order
)
{
$this->order = $order;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$transport = $observer->getTransport();
$orderId = $observer->getTransport()->getOrderId();
$order = $this->order->load($orderId);
$allVisibleItems = $order->getAllVisibleItems();
$totalItemsCount = count($order->getAllVisibleItems());
$i = 0;
foreach ($allVisibleItems as $item)
{
if($i == 0){
$productName = $item->getProduct()->getName();
break;
}
$i++;
}
if($totalItemsCount > 1){
$remainingItems = $totalItemsCount - 1;
$transport['itemName'] = $productName.' and '.$remainingItems .' more products';
}else{
$transport['itemName'] = $productName;
}
}
}
what is the problem? email template