Hello everyone, I am using Multi-Vendor v4.16.1 and I need to change the “from” name & address in all customer notification emails. Currently, they are being sent from the vendor’s registered email address, but I want to send them from my company’s email address.
When I still had an active support plan I requested support from CS-Cart helpdesk and I received the following solution:
FILE: /app/addons/my_changes/init.php:
fn_register_hooks(
‘mailer_create_message_before’,
‘mailer_send_pre’
);
FILE: /app/addons/my_changes/func.php:
use Tygh\Registry;
use Tygh\Enum\SiteArea;
function fn_my_changes_mailer_create_message_before($mailer, &$message, $area, $lang_code, $transport, $builder)
{
$company_id = !empty($params[‘company_id’]) ? $params[‘company_id’] : 0;
if ($company_id && SiteArea::isStorefront($area) && strpos($message[‘template_code’], ‘order_notification’) !== false) {
$message[‘reply_to’] = ‘default_company_orders_department’;
if (is_array($message[‘from’])) {
$message[‘from’][‘name’] = Registry::get(‘settings.Company.company_name’);
}
}
}
function fn_my_changes_mailer_send_pre($mailer, $transport, $message, $area, $lang_code) {
$from = $message->getFrom();
$company_id = $message->getCompanyId();
$data = $message->getData();
if ($company_id && strpos($data[‘template_code’], ‘order_notification’) !== false) {
$message->setFrom(key($from), Registry::get(‘settings.Company.company_name’));
}
}
The above code does change the from address, but whenever an order is placed I am receiving the PHP error:
“Notice: Undefined index: template_code in /…/app/addons/my_changes/func.php on line 21”
How could I solve this? Thank you for your help!