Zen Follower
- Join Date:
- Jun 2012
- Posts:
- 481
- Plugin Contributions:
- 0
Allow observer to override sending additional order confirmation email
I need to not send additional order confirmation emails to store personnel but only for orders generated by a point-of-sale addon. In includes/classes/order.php, where the customer order confirmation email is generated and sent, the following code does exactly what I need.
// Send customer confirmation email unless observer overrides it.
$send_customer_email = true;
$this->notify('NOTIFY_ORDER_INVOICE_CONTENT_READY_TO_SEND', array('zf_insert_id' => $zf_insert_id, 'text_email' => $email_order, 'html_email' => $html_msg), $email_order, $html_msg, $send_customer_email);
if ($send_customer_email === true) {
zen_mail($this->customer['firstname'] . ' ' . $this->customer['lastname'], $this->customer['email_address'], EMAIL_TEXT_SUBJECT . EMAIL_ORDER_NUMBER_SUBJECT . $zf_insert_id, $email_order, STORE_NAME, EMAIL_FROM, $html_msg, 'checkout', $this->attachArray);
}
For orders from the POS code, I set $send_customer_email to false in the observer to that notifier, and no email is sent to the customer.
But there is no similar code later where additional extra order confirmation emails are generated. In the interest of not modifying core code, can similar code be inserted before sending the additional order confirmation emails in a future zen cart version? This solution may be the most flexible and general. Or some other solution implemented?
One other solution is a simple mod to order.php in the check on SEND_EXTRA_ORDER_EMAILS_TO to also check $send_customer_email, which would work for my case.
Another more general, but complex solution could involve the notifier in the extra order confirmation code (NOTIFY_ORDER_INVOICE_CONTENT_FOR_ADDITIONAL_EMAILS) where an observer could potentially manipulate $email_order and $html_msg so that function zen_mail does not send the email. But $extra_info['TEXT'] is appended to $email_order in the call to zen_mail and there is no way to blank out $extra_info['TEXT'] since it is not passed to the observer, is not a global variable, and is not a class variable. If $extra_info were passed or was a class variable, this solution could be used. Or $extra_info['TEXT'] could be appended to $email_order before the notifier. Then $email_order could be set to '' and $html_msg['EMAIL_MESSAGE_HTML'] set to '' so zen_mail won't send the email.
The only way to do what I want with the current code is to have nothing set in SEND_EXTRA_ORDER_EMAILS_TO and redo the code for the additional emails within an observer of another notifier (NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL), a not very efficient method.
There are several simple solutions to my problem for future zen cart versions, some of which I have outlined above. There are probably other simple solutions too, perhaps more elegant. I hope something will be implemented.
Dave
zc157c, php 7.3.x