Esempio n. 1
0
/**
 * @param $variantNo integer
 */
function generateReport($variantNo)
{
    $inputExcelFilePath = genereteExcel($variantNo);
    $pdfFilePath = generatePdf($variantNo, $inputExcelFilePath);
    if (__DIR__ === substr($pdfFilePath, 0, strlen(__DIR__))) {
        $pdfRelativeFilePath = substr($pdfFilePath, strlen(__DIR__) + 1);
    } else {
        $pdfRelativeFilePath = $pdfFilePath;
    }
    return $pdfRelativeFilePath;
}
Esempio n. 2
0
 function save()
 {
     $db = JFactory::getDBO();
     $jshopConfig = JSFactory::getConfig();
     $post = JRequest::get('post');
     $client_id = JRequest::getInt('client_id', 0);
     $file_generete_pdf_order = $jshopConfig->file_generete_pdf_order;
     JPluginHelper::importPlugin('jshoppingadmin');
     $dispatcher = JDispatcher::getInstance();
     $order_id = intval($post['order_id']);
     $orders = $this->getModel("orders");
     $order = JTable::getInstance('order', 'jshop');
     $order->load($order_id);
     if (!$order_id) {
         $order->user_id = -1;
         $order->order_date = getJsDate();
         $orderNumber = $jshopConfig->next_order_number;
         $jshopConfig->updateNextOrderNumber();
         $order->order_number = $order->formatOrderNumber($orderNumber);
         $order->order_hash = md5(time() . $order->order_total . $order->user_id);
         $order->file_hash = md5(time() . $order->order_total . $order->user_id . "hashfile");
         $order->ip_address = $_SERVER['REMOTE_ADDR'];
         $order->order_status = $jshopConfig->default_status_order;
     }
     $order->order_m_date = getJsDate();
     $order_created_prev = $order->order_created;
     if ($post['birthday']) {
         $post['birthday'] = getJsDateDB($post['birthday'], $jshopConfig->field_birthday_format);
     }
     if ($post['d_birthday']) {
         $post['d_birthday'] = getJsDateDB($post['d_birthday'], $jshopConfig->field_birthday_format);
     }
     if ($post['invoice_date']) {
         $post['invoice_date'] = getJsDateDB($post['invoice_date'], $jshopConfig->store_date_format);
     }
     if (!$jshopConfig->hide_tax) {
         $post['order_tax'] = 0;
         $order_tax_ext = array();
         if (isset($post['tax_percent'])) {
             foreach ($post['tax_percent'] as $k => $v) {
                 if ($post['tax_percent'][$k] != "" || $post['tax_value'][$k] != "") {
                     $order_tax_ext[number_format($post['tax_percent'][$k], 2)] = $post['tax_value'][$k];
                 }
             }
         }
         $post['order_tax_ext'] = serialize($order_tax_ext);
         $post['order_tax'] = number_format(array_sum($order_tax_ext), 2);
     }
     $currency = JTable::getInstance('currency', 'jshop');
     $currency->load($post['currency_id']);
     $post['currency_code'] = $currency->currency_code;
     $post['currency_code_iso'] = $currency->currency_code_iso;
     $post['currency_exchange'] = $currency->currency_value;
     $dispatcher->trigger('onBeforeSaveOrder', array(&$post, &$file_generete_pdf_order));
     $order->bind($post);
     $order->store();
     $order_id = $order->order_id;
     $order_items = $order->getAllItems();
     $orders->saveOrderItem($order_id, $post, $order_items);
     JSFactory::loadLanguageFile($order->getLang());
     if ($jshopConfig->order_send_pdf_client || $jshopConfig->order_send_pdf_admin) {
         $order->load($order_id);
         $order->items = null;
         $order->products = $order->getAllItems();
         JSFactory::loadLanguageFile($order->getLang());
         $lang = JSFactory::getLang($order->getLang());
         $order->order_date = strftime($jshopConfig->store_date_format, strtotime($order->order_date));
         $order->order_tax_list = $order->getTaxExt();
         $country = JTable::getInstance('country', 'jshop');
         $country->load($order->country);
         $field_country_name = $lang->get("name");
         $order->country = $country->{$field_country_name};
         $d_country = JTable::getInstance('country', 'jshop');
         $d_country->load($order->d_country);
         $field_country_name = $lang->get("name");
         $order->d_country = $d_country->{$field_country_name};
         $shippingMethod = JTable::getInstance('shippingMethod', 'jshop');
         $shippingMethod->load($order->shipping_method_id);
         $pm_method = JTable::getInstance('paymentMethod', 'jshop');
         $pm_method->load($order->payment_method_id);
         $name = $lang->get("name");
         $description = $lang->get("description");
         $order->shipping_information = $shippingMethod->{$name};
         $order->payment_name = $pm_method->{$name};
         $order->payment_information = $order->payment_params;
         if ($jshopConfig->order_send_pdf_client || $jshopConfig->order_send_pdf_admin) {
             include_once $file_generete_pdf_order;
             $order->pdf_file = generatePdf($order);
             $order->insertPDF();
         }
     }
     if ($order->order_created == 1 && $order_created_prev == 0) {
         $order->items = null;
         JSFactory::loadLanguageFile($order->getLang());
         JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_jshopping/models');
         $checkout = JModelLegacy::getInstance('checkout', 'jshop');
         if ($jshopConfig->send_order_email) {
             $checkout->sendOrderEmail($order_id, 1);
         }
     }
     JSFactory::loadAdminLanguageFile();
     $dispatcher->trigger('onAfterSaveOrder', array(&$order, &$file_generete_pdf_order));
     $this->setRedirect("index.php?option=com_jshopping&controller=orders&client_id=" . $client_id);
 }
Esempio n. 3
0
 function sendOrderEmail($order_id, $manuallysend = 0)
 {
     $mainframe = JFactory::getApplication();
     $lang = JSFactory::getLang();
     $jshopConfig = JSFactory::getConfig();
     $db = JFactory::getDBO();
     $order = JSFactory::getTable('order', 'jshop');
     $jshopConfig->user_field_title[0] = '';
     $jshopConfig->user_field_client_type[0] = '';
     $file_generete_pdf_order = $jshopConfig->file_generete_pdf_order;
     $tmp_fields = $jshopConfig->getListFieldsRegister();
     $config_fields = $tmp_fields["address"];
     $count_filed_delivery = $jshopConfig->getEnableDeliveryFiledRegistration('address');
     $order->load($order_id);
     $status = JSFactory::getTable('orderStatus', 'jshop');
     $status->load($order->order_status);
     $name = $lang->get("name");
     $order->status = $status->{$name};
     $order->order_date = strftime($jshopConfig->store_date_format, strtotime($order->order_date));
     $order->products = $order->getAllItems();
     $order->weight = $order->getWeightItems();
     if ($jshopConfig->show_delivery_time_checkout) {
         $deliverytimes = JSFactory::getAllDeliveryTime();
         $order->order_delivery_time = $deliverytimes[$order->delivery_times_id];
         if ($order->order_delivery_time == "") {
             $order->order_delivery_time = $order->delivery_time;
         }
     }
     $order->order_tax_list = $order->getTaxExt();
     $show_percent_tax = 0;
     if (count($order->order_tax_list) > 1 || $jshopConfig->show_tax_in_product) {
         $show_percent_tax = 1;
     }
     if ($jshopConfig->hide_tax) {
         $show_percent_tax = 0;
     }
     $hide_subtotal = 0;
     if (($jshopConfig->hide_tax || count($order->order_tax_list) == 0) && $order->order_discount == 0 && $jshopConfig->without_shipping && $order->order_payment == 0) {
         $hide_subtotal = 1;
     }
     if ($order->weight == 0 && $jshopConfig->hide_weight_in_cart_weight0) {
         $jshopConfig->show_weight_order = 0;
     }
     $country = JSFactory::getTable('country', 'jshop');
     $country->load($order->country);
     $field_country_name = $lang->get("name");
     $order->country = $country->{$field_country_name};
     $d_country = JSFactory::getTable('country', 'jshop');
     $d_country->load($order->d_country);
     $field_country_name = $lang->get("name");
     $order->d_country = $d_country->{$field_country_name};
     if ($jshopConfig->show_delivery_date && !datenull($order->delivery_date)) {
         $order->delivery_date_f = formatdate($order->delivery_date);
     } else {
         $order->delivery_date_f = '';
     }
     $order->title = $jshopConfig->user_field_title[$order->title];
     $order->d_title = $jshopConfig->user_field_title[$order->d_title];
     $order->birthday = getDisplayDate($order->birthday, $jshopConfig->field_birthday_format);
     $order->d_birthday = getDisplayDate($order->d_birthday, $jshopConfig->field_birthday_format);
     $order->client_type_name = $jshopConfig->user_field_client_type[$order->client_type];
     $shippingMethod = JSFactory::getTable('shippingMethod', 'jshop');
     $shippingMethod->load($order->shipping_method_id);
     $pm_method = JSFactory::getTable('paymentMethod', 'jshop');
     $pm_method->load($order->payment_method_id);
     $paymentsysdata = $pm_method->getPaymentSystemData();
     $payment_system = $paymentsysdata->paymentSystem;
     $name = $lang->get("name");
     $description = $lang->get("description");
     $order->shipping_information = $shippingMethod->{$name};
     $shippingForm = $shippingMethod->getShippingForm();
     if ($shippingForm) {
         $shippingForm->prepareParamsDispayMail($order, $shippingMethod);
     }
     $order->payment_name = $pm_method->{$name};
     $order->payment_information = $order->payment_params;
     if ($payment_system) {
         $payment_system->prepareParamsDispayMail($order, $pm_method);
     }
     if ($pm_method->show_descr_in_email) {
         $order->payment_description = $pm_method->{$description};
     } else {
         $order->payment_description = "";
     }
     $statictext = JSFactory::getTable("statictext", "jshop");
     $rowstatictext = $statictext->loadData("order_email_descr");
     $order_email_descr = $rowstatictext->text;
     $order_email_descr = str_replace("{name}", $order->f_name, $order_email_descr);
     $order_email_descr = str_replace("{family}", $order->l_name, $order_email_descr);
     $order_email_descr = str_replace("{email}", $order->email, $order_email_descr);
     $order_email_descr = str_replace("{title}", $order->title, $order_email_descr);
     $rowstatictext = $statictext->loadData("order_email_descr_end");
     $order_email_descr_end = $rowstatictext->text;
     $order_email_descr_end = str_replace("{name}", $order->f_name, $order_email_descr_end);
     $order_email_descr_end = str_replace("{family}", $order->l_name, $order_email_descr_end);
     $order_email_descr_end = str_replace("{email}", $order->email, $order_email_descr_end);
     $order_email_descr_end = str_replace("{title}", $order->title, $order_email_descr_end);
     if ($jshopConfig->show_return_policy_text_in_email_order) {
         $list = $order->getReturnPolicy();
         $listtext = array();
         foreach ($list as $v) {
             $listtext[] = $v->text;
         }
         $rptext = implode('<div class="return_policy_space"></div>', $listtext);
         $order_email_descr_end = $rptext . $order_email_descr_end;
     }
     $text_total = _JSHOP_ENDTOTAL;
     if (($jshopConfig->show_tax_in_product || $jshopConfig->show_tax_product_in_cart) && count($order->order_tax_list) > 0) {
         $text_total = _JSHOP_ENDTOTAL_INKL_TAX;
     }
     $uri = JURI::getInstance();
     $liveurlhost = $uri->toString(array("scheme", 'host', 'port'));
     if ($jshopConfig->admin_show_vendors) {
         $listVendors = $order->getVendors();
     } else {
         $listVendors = array();
     }
     $vendors_send_message = $jshopConfig->vendor_order_message_type == 1;
     $vendor_send_order = $jshopConfig->vendor_order_message_type == 2;
     $vendor_send_order_admin = $jshopConfig->vendor_order_message_type == 2 && $order->vendor_type == 0 && $order->vendor_id || $jshopConfig->vendor_order_message_type == 3;
     if ($vendor_send_order_admin) {
         $vendor_send_order = 0;
     }
     $admin_send_order = 1;
     if ($jshopConfig->admin_not_send_email_order_vendor_order && $vendor_send_order_admin && count($listVendors)) {
         $admin_send_order = 0;
     }
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onBeforeSendEmailsOrder', array(&$order, &$listVendors, &$file_generete_pdf_order, &$admin_send_order));
     //client message
     include_once JPATH_COMPONENT_SITE . "/views/checkout/view.html.php";
     $view_name = "checkout";
     $view_config = array("template_path" => $jshopConfig->template_path . $jshopConfig->template . "/" . $view_name);
     $view = new JshoppingViewCheckout($view_config);
     $view->setLayout("orderemail");
     $view->assign('client', 1);
     $view->assign('show_customer_info', 1);
     $view->assign('show_weight_order', 1);
     $view->assign('show_total_info', 1);
     $view->assign('show_payment_shipping_info', 1);
     $view->assign('config_fields', $config_fields);
     $view->assign('count_filed_delivery', $count_filed_delivery);
     $view->assign('order_email_descr', $order_email_descr);
     $view->assign('order_email_descr_end', $order_email_descr_end);
     $view->assign('config', $jshopConfig);
     $view->assign('order', $order);
     $view->assign('products', $order->products);
     $view->assign('show_percent_tax', $show_percent_tax);
     $view->assign('hide_subtotal', $hide_subtotal);
     $view->assign('noimage', $jshopConfig->noimage);
     $view->assign('text_total', $text_total);
     $view->assign('liveurlhost', $liveurlhost);
     $dispatcher->trigger('onBeforeCreateTemplateOrderMail', array(&$view));
     $message_client = $view->loadTemplate();
     //admin message
     $view_name = "checkout";
     $view_config = array("template_path" => $jshopConfig->template_path . $jshopConfig->template . "/" . $view_name);
     $view = new JshoppingViewCheckout($view_config);
     $view->setLayout("orderemail");
     $view->assign('client', 0);
     $view->assign('show_customer_info', 1);
     $view->assign('show_weight_order', 1);
     $view->assign('show_total_info', 1);
     $view->assign('show_payment_shipping_info', 1);
     $view->assign('config_fields', $config_fields);
     $view->assign('count_filed_delivery', $count_filed_delivery);
     $view->assign('order_email_descr', $order_email_descr);
     $view->assign('order_email_descr_end', $order_email_descr_end);
     $view->assign('config', $jshopConfig);
     $view->assign('order', $order);
     $view->assign('products', $order->products);
     $view->assign('show_percent_tax', $show_percent_tax);
     $view->assign('hide_subtotal', $hide_subtotal);
     $view->assign('noimage', $jshopConfig->noimage);
     $view->assign('text_total', $text_total);
     $view->assign('liveurlhost', $liveurlhost);
     $dispatcher->trigger('onBeforeCreateTemplateOrderMail', array(&$view));
     $message_admin = $view->loadTemplate();
     //vendors messages or order
     if ($vendors_send_message || $vendor_send_order) {
         foreach ($listVendors as $k => $datavendor) {
             if ($vendors_send_message) {
                 $show_customer_info = 0;
                 $show_weight_order = 0;
                 $show_total_info = 0;
                 $show_payment_shipping_info = 0;
             }
             if ($vendor_send_order) {
                 $show_customer_info = 1;
                 $show_weight_order = 0;
                 $show_total_info = 0;
                 $show_payment_shipping_info = 1;
             }
             $vendor_order_items = $order->getVendorItems($datavendor->id);
             $view_name = "checkout";
             $view_config = array("template_path" => $jshopConfig->template_path . $jshopConfig->template . "/" . $view_name);
             $view = new JshoppingViewCheckout($view_config);
             $view->setLayout("orderemail");
             $view->assign('client', 0);
             $view->assign('show_customer_info', $show_customer_info);
             $view->assign('show_weight_order', $show_weight_order);
             $view->assign('show_total_info', $show_total_info);
             $view->assign('show_payment_shipping_info', $show_payment_shipping_info);
             $view->assign('config_fields', $config_fields);
             $view->assign('count_filed_delivery', $count_filed_delivery);
             $view->assign('order_email_descr', $order_email_descr);
             $view->assign('order_email_descr_end', $order_email_descr_end);
             $view->assign('config', $jshopConfig);
             $view->assign('order', $order);
             $view->assign('products', $vendor_order_items);
             $view->assign('show_percent_tax', $show_percent_tax);
             $view->assign('hide_subtotal', $hide_subtotal);
             $view->assign('noimage', $jshopConfig->noimage);
             $view->assign('text_total', $text_total);
             $view->assign('liveurlhost', $liveurlhost);
             $view->assign('show_customer_info', $vendor_send_order);
             $dispatcher->trigger('onBeforeCreateTemplateOrderPartMail', array(&$view));
             $message_vendor = $view->loadTemplate();
             $listVendors[$k]->message = $message_vendor;
         }
     }
     $pdfsend = 1;
     if ($jshopConfig->send_invoice_manually && !$manuallysend) {
         $pdfsend = 0;
     }
     if ($pdfsend && ($jshopConfig->order_send_pdf_client || $jshopConfig->order_send_pdf_admin)) {
         include_once $file_generete_pdf_order;
         $order->setInvoiceDate();
         $order->pdf_file = generatePdf($order, $jshopConfig);
         $order->insertPDF();
     }
     $mailfrom = $mainframe->getCfg('mailfrom');
     $fromname = $mainframe->getCfg('fromname');
     //send mail client
     if ($order->email) {
         $mailer = JFactory::getMailer();
         $mailer->setSender(array($mailfrom, $fromname));
         $mailer->addRecipient($order->email);
         $mailer->setSubject(sprintf(_JSHOP_NEW_ORDER, $order->order_number, $order->f_name . " " . $order->l_name));
         $mailer->setBody($message_client);
         if ($pdfsend && $jshopConfig->order_send_pdf_client) {
             $mailer->addAttachment($jshopConfig->pdf_orders_path . "/" . $order->pdf_file);
         }
         $mailer->isHTML(true);
         $dispatcher->trigger('onBeforeSendOrderEmailClient', array(&$mailer, &$order, &$manuallysend, &$pdfsend));
         $send = $mailer->Send();
     }
     //send mail admin
     if ($admin_send_order) {
         $mailer = JFactory::getMailer();
         $mailer->setSender(array($mailfrom, $fromname));
         $mailer->addRecipient(explode(',', $jshopConfig->contact_email));
         $mailer->setSubject(sprintf(_JSHOP_NEW_ORDER, $order->order_number, $order->f_name . " " . $order->l_name));
         $mailer->setBody($message_admin);
         if ($pdfsend && $jshopConfig->order_send_pdf_admin) {
             $mailer->addAttachment($jshopConfig->pdf_orders_path . "/" . $order->pdf_file);
         }
         $mailer->isHTML(true);
         $dispatcher->trigger('onBeforeSendOrderEmailAdmin', array(&$mailer, &$order, &$manuallysend, &$pdfsend));
         $send = $mailer->Send();
     }
     //send mail vendors
     if ($vendors_send_message || $vendor_send_order) {
         foreach ($listVendors as $k => $vendor) {
             $mailer = JFactory::getMailer();
             $mailer->setSender(array($mailfrom, $fromname));
             $mailer->addRecipient($vendor->email);
             $mailer->setSubject(sprintf(_JSHOP_NEW_ORDER_V, $order->order_number, ""));
             $mailer->setBody($vendor->message);
             $mailer->isHTML(true);
             $dispatcher->trigger('onBeforeSendOrderEmailVendor', array(&$mailer, &$order, &$manuallysend, &$pdfsend, &$vendor, &$vendors_send_message, &$vendor_send_order));
             $send = $mailer->Send();
         }
     }
     //vendor send order
     if ($vendor_send_order_admin) {
         foreach ($listVendors as $k => $vendor) {
             $mailer = JFactory::getMailer();
             $mailer->setSender(array($mailfrom, $fromname));
             $mailer->addRecipient($vendor->email);
             $mailer->setSubject(sprintf(_JSHOP_NEW_ORDER, $order->order_number, $order->f_name . " " . $order->l_name));
             $mailer->setBody($message_admin);
             if ($pdfsend && $jshopConfig->order_send_pdf_admin) {
                 $mailer->addAttachment($jshopConfig->pdf_orders_path . "/" . $order->pdf_file);
             }
             $mailer->isHTML(true);
             $dispatcher->trigger('onBeforeSendOrderEmailVendorOrder', array(&$mailer, &$order, &$manuallysend, &$pdfsend, &$vendor, &$vendors_send_message, &$vendor_send_order));
             $send = $mailer->Send();
         }
     }
     $dispatcher->trigger('onAfterSendEmailsOrder', array(&$order));
 }
Esempio n. 4
0
 function preview_pdf()
 {
     $dispatcher = JDispatcher::getInstance();
     $jshopConfig = JSFactory::getConfig();
     $jshopConfig->currency_code = "USD";
     $file_generete_pdf_order = $jshopConfig->file_generete_pdf_order;
     $order = JSFactory::getTable('order', 'jshop');
     $order->firma_name = "Firma";
     $order->f_name = "Fname";
     $order->l_name = 'Lname';
     $order->street = 'Street';
     $order->zip = "Zip";
     $order->city = "City";
     $order->country = "Country";
     $order->order_number = outputDigit(0, 8);
     $order->order_date = strftime($jshopConfig->store_date_format, time());
     $order->products = array();
     $prod = new stdClass();
     $prod->product_name = "Product name";
     $prod->product_ean = "12345678";
     $prod->product_quantity = 1;
     $prod->product_item_price = 125;
     $prod->product_tax = 19;
     $order->products[] = $prod;
     $order->order_subtotal = 125;
     $order->order_shipping = 20;
     $display_price = $jshopConfig->display_price_front;
     if ($display_price == 0) {
         $order->display_price = 0;
         $order->order_tax_list = array(19 => 23.15);
         $order->order_total = 145;
     } else {
         $order->display_price = 1;
         $order->order_tax_list = array(19 => 27.55);
         $order->order_total = 172.55;
     }
     $dispatcher->trigger('onBeforeCreateDemoPreviewPdf', array(&$order, &$file_generete_pdf_order));
     require_once $file_generete_pdf_order;
     $order->pdf_file = generatePdf($order, $jshopConfig);
     header("Location: " . $jshopConfig->pdf_orders_live_path . "/" . $order->pdf_file);
     die;
 }
Esempio n. 5
0
 function generatePdf($file_generete_pdf_order)
 {
     include_once $file_generete_pdf_order;
     $this->setInvoiceDate();
     $this->pdf_file = generatePdf($this);
     $this->insertPDF();
     return $this->pdf_file;
 }
Esempio n. 6
0
    function _sendOrderEmail($order_id){
        $mainframe =& JFactory::getApplication();        
        
        $lang = &JSFactory::getLang();
        $jshopConfig = &JSFactory::getConfig();
        $db = &JFactory::getDBO();
        $order = &JTable::getInstance('order', 'jshop');
        
        $tmp_fields = $jshopConfig->getListFieldsRegister();
        $config_fields = $tmp_fields["address"];
        $count_filed_delivery = 0;
        foreach($config_fields as $k=>$v){
            if (substr($k, 0, 2)=="d_" && $v['display']==1) $count_filed_delivery++;
        }
        
        $order->load($order_id);
        
        $status = &JTable::getInstance('orderStatus', 'jshop');
        $status->load($order->order_status);
        $name = $lang->get("name");
        $order->status = $status->$name;
        $order->order_date = strftime($jshopConfig->store_date_format, strtotime($order->order_date));
        $order->products = $order->getAllItems();
        $order->weight = $order->getWeightItems();        
        $order->order_tax_list = $order->getTaxExt();
        $show_percent_tax = 0;        
        if (count($order->order_tax_list)>1 || $jshopConfig->show_tax_in_product) $show_percent_tax = 1;        
        if ($jshopConfig->hide_tax) $show_percent_tax = 0;
        $hide_subtotal = 0;
        if (($jshopConfig->hide_tax || count($order->order_tax_list)==0) && $order->order_discount==0 && $jshopConfig->without_shipping && $order->order_payment==0) $hide_subtotal = 1;
        
        $country = &JTable::getInstance('country', 'jshop');
        $country->load($order->country);
        $field_country_name = $lang->get("name");
        $order->country = $country->$field_country_name;        
        
        $d_country = &JTable::getInstance('country', 'jshop');
        $d_country->load($order->d_country);
        $field_country_name = $lang->get("name");
        $order->d_country = $d_country->$field_country_name;

        $shippingMethod = &JTable::getInstance('shippingMethod', 'jshop');
        $shippingMethod->load($order->shipping_method_id);
        
        $pm_method = &JTable::getInstance('paymentMethod', 'jshop');
        $pm_method->load($order->payment_method_id);
        
        $name = $lang->get("name");
        $description = $lang->get("description");
        $order->shipping_information = $shippingMethod->$name;
        $order->payment_name = $pm_method->$name;
        $order->payment_information = $order->payment_params;
        if ($pm_method->show_descr_in_email) $order->payment_description = $pm_method->$description;  else $order->payment_description = "";

        $statictext = &JTable::getInstance("statictext","jshop");
        $rowstatictext = $statictext->loadData("order_email_descr");        
        $order_email_descr = $rowstatictext->text;
        $order_email_descr = str_replace("{name}",$order->f_name, $order_email_descr);
        $order_email_descr = str_replace("{family}",$order->l_name, $order_email_descr);
        $order_email_descr = str_replace("{email}",$order->email, $order_email_descr);
                
        $text_total = _JSHOP_ENDTOTAL;
        if (($jshopConfig->show_tax_in_product || $jshopConfig->show_tax_product_in_cart) && (count($order->order_tax_list)>0)){
            $text_total = _JSHOP_ENDTOTAL_INKL_TAX;
        }
        
        $uri =& JURI::getInstance();        
        $liveurlhost = $uri->toString( array("scheme",'host', 'port'));
        
        $vendors_send_message = ($jshopConfig->vendor_order_message_type==1 || ($order->vendor_type==1 && $jshopConfig->vendor_order_message_type==2));
        $vendor_send_order = ($jshopConfig->vendor_order_message_type==2 && $order->vendor_type == 0 && $order->vendor_id);
        $admin_send_order = 1;
        if ($jshopConfig->admin_not_send_email_order_vendor_order && $vendor_send_order) $admin_send_order = 0;
        
        JPluginHelper::importPlugin('jshoppingorder');
        $dispatcher =& JDispatcher::getInstance();
        $dispatcher->trigger( 'onBeforeSendEmailsOrder', array(&$order) );
        
        //client message
        $client = 1;
        $view_name = "checkout";
        $view_config = array("template_path"=>JPATH_COMPONENT."/templates/".$jshopConfig->template."/".$view_name);
        $view = &$this->getView($view_name, 'html', '', $view_config);
        $view->setLayout("orderemail");
        $view->assign('client', $client);
        $view->assign('config_fields', $config_fields);
        $view->assign('count_filed_delivery', $count_filed_delivery);
        $view->assign('order_email_descr', $order_email_descr);
        $view->assign('config', $jshopConfig);
        $view->assign('order', $order);
        $view->assign('show_percent_tax', $show_percent_tax);
        $view->assign('hide_subtotal', $hide_subtotal);
        $view->assign('noimage',"noimage.gif");
        $view->assign('text_total',$text_total);
        $view->assign('liveurlhost',$liveurlhost);
        $message_client = $view->loadTemplate();
        
        //admin message
        $client = 0;
        $view_name = "checkout";
        $view_config = array("template_path"=>JPATH_COMPONENT."/templates/".$jshopConfig->template."/".$view_name);
        $view = &$this->getView($view_name, 'html', '', $view_config);
        $view->setLayout("orderemail");
        $view->assign('client', $client);
        $view->assign('config_fields', $config_fields);
        $view->assign('count_filed_delivery', $count_filed_delivery);
        $view->assign('config', $jshopConfig);
        $view->assign('order',$order);
        $view->assign('show_percent_tax', $show_percent_tax);
        $view->assign('hide_subtotal', $hide_subtotal);
        $view->assign('noimage',"noimage.gif");
        $view->assign('text_total',$text_total);
        $view->assign('liveurlhost',$liveurlhost);
        $message_admin = $view->loadTemplate();
        
        //vendors messages        
        if ($vendors_send_message){            
            $listVendors = $order->getVendors();            
            foreach($listVendors as $k=>$datavendor){
                $vendor_order_items = $order->getVendorItems($datavendor->id);
                $client = 0;
                $view_name = "checkout";
                $view_config = array("template_path"=>JPATH_COMPONENT."/templates/".$jshopConfig->template."/".$view_name);
                $view = &$this->getView($view_name, 'html', '', $view_config);
                $view->setLayout("orderemailpart");
                $view->assign('client', $client);
                $view->assign('config_fields', $config_fields);
                $view->assign('count_filed_delivery', $count_filed_delivery);
                $view->assign('config', $jshopConfig);
                $view->assign('order',$order);
                $view->assign('products', $vendor_order_items);
                $view->assign('show_percent_tax', $show_percent_tax);
                $view->assign('hide_subtotal', $hide_subtotal);
                $view->assign('noimage',"noimage.gif");
                $view->assign('text_total',$text_total);
                $view->assign('liveurlhost',$liveurlhost);
                $message_vendor = $view->loadTemplate();
                $listVendors[$k]->message = $message_vendor;
            }
        }
        
        if ($jshopConfig->order_send_pdf_client || $jshopConfig->order_send_pdf_admin){
            include_once(JPATH_SITE . "/components/com_jshopping/lib/generete_pdf_order.php");
            $order->pdf_file = generatePdf($order, $jshopConfig);
            $order->insertPDF();
        }
        
        $mailfrom = $mainframe->getCfg( 'mailfrom' );
        $fromname = $mainframe->getCfg( 'fromname' );
        
        //send mail client
        $mailer =& JFactory::getMailer();
        $mailer->setSender(array($mailfrom, $fromname));
        $mailer->addRecipient($order->email);
        $mailer->setSubject( sprintf(_JSHOP_NEW_ORDER, $order->order_number, $order->f_name." ".$order->l_name));
        $mailer->setBody($message_client);
        if ($jshopConfig->order_send_pdf_client){
            $mailer->addAttachment($jshopConfig->pdf_orders_path."/".$order->pdf_file);
        }
        $mailer->isHTML(true);
        $send =& $mailer->Send();
        
        //send mail admin        
        if ($admin_send_order){
            $mailer =& JFactory::getMailer();
            $mailer->setSender(array($mailfrom, $fromname));
            $mailer->addRecipient($jshopConfig->contact_email);
            $mailer->setSubject( sprintf(_JSHOP_NEW_ORDER, $order->order_number, $order->f_name." ".$order->l_name));
            $mailer->setBody($message_admin);
            if ($jshopConfig->order_send_pdf_admin){
                $mailer->addAttachment($jshopConfig->pdf_orders_path."/".$order->pdf_file);
            }
            $mailer->isHTML(true);
            $send =& $mailer->Send();
        }
        
        //send mail vendors
        if ($vendors_send_message){
            foreach($listVendors as $k=>$vendor){
                $mailer =& JFactory::getMailer();
                $mailer->setSender(array($mailfrom, $fromname));
                $mailer->addRecipient($vendor->email);
                $mailer->setSubject( sprintf(_JSHOP_NEW_ORDER_V, $order->order_number, ""));
                $mailer->setBody($vendor->message);                
                $mailer->isHTML(true);
                $send =& $mailer->Send();
            }            
        }
        
        //vendor send order
        if ($vendor_send_order){
            $vendor = &JTable::getInstance('vendor', 'jshop');
            $vendor->load($order->vendor_id);
            $mailer =& JFactory::getMailer();
            $mailer->setSender(array($mailfrom, $fromname));
            $mailer->addRecipient($vendor->email);
            $mailer->setSubject( sprintf(_JSHOP_NEW_ORDER, $order->order_number, $order->f_name." ".$order->l_name));
            $mailer->setBody($message_admin);
            if ($jshopConfig->order_send_pdf_admin){
                $mailer->addAttachment($jshopConfig->pdf_orders_path."/".$order->pdf_file);
            }
            $mailer->isHTML(true);
            $send =& $mailer->Send();            
        }
                
        $dispatcher->trigger( 'onAfterSendEmailsOrder', array(&$order) );
        
    }
Esempio n. 7
0
    function save(){
        $jshopConfig = &JSFactory::getConfig();
        $post = JRequest::get('post');
        $order = &JTable::getInstance('order', 'jshop');
        $order_id = $post['order_id'];
        $db = &JFactory::getDBO();
        JPluginHelper::importPlugin('jshoppingadmin');
        $dispatcher =& JDispatcher::getInstance();
        
        $n = JRequest::getVar('amount_tax_items');        
        $a = null;
        if (!$jshopConfig->hide_tax){
            $post['order_tax'] = 0;
            for($i = 1; $i<=$n; $i++) {
                $a[number_format(JRequest::getVar('tax_percent_'.$i,''),2)] = JRequest::getVar('tax_value_'.$i,'');     
                $post['order_tax'] += JRequest::getVar('tax_value_'.$i,'');   
            } 
            $post['order_tax_ext'] = serialize($a);
            $post['order_tax'] = number_format($post['order_tax'],2);  
        }
        
        $dispatcher->trigger( 'onBeforeSaveOrder', array(&$post) );
        
        $k = JRequest::getVar('amount_order_items');
        if ($k){
            for($i = 1; $i<=$k; $i++) {
                $product_name       = JRequest::getVar('product_name_'.$i,'');
                $product_ean        = JRequest::getVar('product_ean_'.$i,'');
                $product_item_price = JRequest::getVar('product_item_price_'.$i,0);
                $product_quantity   = JRequest::getVar('product_quantity_'.$i,0);
                $order_item_id   = JRequest::getVar('order_item_id_'.$i); 
                $query = 'UPDATE #__jshopping_order_item SET `product_name`="'.$product_name.'",`product_ean`="'.$product_ean.'",`product_item_price`="'.$product_item_price.'",`product_quantity`="'.$product_quantity.'" WHERE `order_id`='.$order_id.' AND `order_item_id`='.$order_item_id;          
                $db->setQuery($query);
                $db->query();    
            }
        }

        if (!$order->bind($post)) {
            JError::raiseWarning("",_JSHOP_ERROR_BIND);
            $this->setRedirect("index.php?option=com_jshopping&controller=orders");
        }

        if (!$order->store()) {
            JError::raiseWarning("",_JSHOP_ERROR_SAVE_DATABASE);
            $this->setRedirect("index.php?option=com_jshopping&controller=orders");
        }    
        
        if ($jshopConfig->order_send_pdf_client || $jshopConfig->order_send_pdf_admin){
            $order->load($post['order_id']);
            $order->products = $order->getAllItems();
            JSFactory::loadLanguageFile($order->getLang());
            $lang = &JSFactory::getLang($order->getLang());
            
            $order->order_date = strftime($jshopConfig->store_date_format, strtotime($order->order_date));
            $order->order_tax_list = $order->getTaxExt();
            $country = &JTable::getInstance('country', 'jshop');
            $country->load($order->country);
            $field_country_name = $lang->get("name");
            $order->country = $country->$field_country_name;        
            
            $d_country = &JTable::getInstance('country', 'jshop');
            $d_country->load($order->d_country);
            $field_country_name = $lang->get("name");
            $order->d_country = $d_country->$field_country_name;

            $shippingMethod = &JTable::getInstance('shippingMethod', 'jshop');
            $shippingMethod->load($order->shipping_method_id);
            
            $pm_method = &JTable::getInstance('paymentMethod', 'jshop');
            $pm_method->load($order->payment_method_id);
            
            $name = $lang->get("name");
            $description = $lang->get("description");
            $order->shipping_information = $shippingMethod->$name;
            $order->payment_name = $pm_method->$name;
            $order->payment_information = $order->payment_params;
            
            include_once(JPATH_SITE . "/components/com_jshopping/lib/generete_pdf_order.php");
            $order->pdf_file = generatePdf($order);
            $order->insertPDF();
        }
        
        $dispatcher->trigger( 'onAfterSaveOrder', array(&$order) );
        
        $this->setRedirect("index.php?option=com_jshopping&controller=orders");       
    }