Hook To Add Bcc Email To Fn_Order_Notification Function

Every time an order is created by an admin, I want to get a copy of the notification.

I want to pass my email address to the fn_order_notification in the file fn.cart.php

I have the my_changes addon working.

So in my init.php file I register my hook:

fn_register_hooks(
     'order_notification'
);
Then in the file func.php (that's how I have my_changes setup) I added the function:
function fn_my_changes_order_notification($order_info, $order_statuses, $force_notification){
      $mailer->addrAppend('Bcc', array('name@myserver.com'));
}

Of course this is not working. So in the function fn_order_notification, I want to BCC to myself only on the email that is sent to customer :

// Notify customer
        if ($notify_user == true) {
        $mailer->send(array(
            'to' => $order_info['email'],
            'from' => 'company_orders_department',
            'data' => array(
                'order_info' => $order_info,
                'shipments' => $shipments,
                'tracking_numbers' => $tracking_numbers,
                'shipping_methods' => $shipping_methods,
                'order_status' => $order_status,
                'payment_method' => $payment_method,
                'profile_fields' => $profile_fields,
                'profields' => $profields,
                'secondary_currency' => $secondary_currency,
                'take_surcharge_from_vendor' => $take_surcharge_from_vendor
            ),
            'template_code' => $email_template_name,
            'tpl' => 'orders/order_notification.tpl', // this parameter is obsolete and is used for back compatibility
            'company_id' => $order_info['company_id'],
        ), 'C', $order_info['lang_code']);

        if (!empty($edp_data)) {
            $mailer->send(array(
                'to' => $order_info['email'],
                'from' => 'company_orders_department',
                'data' => array(
                    'order_files_list_url' => fn_url("orders.order_downloads&order_id={$order_info['order_id']}", 'C'),
                    'order_info' => $order_info,
                    'edp_data' => $edp_data,
                ),
                'template_code' => 'edp_access',
                'tpl' => 'orders/edp_access.tpl', // this parameter is obsolete and is used for back compatibility
                'company_id' => $order_info['company_id'],
            ), 'C', $order_info['lang_code']);
        }
    }

What am I doing wrong in my hook setup?

As you can see, $mailer is not in the list of the hook arguments. Try to use the mailer_send_pre hook (app/Tygh/Mailer/Mailer.php)

I don't know if this will work for your needs but it is certainly a lot easier. You can add multiple emails in the email notification settings separated by a semi colon.

[attachment=13004:addition_email.jpg]

addition_email.jpg

I don't know if this will work for your needs but it is certainly a lot easier. You can add multiple emails in the email notification settings separated by a semi colon.

attachicon.gifaddition_email.jpg

ewelg said

... only on the email that is sent to customer

ewelg said

... only on the email that is sent to customer



That's why I said
I don't know if this will work for your needs but...
eweig may not be aware of all of the options.?

That's why I said

I don't know if this will work for your needs but...
eweig may not be aware of all of the options.?

Hope our suggestions will help eweig

Your suggestions always guide me and I appreciate it.

As you suggested I'm using a hook to mailer_send_pre. So my function looks like this:


function fn_my_changes_mailer_send_pre($this, $transport, $message, $area, $lang_code){
$message->addBCC('someone@myhost.com');
}

This does send me a copy of the email. The only issue now is that in the order form I have "Notify Customer" and "Notify orders department" check marked.

So it's adding the BCC to both emails which results in two 2 emails for each order. I need to figure out how to attach it to one of the emails and not the other. Any ideas?

@TheTool gave an interesting solution, but wouldn't work on my issue. I'm sending this copy to the creator of the order.

So it's adding the BCC to both emails which results in two 2 emails for each order. I need to figure out how to attach it to one of the emails and not the other. Any ideas?

As an option, try to compare $message->getTo() with Registry::get('settings.Company.company_orders_department')

Alternatively give you are using a BCC you could simply turn off admin notification in the order statuses.

And actually, from a legal perspective, using a BCC is a much stronger case given that both addresses are in the same message versus a separate copy. Never understood why they went with separate emails for copies versus BCC.

Alternatively give you are using a BCC you could simply turn off admin notification in the order statuses.

And actually, from a legal perspective, using a BCC is a much stronger case given that both addresses are in the same message versus a separate copy. Never understood why they went with separate emails for copies versus BCC.

If old template editor is used, the system sends different e-mail to admin and customer. Yes, they looks similar, but different templates are used. I can assume that сustomized customer e-mail template is used on his store. But may be I am wrong

Not sure I understand what the relationship of template/editor is to the number of emails sent. The mailer will send multiple emails if notify admin, notify customer and/or notify vendor are selected for a status. I don't believe BCC is used for any of them which was my point. It is true that you set those notifications differently depending on which email method are are using (not sure why on that either, seems like unnecessary duplication), I don't believe that has any impact on the underlying mailer actions.

Does the new editor use BCC in the mailer when 'notify admin' is set?

Not sure I understand what the relationship of template/editor is to the number of emails sent. The mailer will send multiple emails if notify admin, notify customer and/or notify vendor are selected for a status. I don't believe BCC is used for any of them which was my point. It is true that you set those notifications differently depending on which email method are are using (not sure why on that either, seems like unnecessary duplication), I don't believe that has any impact on the underlying mailer actions.

Does the new editor use BCC in the mailer when 'notify admin' is set?

Old template editor:

Notify admin: sends invoice from design/backend/mail

Notify customer: sends invoice from design/themes/TEHEME/mail

New template editor:

Notify admin: sends invoice from database

Notify customer: sends the same invoice from database

So for old editor invoice content can be completely different and eweig wants to receive both e-mail (for admin and customer) to one e-mail address

Just my thoughts

Yes they can have separate content. I simply don't understand why they never made BCC a part of the standard product. It is the only way to ensure that the contract between customer and merchant is documented. I don't think separate copies (especially with separate content) would stand up as evidence in court if a dispute ever evolved. I'd much rather see:

[] Notify customer ( [] BCC admin)

[] Notify admin

[] Notify vendor ( [] BCC admin)

As the options...