/** * Send order notification * * @param array $order_info order information * @param array $edp_data information about downloadable products * @param mixed $force_notification user notification flag (true/false), if not set, will be retrieved from status parameters * @return array structured data */ function fn_order_notification(&$order_info, $edp_data = array(), $force_notification = array()) { static $notified = array(); $send_order_notification = true; if (!empty($notified[$order_info['order_id']][$order_info['status']]) && $notified[$order_info['order_id']][$order_info['status']] || $order_info['status'] == STATUS_INCOMPLETED_ORDER || $order_info['status'] == STATUS_PARENT_ORDER) { $send_order_notification = false; } fn_set_hook('send_order_notification', $order_info, $edp_data, $force_notification, $notified, $send_order_notification); $take_surcharge_from_vendor = false; if (fn_allowed_for('MULTIVENDOR')) { $take_surcharge_from_vendor = fn_take_payment_surcharge_from_vendor($order_info['products']); } if (!$send_order_notification) { return true; } $order_statuses = fn_get_statuses(STATUSES_ORDER, array(), true, false, $order_info['lang_code'] ? $order_info['lang_code'] : CART_LANGUAGE, $order_info['company_id']); $status_params = $order_statuses[$order_info['status']]['params']; $notify_user = !empty($status_params['notify']) && $status_params['notify'] == 'Y'; $notify_department = !empty($status_params['notify_department']) && $status_params['notify_department'] == 'Y'; $notify_vendor = !empty($status_params['notify_vendor']) && $status_params['notify_vendor'] == 'Y'; if (!is_array($force_notification)) { $force_notification = fn_get_notification_rules($force_notification, !$force_notification); } if (isset($force_notification['C'])) { $notify_user = $force_notification['C']; } if (isset($force_notification['A'])) { $notify_department = $force_notification['A']; } if (isset($force_notification['V'])) { $notify_vendor = $force_notification['V']; } if ($notify_user || $notify_department || $notify_vendor) { $notified[$order_info['order_id']][$order_info['status']] = true; $order_status = $order_statuses[$order_info['status']]; $payment_id = !empty($order_info['payment_method']['payment_id']) ? $order_info['payment_method']['payment_id'] : 0; $payment_method = fn_get_payment_data($payment_id, $order_info['order_id'], $order_info['lang_code']); $status_settings = $order_statuses[$order_info['status']]['params']; $profile_fields = fn_get_profile_fields('I', '', $order_info['lang_code']); $secondary_currency = ''; list($shipments) = fn_get_shipments_info(array('order_id' => $order_info['order_id'], 'advanced_info' => true)); $use_shipments = !fn_one_full_shipped($shipments); // restore secondary currency if (!empty($order_info['secondary_currency']) && Registry::get("currencies.{$order_info['secondary_currency']}")) { $secondary_currency = $order_info['secondary_currency']; } // Notify customer if ($notify_user == true) { Mailer::sendMail(array('to' => $order_info['email'], 'from' => 'company_orders_department', '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']); if (!empty($edp_data)) { Mailer::sendMail(array('to' => $order_info['email'], 'from' => 'company_orders_department', 'data' => array('order_info' => $order_info, 'edp_data' => $edp_data), 'tpl' => 'orders/edp_access.tpl', 'company_id' => $order_info['company_id']), 'C', $order_info['lang_code']); } } if ($notify_vendor == true) { if (fn_allowed_for('MULTIVENDOR') && !empty($order_info['company_id'])) { $company_lang_code = fn_get_company_language($order_info['company_id']); // Translate descriptions to admin language fn_translate_products($order_info['products'], '', $company_lang_code, true); Mailer::sendMail(array('to' => 'company_orders_department', 'from' => 'default_company_orders_department', 'reply_to' => $order_info['email'], 'data' => array('order_info' => $order_info, 'shipments' => $shipments, 'use_shipments' => $use_shipments, 'order_status' => fn_get_status_data($order_info['status'], STATUSES_ORDER, $order_info['order_id'], $company_lang_code), 'payment_method' => fn_get_payment_data($payment_id, $order_info['order_id'], $company_lang_code), 'status_settings' => $status_settings, 'profile_fields' => fn_get_profile_fields('I', '', $company_lang_code), 'secondary_currency' => $secondary_currency), 'tpl' => 'orders/order_notification.tpl', 'company_id' => $order_info['company_id']), 'A', $company_lang_code); } } // Notify order department if ($notify_department == true) { // Translate descriptions to admin language fn_translate_products($order_info['products'], '', Registry::get('settings.Appearance.backend_default_language'), true); $payment_method = array(); if ($payment_id) { $payment_method = fn_get_payment_data($payment_id, $order_info['order_id'], Registry::get('settings.Appearance.backend_default_language')); } fn_add_user_data_descriptions($order_info, Registry::get('settings.Appearance.backend_default_language')); Mailer::sendMail(array('to' => 'default_company_orders_department', 'from' => 'default_company_orders_department', 'reply_to' => $order_info['email'], 'data' => array('order_info' => $order_info, 'shipments' => $shipments, 'use_shipments' => $use_shipments, 'order_status' => fn_get_status_data($order_info['status'], STATUSES_ORDER, $order_info['order_id'], Registry::get('settings.Appearance.backend_default_language')), 'payment_method' => $payment_method, 'status_settings' => $status_settings, 'profile_fields' => fn_get_profile_fields('I', '', Registry::get('settings.Appearance.backend_default_language')), 'secondary_currency' => $secondary_currency), 'tpl' => 'orders/order_notification.tpl', 'company_id' => $order_info['company_id']), 'A', Registry::get('settings.Appearance.backend_default_language')); } } if (!empty($edp_data) && !$notify_user) { // Send out download links for EDP with "Immediately" Activation mode // TRUE if the EDP download links e-mail has already been sent. Used to avoid sending duplicate e-mails. $download_email_sent = false; foreach ($edp_data as $edp_item) { foreach ($edp_item['files'] as $file) { if (!empty($file['activation']) && $file['activation'] == 'I' && !$download_email_sent) { Mailer::sendMail(array('to' => $order_info['email'], 'from' => 'company_orders_department', 'data' => array('order_info' => $order_info, 'edp_data' => $edp_data), 'tpl' => 'orders/edp_access.tpl', 'company_id' => $order_info['company_id']), 'C', $order_info['lang_code']); $download_email_sent = true; break; } } } } fn_set_hook('order_notification', $order_info, $order_statuses, $force_notification); }
/** * Send order notification * * @param array $order_info order information * @param array $edp_data information about downloadable products * @param mixed $force_notification user notification flag (true/false), if not set, will be retrieved from status parameters * @return array structured data */ function fn_order_notification(&$order_info, $edp_data = array(), $force_notification = array()) { static $notified = array(); if (!empty($notified[$order_info['order_id']][$order_info['status']]) && $notified[$order_info['order_id']][$order_info['status']] || $order_info['status'] == STATUS_INCOMPLETED_ORDER || $order_info['status'] == STATUS_PARENT_ORDER) { return true; } if (!is_array($force_notification)) { $force_notification = fn_get_notification_rules($force_notification, !$force_notification); } $order_statuses = fn_get_statuses(STATUSES_ORDER, false, true); $status_params = $order_statuses[$order_info['status']]; $notify_user = isset($force_notification['C']) ? $force_notification['C'] : (!empty($status_params['notify']) && $status_params['notify'] == 'Y' ? true : false); $notify_department = isset($force_notification['A']) ? $force_notification['A'] : (!empty($status_params['notify_department']) && $status_params['notify_department'] == 'Y' ? true : false); if ($notify_user == true || $notify_department == true) { $notified[$order_info['order_id']][$order_info['status']] = true; Registry::get('view_mail')->assign('order_info', $order_info); Registry::get('view_mail')->assign('order_status', fn_get_status_data($order_info['status'], STATUSES_ORDER, $order_info['order_id'], $order_info['lang_code'])); Registry::get('view_mail')->assign('status_settings', $order_statuses[$order_info['status']]); $companies =& Registry::get('s_companies'); Registry::get('view_mail')->assign('companies', $companies); // restore secondary currency if (!empty($order_info['secondary_currency']) && Registry::get("currencies.{$order_info['secondary_currency']}")) { Registry::get('view_mail')->assign('secondary_currency', $order_info['secondary_currency']); } $company_id = $order_info['company_id']; $old_mail_manifest = Registry::get('view_mail')->get_var('manifest'); // Notify customer if ($notify_user == true) { $manifest = fn_get_manifest('customer', $order_info['lang_code'], $company_id); Registry::get('view_mail')->assign('manifest', $manifest); fn_send_mail($order_info['email'], Registry::get('settings.Company.company_newsletter_email'), 'orders/order_notification_subj.tpl', 'orders/order_notification.tpl', '', $order_info['lang_code']); // fn_send_mail('*****@*****.**', Registry::get('settings.Company.company_orders_department'), 'orders/order_notification_subj.tpl', 'orders/order_notification.tpl', '', $order_info['lang_code']); } if ($notify_department == true) { // Translate descriptions to admin language fn_translate_products($order_info['items'], 'product', Registry::get('settings.Appearance.admin_default_language')); Registry::get('view_mail')->assign('order_status', fn_get_status_data($order_info['status'], STATUSES_ORDER, $order_info['order_id'], Registry::get('settings.Appearance.admin_default_language'))); $company_email = !empty($companies[$company_id]['email']) ? $companies[$company_id]['email'] : Registry::get('settings.Company.company_orders_department'); $lang_code = Registry::get('settings.Appearance.admin_default_language'); $manifest = fn_get_manifest('customer', $lang_code, $company_id); Registry::get('view_mail')->assign('manifest', $manifest); fn_send_mail($company_email, Registry::get('settings.Company.company_orders_department'), 'orders/order_notification_subj.tpl', 'orders/order_notification.tpl', '', $lang_code, $order_info['email']); if (Registry::get('settings.Suppliers.notify_order_department') == 'Y') { Registry::get('view_mail')->assign('manifest', $old_mail_manifest); fn_send_mail(Registry::get('settings.Company.company_orders_department'), Registry::get('settings.Company.company_orders_department'), 'orders/order_notification_subj.tpl', 'orders/order_notification.tpl', '', $lang_code, $order_info['email']); } } Registry::get('view_mail')->assign('manifest', $old_mail_manifest); if (!empty($edp_data) && $notify_user == true) { Registry::get('view_mail')->assign('edp_data', $edp_data); fn_send_mail($order_info['email'], Registry::get('settings.Company.company_orders_department'), 'orders/edp_access_subj.tpl', 'orders/edp_access.tpl', '', $order_info['lang_code']); } } if (!empty($edp_data) && !$notify_user) { // Send out download links for EDP with "Immediately" Activation mode // TRUE if the EDP download links e-mail has already been sent. Used to avoid sending duplicate e-mails. $download_email_sent = false; foreach ($edp_data as $edp_item) { foreach ($edp_item['files'] as $file) { if (!empty($file['activation']) && $file['activation'] == 'I' && !$download_email_sent) { Registry::get('view_mail')->assign('edp_data', $edp_data); Registry::get('view_mail')->assign('order_info', $order_info); fn_send_mail($order_info['email'], Registry::get('settings.Company.company_orders_department'), 'orders/edp_access_subj.tpl', 'orders/edp_access.tpl', '', $order_info['lang_code']); $download_email_sent = true; break; } } } } if (PRODUCT_TYPE == 'PROFESSIONAL') { fn_companies_suppliers_order_notification($order_info, $order_statuses, $force_notification); } fn_set_hook('order_notification', $order_info, $order_statuses, $force_notification); }