Send Order Notification When Order Complete In Admin

I want to send a copy of the order confirmation email to a third party when an order is marked completed in admin. So far I've achieved part of it, it will send if $statusTo == “C”.



I want the email to go only when $notify_vendor == true and I'm missing a bit here. I don't seem to be able to get the var notify_vendor, anybody know what I'm missing?



function fn_my_changes_change_order_status(&$statusTo, &$statusFrom, &$order_info){
if($statusTo == "C" && $notify_vendor == true){
//send copy to trustwave
Mailer::sendMail(array(
'to' => "test@test.com",
'from' => 'admin@admin.com',
'bcc' => $order_info['email'],
'data' => array(
'order_info' => $order_info,
'shipments' => $shipments,
'use_shipments' => $use_shipments,
'order_status' => $order_status,
'payment_method' => $payment_method,
'status_settings' => $status_settings,
'profile_fields' => $profile_fields,
'secondary_currency' => $secondary_currency,
'take_surcharge_from_vendor' => $take_surcharge_from_vendor
),
'tpl' => 'orders/order_notification.tpl',
'company_id' => $order_info['company_id'],
), 'C', $order_info['lang_code']);
}
};
?>

Please add this code:



$order_statuses = fn_get_statuses(STATUSES_ORDER, array(), true, false, CART_LANGUAGE, $order_info['company_id']);
$status_params = $order_statuses[$statusTo]['params'];
$notify_vendor = !empty($status_params['notify_vendor']) && $status_params['notify_vendor'] == 'Y' ? true : false;

hi,



basically the PHP hook change_order_status has more parameters and it sounds as if you change order status to “Completed” manually in admin panel, please use this code:



function fn_my_changes_change_order_status(&$statusTo, &$statusFrom, &$order_info, $force_notification, $order_statuses, $place_order)
{
$status_params = $order_statuses[$order_info['status']]['params'];
$notify_vendor = isset($force_notification['V']) ? $force_notification['V'] : (!empty($status_params['notify_vendor']) && $status_params['notify_vendor'] == 'Y' ? true : false);

if($statusTo == "C" && $notify_vendor == true) {
//send copy to trustwave
Mailer::sendMail(array(
'to' => "test@test.com",
'from' => 'admin@admin.com',
'bcc' => $order_info['email'],
'data' => array(
'order_info' => $order_info,
'shipments' => $shipments,
'use_shipments' => $use_shipments,
'order_status' => $order_status,
'payment_method' => $payment_method,
'status_settings' => $status_settings,
'profile_fields' => $profile_fields,
'secondary_currency' => $secondary_currency,
'take_surcharge_from_vendor' => $take_surcharge_from_vendor
),
'tpl' => 'orders/order_notification.tpl',
'company_id' => $order_info['company_id'],
), 'C', $order_info['lang_code']);
}
}




let us know if it helps.



best regards,

WSA team

Thanks they both work much appreciated. Good to know that there are more parameters to change_order_status. :)

I had to change the way this is done so that now:



I'm trying to send an email after a user sends a shipment notification in the admin. I only want the email to send to third party if the admin has checked the '[font=Helvetica Neue, Helvetica, Arial, sans-serif][color=#404040][size=3]Send shipment notification to customer' checkbox 7 the order status is complete. I can't seem to capture the value of [/size][/color][/font]$force_notification





function fn_my_changes_create_shipment_post(&$order_info,&$shipment_data, $group_key, $all_products, $shipment_id,$force_notification = array()){
$all_order_info = fn_get_order_info($order_info['order_id']);
if($all_order_info['status'] == "C" && !empty($force_notification['C'])){
Mailer::sendMail(array(
'to' => "test@test.com",
'from' => 'from@from.com',
'data' => array(
'order_info' => $all_order_info,
),
'tpl' => 'orders/order_notification.tpl',
'company_id' => $all_order_info['company_id'],
), 'C', $all_order_info['lang_code']);

fn_set_notification('N', fn_get_lang_var('notice'), "Sent to Trustpilot", true, 'hispec_hello');
};

};

Please use



$force_notification = fn_get_notification_rules($_REQUEST);

[quote name='eComLabs' timestamp='1433948287' post='218249']

Please use



$force_notification = fn_get_notification_rules($_REQUEST);


[/quote]



Thanks so much that worked:



$force_notification = fn_get_notification_rules($_REQUEST);
if($all_order_info['status'] == "C" && $force_notification['C'] == true){
Mailer::sendMail(array(
'to' => "test@test.com",
'from' => 'admin@admin.com',
'data' => array(
'order_info' => $all_order_info,
),
'tpl' => 'orders/order_notification.tpl',
'company_id' => $all_order_info['company_id'],
), 'C', $all_order_info['lang_code']);

You are welcome! We are glad to help you.