public static function sendMail($params, $area = AREA, $lang_code = CART_LANGUAGE) { if (empty($params['to']) || empty($params['from']) || empty($params['tpl']) && empty($params['body'])) { return false; } fn_disable_live_editor_mode(); $from = array('email' => '', 'name' => ''); $to = array(); $reply_to = array(); $cc = array(); $mailer = self::instance(!empty($params['mailer_settings']) ? $params['mailer_settings'] : array()); fn_set_hook('send_mail_pre', $mailer, $params, $area, $lang_code); $mailer->ClearReplyTos(); $mailer->ClearCCs(); $mailer->ClearAttachments(); $mailer->Sender = ''; $params['company_id'] = !empty($params['company_id']) ? $params['company_id'] : 0; $company_data = fn_get_company_placement_info($params['company_id'], $lang_code); foreach (array('reply_to', 'to', 'cc') as $way) { if (!empty($params[$way])) { if (!is_array($params[$way])) { ${$way}[] = !empty($company_data[$params[$way]]) ? $company_data[$params[$way]] : $params[$way]; } else { foreach ($params[$way] as $way_ar) { ${$way}[] = !empty($company_data[$way_ar]) ? $company_data[$way_ar] : $way_ar; } } } } if (!empty($reply_to)) { $reply_to = $mailer->formatEmails($reply_to); foreach ($reply_to as $rep_to) { $mailer->AddReplyTo($rep_to); } } if (!empty($cc)) { $cc = $mailer->formatEmails($cc); foreach ($cc as $c) { $mailer->AddCC($c); } } if (!is_array($params['from'])) { if (!empty($company_data[$params['from']])) { $from['email'] = $company_data[$params['from']]; $from['name'] = strstr($params['from'], 'default_') ? $company_data['default_company_name'] : $company_data['company_name']; } elseif (self::ValidateAddress($params['from'])) { $from['email'] = $params['from']; } } else { if (!empty($params['from']['email'])) { if (!empty($company_data[$params['from']['email']])) { $from['email'] = $company_data[$params['from']['email']]; if (empty($params['from']['name'])) { $params['from']['name'] = strstr($params['from']['email'], 'default_') ? $company_data['default_company_name'] : $company_data['company_name']; } } else { $from['email'] = $params['from']['email']; } $from['name'] = !empty($company_data[$params['from']['name']]) ? $company_data[$params['from']['name']] : $params['from']['name']; } } if (empty($to) || empty($from['email'])) { return false; } $mailer->SetFrom($from['email'], $from['name']); $mailer->IsHTML(isset($params['is_html']) ? $params['is_html'] : true); $mailer->CharSet = CHARSET; // Pass data to template foreach ($params['data'] as $k => $v) { Registry::get('view')->assign($k, $v); } Registry::get('view')->assign('company_data', $company_data); $company_id = isset($params['company_id']) ? $params['company_id'] : null; if (!empty($params['tpl'])) { // Get template name for subject and render it $tpl_ext = fn_get_file_ext($params['tpl']); $subj_tpl = str_replace('.' . $tpl_ext, '_subj.' . $tpl_ext, $params['tpl']); $subject = Registry::get('view')->displayMail($subj_tpl, false, $area, $company_id, $lang_code); // Render template for body $body = Registry::get('view')->displayMail($params['tpl'], false, $area, $company_id, $lang_code); } else { $subject = $params['subj']; $body = $params['body']; } $mailer->Body = $mailer->attachImages($body); $mailer->Subject = trim($subject); if (!empty($params['attachments'])) { foreach ($params['attachments'] as $name => $file) { $mailer->AddAttachment($file, $name); } } $to = $mailer->formatEmails($to); foreach ($to as $v) { $mailer->ClearAddresses(); $mailer->AddAddress($v, ''); $result = $mailer->Send(); if (!$result) { fn_set_notification('E', __('error'), __('error_message_not_sent') . ' ' . $mailer->ErrorInfo); } fn_set_hook('send_mail', $mailer); } return $result; }
$n_month = (int) date("m", $order_info['timestamp']); $invoice_date = date("d", $order_info['timestamp']) . ' ' . $month[$n_month] . ' ' . date("Y", $order_info['timestamp']); $order_info['str_total'] = CART_SECONDARY_CURRENCY == 'RUB' ? RusInvoicePayment::clearDoit($order_info['total']) : ""; $order_info['path_stamp'] = fn_get_image_pairs($order_info['payment_id'], 'stamp', 'M', true, true, DESCR_SL); $order_info['text_invoice_payment'] = __("addons.rus_payments.text_invoice_payment", array('[number_account]' => $order_info['order_id'], '[invoice_data]' => $invoice_date)); $view = Tygh::$app['view']; //fn_set_notification('I','view>',print_r($view)); $view->assign('total_print', $total_print); $view->assign('order_info', $order_info); $view->assign('fonts_path', fn_get_theme_path('[relative]/[theme]/media/fonts')); if ($order_info['shipping_cost'] != 0) { $view->assign('shipping_cost', true); } if ($mode == "send_account_payment") { if (!empty($order_info['email'])) { fn_disable_live_editor_mode(); $html = array($view->displayMail('addons/rus_payments/print_invoice_payment.tpl', false, 'C')); Pdf::render($html, fn_get_files_dir_path() . 'account_payment.pdf', 'save'); $data = array('order_info' => $order_info, 'total_print' => $total_print, 'fonts_path' => fn_get_theme_path('[relative]/[theme]/media/fonts')); Mailer::sendMail(array('to' => $order_info['email'], 'from' => 'default_company_orders_department', 'data' => $data, 'attachments' => array(fn_get_files_dir_path() . 'account_payment.pdf'), 'tpl' => 'addons/rus_payments/print_invoice_payment.tpl', 'is_html' => true), 'A'); fn_set_notification('N', __('notice'), __('text_email_sent')); } } else { $view->assign('show_print_button', true); $view->displayMail('addons/rus_payments/print_invoice_payment.tpl', true, 'C'); } exit; } elseif ($mode == 'get_stamp') { Header("Content-Type: image/png"); Header("Content-Type: image/jpg"); Header("Content-Type: image/jpeg");
function fn_print_order_invoices($order_ids, $pdf = false, $area = AREA, $lang_code = CART_LANGUAGE) { $view = Registry::get('view'); $html = array(); $view->assign('order_status_descr', fn_get_simple_statuses(STATUSES_ORDER, true, true)); $view->assign('profile_fields', fn_get_profile_fields('I')); if (!is_array($order_ids)) { $order_ids = array($order_ids); } foreach ($order_ids as $order_id) { $order_info = fn_get_order_info($order_id, false, true, false, true); if (empty($order_info)) { continue; } if (fn_allowed_for('MULTIVENDOR')) { $view->assign('take_surcharge_from_vendor', fn_take_payment_surcharge_from_vendor($order_info['products'])); } list($shipments) = fn_get_shipments_info(array('order_id' => $order_info['order_id'], 'advanced_info' => true)); $use_shipments = !fn_one_full_shipped($shipments); $view->assign('order_info', $order_info); $view->assign('shipments', $shipments); $view->assign('use_shipments', $use_shipments); $view->assign('payment_method', fn_get_payment_data(!empty($order_info['payment_method']['payment_id']) ? $order_info['payment_method']['payment_id'] : 0, $order_info['order_id'], $lang_code)); $view->assign('order_status', fn_get_status_data($order_info['status'], STATUSES_ORDER, $order_info['order_id'], $lang_code, $order_info['company_id'])); $view->assign('status_settings', fn_get_status_params($order_info['status'])); $view->assign('company_data', fn_get_company_placement_info($order_info['company_id'], $lang_code)); if ($pdf == true) { fn_disable_live_editor_mode(); $html[] = $view->displayMail('orders/print_invoice.tpl', false, $area, $order_info['company_id'], $lang_code); } else { $view->displayMail('orders/print_invoice.tpl', true, $area, $order_info['company_id'], $lang_code); if ($order_id != end($order_ids)) { echo "<div style='page-break-before: always;'> </div>"; } } } if ($pdf == true) { Pdf::render($html, __('invoices') . '-' . implode('-', $order_ids)); } return true; }
function fn_print_order_packing_slips($order_ids, $pdf = false, $lang_code = CART_LANGUAGE) { $view = Registry::get('view'); $html = array(); if (!is_array($order_ids)) { $order_ids = array($order_ids); } foreach ($order_ids as $order_id) { $order_info = fn_get_order_info($order_id, false, true, false, true); if (empty($order_info)) { continue; } $view->assign('order_info', $order_info); if ($pdf == true) { fn_disable_live_editor_mode(); $html[] = $view->displayMail('orders/print_packing_slip.tpl', false, 'A', $order_info['company_id'], $lang_code); } else { $view->displayMail('orders/print_packing_slip.tpl', true, 'A', $order_info['company_id'], $lang_code); } if ($order_id != end($order_ids)) { echo "<div style='page-break-before: always;'> </div>"; } } if ($pdf == true) { Pdf::render($html, __('packing_slip') . '-' . implode('-', $order_ids)); } return true; }
function fn_qwintry_save_order_invoice($order_id, $area = AREA, $lang_code = CART_LANGUAGE) { $view = Tygh::$app['view']; $html = array(); $view->assign('order_status_descr', fn_get_simple_statuses(STATUSES_ORDER, true, true)); $view->assign('profile_fields', fn_get_profile_fields('I')); $order_info = fn_get_order_info($order_id, false, true, false, true); if (empty($order_info)) { return; } if (fn_allowed_for('MULTIVENDOR')) { $view->assign('take_surcharge_from_vendor', fn_take_payment_surcharge_from_vendor($order_info['products'])); } list($shipments) = fn_get_shipments_info(array('order_id' => $order_info['order_id'], 'advanced_info' => true)); $use_shipments = !fn_one_full_shipped($shipments); $view->assign('order_info', $order_info); $view->assign('shipments', $shipments); $view->assign('use_shipments', $use_shipments); $view->assign('payment_method', fn_get_payment_data(!empty($order_info['payment_method']['payment_id']) ? $order_info['payment_method']['payment_id'] : 0, $order_info['order_id'], $lang_code)); $view->assign('order_status', fn_get_status_data($order_info['status'], STATUSES_ORDER, $order_info['order_id'], $lang_code, $order_info['company_id'])); $view->assign('status_settings', fn_get_status_params($order_info['status'])); $view->assign('company_data', fn_get_company_placement_info($order_info['company_id'], $lang_code)); fn_disable_live_editor_mode(); $html[] = $view->displayMail('orders/print_invoice.tpl', false, $area, $order_info['company_id'], $lang_code); $filename = QWINTRY_DIR_INVOICES . $order_id . '.pdf'; if (Pdf::render($html, $filename, true)) { return $filename; } return false; }
function fn_print_shipment_packing_slips($shipment_ids, $pdf = false, $lang_code = CART_LANGUAGE) { $view = Tygh::$app['view']; $month = array(1 => 'Января', 2 => 'Февраля', 3 => 'Марта', 4 => 'Апреля', 5 => 'Мая', 6 => 'Июня', 7 => 'Июля', 8 => 'Августа', 9 => 'Сентября', 10 => 'Октября', 11 => 'Ноября', 12 => 'Декабря'); foreach ($shipment_ids as $shipment_id) { list($shipment, $order_info) = fn_get_packing_info($shipment_id); $order_info_ = fn_get_order_info($order_info['order_id']); if (empty($shipment)) { continue; } $total_weight = 0; // foreach($order_info['products'] as $pi=>$pv) // { // $total_weight+=$pv['weight']; // } $order_info['payment_info'] = $order_info_['payment_info']; $order_info['payment_method'] = $order_info_['payment_method']; $order_info['timestamp'] = $order_info_['timestamp']; $order_info['info_customer'] = ""; $n_month = (int) date("m", $order_info['timestamp']); $invoice_date = date("d", $order_info['timestamp']) . ' ' . $month[$n_month] . ' ' . date("Y", $order_info['timestamp']); $order_info['text_invoice_payment'] = __("addons.rus_payments.text_invoice_payment", array('[number_account]' => $order_info['order_id'], '[invoice_data]' => $invoice_date)); $order_info['invoice_date'] = $invoice_date; $products = fn_load_products_extra_data($order_info['products'], array('only_short_fields' => true), 'ru'); $total_amount = 0; //var_dump($products); die(); foreach ($products as $pi => $pv) { $weights[$pi] = $pv['weight']; $total_weight += $pv['weight'] * $pv['shipped_amount']; $total_amount += $pv['shipped_amount']; //var_dump($pv['amount'],'<br/>'); } $order_info['weights'] = $weights; $order_info['total_cnt'] = $total_amount; $order_info['str_count'] = RusInvoicePayment::clearDoit($total_amount); $order_info['str_count'] = str_replace('Один', 'Одно', $order_info['str_count']); $order_info['str_count'] = str_replace(array(' 00 копеек', 'рублей', 'рубль', 'рубля'), '', $order_info['str_count']); $order_info['total_weight'] = RusInvoicePayment::clearDoit($total_weight); $order_info['total_weight'] = str_replace(array('рублей', 'рубль'), 'килограмм', $order_info['total_weight']); $order_info['total_weight'] = str_replace('рубля', 'килограмма', $order_info['total_weight']); $order_info['total_weight'] = str_replace('копеек', 'грамм', $order_info['total_weight']); $order_info['str_total'] = RusInvoicePayment::clearDoit($order_info['display_subtotal']); if (!empty($order_info['payment_info'])) { if (!empty($order_info['payment_info']['organization_customer'])) { $order_info['info_customer'] .= $order_info['payment_info']['organization_customer'] . ' '; } if (!empty($order_info['payment_info']['inn_customer'])) { $order_info['info_customer'] .= __("inn_customer") . ': ' . $order_info['payment_info']['inn_customer'] . ' '; } if (!empty($order_info['payment_info']['kpp_customer'])) { $order_info['info_customer'] .= __("kpp_customer") . ': ' . $order_info['payment_info']['kpp_customer'] . ' '; } if (!empty($order_info['payment_info']['ogrn_customer'])) { $order_info['info_customer'] .= __("ogrn_customer") . ': ' . $order_info['payment_info']['ogrn_customer'] . ' '; } if (!empty($order_info['payment_info']['phone'])) { $order_info['info_customer'] .= __("phone") . ': ' . $order_info['payment_info']['phone'] . ' '; } if (!empty($order_info['payment_info']['zip_postal_code'])) { $order_info['info_customer'] .= __("zip_postal_code") . ': ' . $order_info['payment_info']['zip_postal_code'] . ' '; } if (!empty($order_info['payment_info']['address'])) { $order_info['info_customer'] .= __("address") . ': ' . $order_info['payment_info']['address'] . ' '; } if (!empty($order_info['payment_info']['bank_details'])) { $order_info['info_customer'] .= __("addons.rus_payments.bank_details") . ': ' . $order_info['payment_info']['bank_details']; } } $order_info['info_supplier'] = ""; $data_payment = $order_info['payment_method']['processor_params']; if (!empty($data_payment)) { if (!empty($data_payment['account_recepient_name'])) { $order_info['info_supplier'] .= $data_payment['account_recepient_name'] . '; '; } if (!empty($data_payment['account_address'])) { $order_info['info_supplier'] .= __("address") . ': ' . $data_payment['account_address'] . '; '; } if (!empty($data_payment['account_inn'])) { $order_info['info_supplier'] .= __("inn_customer") . ': ' . $data_payment['account_inn'] . ' / '; } if (!empty($data_payment['account_kpp'])) { $order_info['info_supplier'] .= __("addons.rus_payments.account_kpp") . ': ' . $data_payment['account_kpp'] . '; '; } if (!empty($data_payment['account_ogrn'])) { $order_info['info_supplier'] .= __("ogrn_customer") . ': ' . $data_payment['account_ogrn'] . '; '; } if (!empty($data_payment['account_bank'])) { $order_info['info_supplier'] .= "Банк" . ': ' . $data_payment['account_bank'] . ' '; } if (!empty($data_payment['account_current'])) { $order_info['info_supplier'] .= "р/с" . ': ' . $data_payment['account_current'] . '; '; } if (!empty($data_payment['account_cor'])) { $order_info['info_supplier'] .= "к/с" . ': ' . $data_payment['account_cor'] . '; '; } if (!empty($data_payment['account_bik'])) { $order_info['info_supplier'] .= "БИК" . ': ' . $data_payment['account_bik'] . '; '; } // if (!empty($data_payment['account_phone'])) { // $order_info['info_supplier'] .= __("phone") . ': ' . $data_payment['account_phone'] . ' '; // } } $view->assign('order_info', $order_info); $view->assign('shipment', $shipment); if ($pdf == true) { fn_disable_live_editor_mode(); $html[] = $view->displayMail('orders/print_packing_slip.tpl', false, 'A', $order_info['company_id'], $lang_code); } else { $view->displayMail('orders/print_packing_slip.tpl', true, 'A', $order_info['company_id'], $lang_code); if ($shipment_id != end($shipment_ids)) { echo "<div style='page-break-before: always;'> </div>"; } } } if ($pdf == true) { Pdf::render($html, __('shipments') . '-' . implode('-', $shipment_ids)); } return true; }
function fn_print_shipment_packing_slips($shipment_ids, $pdf = false, $lang_code = CART_LANGUAGE) { $view = Tygh::$app['view']; foreach ($shipment_ids as $shipment_id) { list($shipment, $order_info) = fn_get_packing_info($shipment_id); if (empty($shipment)) { continue; } $view->assign('order_info', $order_info); $view->assign('shipment', $shipment); if ($pdf == true) { fn_disable_live_editor_mode(); $html[] = $view->displayMail('orders/print_packing_slip.tpl', false, 'A', $order_info['company_id'], $lang_code); } else { $view->displayMail('orders/print_packing_slip.tpl', true, 'A', $order_info['company_id'], $lang_code); if ($shipment_id != end($shipment_ids)) { echo "<div style='page-break-before: always;'> </div>"; } } } if ($pdf == true) { Pdf::render($html, __('shipments') . '-' . implode('-', $shipment_ids)); } return true; }