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
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Magetrend_Custom',
__DIR__
);
event file C:xampphtdocsmyshopappcodeMagetrendCustometc 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="MagetrendCustomObserverCustomVar"/>
</event>
</config>
observer file C:xampphtdocsmyshopappcodeMagetrendCustomObserver CustomVar.php
<?php
namespace MagetrendCustomObserver;
class CustomVar implements MagentoFrameworkEventObserverInterface
{
protected $order;
public function __construct(
MagentoSalesModelOrder $order
)
{
$this->order = $order;
}
public function execute(MagentoFrameworkEventObserver $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