I’ve created my 1st module. The purpose is to add the customer group name to the order email template. I think that I didn’t do something quite right and was hoping someone could look at my files to see where I may have messed up. The files are stored in magento/app/code/KeystoneCandle/AddGroupEmail/, /etc and /Observer
registration.php
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'KeytoneCandle_AddGroupEmail',
__DIR__
);
module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="KeystoneCandle_AddGroupEmail" setup_version="1.0.0">
<sequence>
<module name="Magento_Catalog"/>
</sequence>
</module>
</config>
Observer file AddGroupEmail.php
<?php
namespace KeystoneCandleAddGroupEmailObserver;
use MagentoFrameworkEventObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoCustomerModelGroup;
class AddCustomerGroupToOrderEmail implements ObserverInterface
{
protected $_order;
protected $_group;
public function __construct(
MagentoSalesModelOrder $order,
Group $group
) {
$this->_order = $order;
$this->_group = $group;
}
public function execute(Observer $observer)
{
$order = $observer->getEvent()->getOrder();
$customerGroupId = $order->getCustomerGroupId();
$customerGroup = $this->_group->load($customerGroupId);
$customerGroupName = $customerGroup->getCustomerGroupCode();
// You can do additional processing with the customer group if needed.
$order->setData('customer_group_id', $customerGroupId);
$order->setData('customer_group_name', $customerGroupName);
}
}
Then in the email template I try to use these variables to show the customer group name and ID
{{var order.customer_group_name}} {{var order.customer_group_id}}
I’ve run setup:upgrade, setup:di:compile, setup:static-content:deploy -f, cache:flush/clean
The strange thing is that the
{{var order.customer_group_id}}
variable pulls the customer group id even after I disable my module (and run all the previous commands) so I’m not sure if that variable needed the observer or not but I can’t get any reaction from the customergroupname. I’d appreciate any insights. Thanks.