Esempio n. 1
0
# ------------------------------------------------------------------------
# author    Ramesh Elamathi - Weblogicx India http://www.weblogicxindia.com
# copyright Copyright (C) 2014 - 19 Weblogicxindia.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://j2store.org
# Technical Support:  Forum - http://j2store.org/forum/index.html
-------------------------------------------------------------------------*/
//no direct access
defined('_JEXEC') or die('Restricted access');
/**
 * Get the document.
 */
$document = JFactory::getDocument();
$document->addScript(JUri::root() . 'administrator/modules/mod_j2store_chart/media/chart_api.js');
require_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/base.php';
$currency = J2StoreFactory::getCurrencyObject();
//chart script.
$script = '
 google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);

         function drawChart() {

        //year chart axis.

        var yearchart = google.visualization.arrayToDataTable([

         ["' . JText::_("J2STORE_YEAR") . '","' . JText::_("J2STORE_AMOUNT") . '"],

         ';
/**
Esempio n. 2
0
 /**
  * Method to get rates from the USPS shipping API
  *
  * @param array $address
  * @return array rates array
  */
 private function getRates($address)
 {
     $rates = array();
     $status = true;
     $shipping_status = false;
     //first check if shippable items are in cart
     JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_j2store/models');
     $model = JModelLegacy::getInstance('Mycart', 'J2StoreModel');
     $products = $model->getDataNew();
     foreach ($products as $product) {
         if ($product['shipping']) {
             $shipping_status = true;
         }
     }
     if ($shipping_status === false) {
         return $rates;
     }
     $currencyObject = J2StoreFactory::getCurrencyObject();
     $store_address = J2StoreHelperCart::getStoreAddress();
     $domestic_services = $this->params->get('domestic_services');
     $inernational_services = $this->params->get('international_services');
     $quote_data = array();
     $method_data = array();
     $cart_weight_total = J2StoreHelperCart::getWeight();
     $weightObject = J2StoreFactory::getWeightObject();
     $weight = $weightObject->convert($cart_weight_total, $store_address->config_weight_class_id, $this->params->get('usps_weight_class_id'));
     $weight = $weight < 0.1 ? 0.1 : $weight;
     $pounds = floor($weight);
     $ounces = round(16 * ($weight - $pounds), 2);
     // max 5 digits
     $postcode = str_replace(' ', '', $address['postal_code']);
     //get country data
     $countryObject = $this->getCountry($address['country_id']);
     if ($countryObject->country_isocode_2 == 'US') {
         $xml = '<RateV4Request USERID="' . $this->usps_username . '">';
         $xml .= '	<Package ID="1">';
         $xml .= '		<Service>ALL</Service>';
         $xml .= '		<ZipOrigination>' . substr($this->params->get('usps_postcode'), 0, 5) . '</ZipOrigination>';
         $xml .= '		<ZipDestination>' . substr($postcode, 0, 5) . '</ZipDestination>';
         $xml .= '		<Pounds>' . $pounds . '</Pounds>';
         $xml .= '		<Ounces>' . $ounces . '</Ounces>';
         // Prevent common size mismatch error from USPS (Size cannot be Regular if Container is Rectangular for some reason)
         if ($this->params->get('usps_container') == 'RECTANGULAR' && $this->params->get('usps_size') == 'REGULAR') {
             $this->params->set('usps_container', 'VARIABLE');
         }
         $xml .= '		<Container>' . $this->params->get('usps_container') . '</Container>';
         $xml .= '		<Size>' . $this->params->get('usps_size') . '</Size>';
         $xml .= '		<Width>' . $this->params->get('usps_width') . '</Width>';
         $xml .= '		<Length>' . $this->params->get('usps_length') . '</Length>';
         $xml .= '		<Height>' . $this->params->get('usps_height') . '</Height>';
         // Calculate girth based on usps calculation
         $xml .= '		<Girth>' . round((double) $this->params->get('usps_length') + (double) $this->params->get('usps_width') * 2 + (double) $this->params->get('usps_height') * 2, 1) . '</Girth>';
         $xml .= '		<Machinable>' . ($this->params->get('usps_machinable') ? 'true' : 'false') . '</Machinable>';
         $xml .= '	</Package>';
         $xml .= '</RateV4Request>';
         $request = 'API=RateV4&XML=' . urlencode($xml);
     } else {
         $countries = $this->getCountries();
         if (isset($countries[$countryObject->country_isocode_2])) {
             $xml = '<IntlRateV2Request USERID="' . $this->usps_username . '">';
             $xml .= '	<Package ID="1">';
             $xml .= '		<Pounds>' . $pounds . '</Pounds>';
             $xml .= '		<Ounces>' . $ounces . '</Ounces>';
             $xml .= '		<MailType>All</MailType>';
             $xml .= '		<GXG>';
             $xml .= '		  <POBoxFlag>N</POBoxFlag>';
             $xml .= '		  <GiftFlag>N</GiftFlag>';
             $xml .= '		</GXG>';
             $xml .= '		<ValueOfContents>' . J2StoreHelperCart::getSubTotal() . '</ValueOfContents>';
             $xml .= '		<Country>' . $countries[$countryObject->country_isocode_2] . '</Country>';
             // Intl only supports RECT and NONRECT
             if ($this->params->get('usps_container') == 'VARIABLE') {
                 $this->params->set('usps_container', 'NONRECTANGULAR');
             }
             $xml .= '		<Container>' . $this->params->get('usps_container') . '</Container>';
             $xml .= '		<Size>' . $this->params->get('usps_size') . '</Size>';
             $xml .= '		<Width>' . $this->params->get('usps_width') . '</Width>';
             $xml .= '		<Length>' . $this->params->get('usps_length') . '</Length>';
             $xml .= '		<Height>' . $this->params->get('usps_height') . '</Height>';
             $xml .= '		<Girth>' . $this->params->get('usps_girth') . '</Girth>';
             $xml .= '		<CommercialFlag>N</CommercialFlag>';
             $xml .= '	</Package>';
             $xml .= '</IntlRateV2Request>';
             $request = 'API=IntlRateV2&XML=' . urlencode($xml);
         } else {
             $status = false;
         }
     }
     if ($status) {
         $result = $this->_sendRequest($request);
         $handling = $this->params->get('handling', '0');
         if ($result) {
             if ($this->params->get('show_debug')) {
                 $this->_log("USPS DATA SENT: " . urldecode($request));
                 $this->_log("USPS DATA RECV: " . $result);
             }
             $dom = new DOMDocument('1.0', 'UTF-8');
             $dom->loadXml($result);
             $rate_response = $dom->getElementsByTagName('RateV4Response')->item(0);
             $intl_rate_response = $dom->getElementsByTagName('IntlRateV2Response')->item(0);
             $error = $dom->getElementsByTagName('Error')->item(0);
             $firstclasses = array('First-Class Mail Parcel', 'First-Class Mail Large Envelope', 'First-Class Mail Letter', 'First-Class Mail Postcards');
             if ($rate_response || $intl_rate_response) {
                 if ($countryObject->country_isocode_2 == 'US') {
                     $allowed = array(0, 1, 2, 3, 4, 5, 6, 7, 12, 13, 16, 17, 18, 19, 22, 23, 25, 27, 28, 30, 31, 55, 56, 62, 63);
                     $package = $rate_response->getElementsByTagName('Package')->item(0);
                     $postages = $package->getElementsByTagName('Postage');
                     if ($postages->length) {
                         foreach ($postages as $postage) {
                             $classid = $postage->getAttribute('CLASSID');
                             if (in_array($classid, $allowed)) {
                                 if ($classid == '0') {
                                     $mailservice = $postage->getElementsByTagName('MailService')->item(0)->nodeValue;
                                     foreach ($firstclasses as $k => $firstclass) {
                                         if ($firstclass == $mailservice) {
                                             $classid = $classid . $k;
                                             break;
                                         }
                                     }
                                     if (in_array('usps_domestic_' . $classid, $domestic_services)) {
                                         $cost = $postage->getElementsByTagName('Rate')->item(0)->nodeValue;
                                         $price = $currencyObject->convert($cost, 'USD', $store_address->config_currency);
                                         $rate = array();
                                         $rate['name'] = $postage->getElementsByTagName('MailService')->item(0)->nodeValue;
                                         $rate['code'] = 'usps.' . $classid;
                                         $rate['price'] = $price;
                                         $rate['extra'] = (double) $handling;
                                         $rate['total'] = $price;
                                         $rate['tax'] = "0.00";
                                         $rate['element'] = $this->_element;
                                         $rates[] = $rate;
                                     }
                                 } elseif (in_array('usps_domestic_' . $classid, $domestic_services)) {
                                     $cost = $postage->getElementsByTagName('Rate')->item(0)->nodeValue;
                                     $price = $currencyObject->convert($cost, 'USD', $store_address->config_currency);
                                     $rate = array();
                                     $rate['name'] = $postage->getElementsByTagName('MailService')->item(0)->nodeValue;
                                     $rate['code'] = 'usps.' . $classid;
                                     $rate['price'] = $price;
                                     $rate['extra'] = (double) $handling;
                                     $rate['total'] = $price;
                                     $rate['tax'] = "0.00";
                                     $rate['element'] = $this->_element;
                                     $rates[] = $rate;
                                 }
                             }
                         }
                     } else {
                         $error = $package->getElementsByTagName('Error')->item(0);
                         $method_data = array('code' => 'usps', 'title' => JText::_('usps_error_text'), 'quote' => $quote_data, 'error' => $error->getElementsByTagName('Description')->item(0)->nodeValue);
                     }
                 } else {
                     $allowed = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27);
                     $package = $intl_rate_response->getElementsByTagName('Package')->item(0);
                     $services = $package->getElementsByTagName('Service');
                     if (isset($inernational_services) && !empty($inernational_services)) {
                         foreach ($services as $service) {
                             $id = $service->getAttribute('ID');
                             if (in_array($id, $allowed) && in_array('usps_international_' . $id, $inernational_services)) {
                                 $title = $service->getElementsByTagName('SvcDescription')->item(0)->nodeValue;
                                 if ($this->params->get('usps_display_time')) {
                                     $title .= ' (' . JText::_('usps_text_eta') . ' ' . $service->getElementsByTagName('SvcCommitments')->item(0)->nodeValue . ')';
                                 }
                                 $cost = $service->getElementsByTagName('Postage')->item(0)->nodeValue;
                                 $price = $currencyObject->convert($cost, 'USD', $store_address->config_currency);
                                 $rate = array();
                                 $rate['name'] = $title;
                                 $rate['code'] = 'usps.' . $id;
                                 $rate['price'] = $price;
                                 $rate['extra'] = (double) $handling;
                                 $rate['total'] = $price;
                                 $rate['tax'] = "0.00";
                                 $rate['element'] = $this->_element;
                                 $rates[] = $rate;
                             }
                         }
                     }
                 }
             } elseif ($error) {
                 $method_data = array('code' => 'usps', 'title' => JText::_('usps_error_text'), 'quote' => $quote_data, 'error' => $error->getElementsByTagName('Description')->item(0)->nodeValue);
             }
         }
     }
     if (count($rates)) {
         //if the shipping is taxable, calculate it here.
         $tax_class_id = $this->params->get('usps_tax_class_id', '');
         if ($tax_class_id) {
             $j2tax = new J2StoreTax();
             $newRates = array();
             foreach ($rates as $rate) {
                 $newRate = array();
                 $newRate['name'] = JText::_($rate['name']);
                 $newRate['code'] = $rate['code'];
                 $newRate['price'] = $rate['price'];
                 $newRate['extra'] = $rate['extra'];
                 $shipping_method_tax_total = $j2tax->getTax($newRate['price'] + $newRate['extra'], $tax_class_id);
                 $newRate['tax'] = round($shipping_method_tax_total, 2);
                 $newRate['total'] = $rate['total'] + $newRate['tax'];
                 $newRate['element'] = $rate['element'];
                 $newRates[] = $newRate;
             }
             unset($rates);
             $rates = $newRates;
         }
     }
     return $rates;
 }
Esempio n. 3
0
 function getAmount($value, $currency_code, $currency_value, $convert = false)
 {
     if (version_compare($this->_j2version, '2.6.7', 'lt')) {
         return J2StoreUtilities::number($value, array('thousands' => '', 'num_decimals' => '2', 'decimal' => '.'));
     } else {
         include_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/base.php';
         $currencyObject = J2StoreFactory::getCurrencyObject();
         $amount = $currencyObject->format($value, $currency_code, $currency_value, false);
         return $amount;
     }
 }
Esempio n. 4
0
 public static function number($amount, $currency = '', $value = '', $format = true)
 {
     if ($value == 0) {
         $value = '';
     }
     //backward compatibility
     if (is_array($currency)) {
         $currency = '';
     }
     $currencyobject = J2StoreFactory::getCurrencyObject();
     return $currencyobject->format($amount, $currency, $value, $format);
 }
 function getCurrency($order)
 {
     $results = array();
     $convert = false;
     $params = JComponentHelper::getParams('com_j2store');
     if (version_compare($this->_j2version, '2.6.7', 'lt')) {
         $currency_code = $params->get('currency_code', 'USD');
         $currency_value = 1;
     } else {
         include_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/base.php';
         $currencyObject = J2StoreFactory::getCurrencyObject();
         $currency_code = $order->currency_code;
         $currency_value = $order->currency_value;
         // accepted currencies
         $currencies = $this->getAcceptedCurrencies();
         if (!in_array($order->currency_code, $currencies)) {
             $default_currency = 'USD';
             if ($currencyObject->has($default_currency)) {
                 $currencyObject->set($default_currency);
                 $currency_code = $default_currency;
                 $currency_value = $currencyObject->getValue($default_currency);
                 $convert = true;
             }
         }
     }
     $results['currency_code'] = $currency_code;
     $results['currency_value'] = $currency_value;
     $results['convert'] = $convert;
     return $results;
 }
Esempio n. 6
0
 function view()
 {
     // initialise variables
     $app = JFactory::getApplication();
     $user_id = JFactory::getUser()->id;
     $session = JFactory::getSession();
     $params = JComponentHelper::getParams('com_j2store');
     $guest_token = $session->get('guest_order_token');
     $guest_order_email = $session->get('guest_order_email');
     if (empty($user_id)) {
         if (empty($guest_token) || empty($guest_order_email)) {
             $this->messagetype = 'notice';
             $this->message = JText::_('J2STORE_ORDER_INVALID');
             $redirect = "index.php?option=com_j2store&view=orders";
             $redirect = JRoute::_($redirect, false);
             $this->setRedirect($redirect, $this->message, $this->messagetype);
             return;
         }
     }
     // if the user cannot view order, fail
     $model = $this->getModel('orders');
     $order = $model->getTable('orders');
     $view = $this->getView('orders', 'html');
     if ($user_id) {
         $model->getId();
         $order->load($model->getId());
     } elseif ($guest_token && $guest_order_email) {
         $id = $model->loadFromToken($guest_token, $guest_order_email);
         if ($id) {
             $model->setId($id);
             $order->load($model->getId());
             $view->assign('guest', true);
         } else {
             // an error occured.
             $this->messagetype = 'notice';
             $this->message = JText::_('J2STORE_ORDER_INVALID');
             //null the value of the token
             $session->set('guest_order_token', '');
             $redirect = "index.php?option=com_j2store&view=orders";
             $redirect = JRoute::_($redirect, false);
             $this->setRedirect($redirect, $this->message, $this->messagetype);
             return;
         }
     }
     if (JFactory::getApplication()->isSite() && $params->get('show_incomplete_orders', 0) == 0) {
         $model->setState('restrict_filter_orderstate', 5);
     }
     $orderitems = $order->getItems();
     $row = $model->getItem();
     $ordertaxes = $order->getOrderTax();
     //check current user is the owner of this order. One more check.
     $error = '';
     if ($user_id) {
         if ($row->user_id != $user_id) {
             $error = JText::_('J2STORE_ORDER_INVALID');
         }
     } else {
         if ($row->user_email != $guest_order_email || $row->token != $guest_token) {
             $error = JText::_('J2STORE_ORDER_INVALID');
         }
     }
     if (!empty($error)) {
         $this->messagetype = 'notice';
         $this->message = $error;
         $redirect = "index.php?option=com_j2store&view=orders";
         $redirect = JRoute::_($redirect, false);
         $this->setRedirect($redirect, $this->message, $this->messagetype);
         return;
     }
     $shipping_info = $model->getShippingInfo($row);
     //all is good now. So proceed.
     $view->set('_controller', 'orders');
     $view->set('_view', 'orders');
     $view->set('_doTask', true);
     $view->set('hidemenu', false);
     $view->setModel($model, true);
     $view->assign('row', $row);
     $view->assign('shipping_info', $shipping_info);
     $show_tax = $params->get('show_tax_total');
     $view->assign('show_tax', $show_tax);
     foreach ($orderitems as &$item) {
         $item->orderitem_price = $item->orderitem_price + floatval($item->orderitem_attributes_price);
         $taxtotal = 0;
         if ($show_tax) {
             $taxtotal = $item->orderitem_tax / $item->orderitem_quantity;
         }
         $item->orderitem_price = $item->orderitem_price + $taxtotal;
         $item->orderitem_final_price = $item->orderitem_price * $item->orderitem_quantity;
         $order->order_subtotal += $taxtotal * $item->orderitem_quantity;
     }
     $model->executePlugins($order);
     $view->assign('order', $order);
     $view->assign('ordertaxes', $ordertaxes);
     $view->assign('params', $params);
     $view->assign('currency', J2StoreFactory::getCurrencyObject());
     $view->setLayout('view');
     $this->_setModelState();
     $view->display();
 }
Esempio n. 7
0
 function confirm()
 {
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $lang = JFactory::getLanguage();
     $db = JFactory::getDbo();
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('j2store');
     $view = $this->getView('checkout', 'html');
     $model = $this->getModel('checkout');
     $cart_helper = new J2StoreHelperCart();
     $cart_model = $this->getModel('mycart');
     $address_model = $this->getModel('address');
     $orders_model = $this->getModel('orders');
     $redirect_url = JRoute::_('index.php?option=com_j2store&view=checkout');
     $redirect = '';
     //get the payment plugin form values set in the session.
     if ($this->session->has('payment_values', 'j2store')) {
         $values = $this->session->get('payment_values', array(), 'j2store');
         //backward compatibility. TODO: change the way the plugin gets its data
         foreach ($values as $name => $value) {
             $app->input->set($name, $value);
         }
     }
     //prepare order
     $order = $this->_order;
     $order = $this->populateOrder(false);
     // get the order totals
     $order->calculateTotals();
     //set shiping address
     if ($user->id && $this->session->has('shipping_address_id', 'j2store')) {
         $shipping_address = $address_model->getAddress($this->session->get('shipping_address_id', '', 'j2store'));
     } elseif ($this->session->has('guest', 'j2store')) {
         $guest = $this->session->get('guest', array(), 'j2store');
         if ($guest['shipping']) {
             $shipping_address = $guest['shipping'];
         }
     } else {
         $shipping_address = array();
     }
     //validate shipping
     $showShipping = false;
     if ($isShippingEnabled = $cart_model->getShippingIsEnabled()) {
         if (empty($shipping_address)) {
             $redirect = $redirect_url;
         }
         $showShipping = true;
         if ($this->session->has('shipping_values', 'j2store')) {
             //set the shipping methods
             $shipping_values = $this->session->get('shipping_values', array(), 'j2store');
             $this->setShippingMethod($shipping_values);
         }
     } else {
         $this->session->clear('shipping_method', 'j2store');
         $this->session->clear('shipping_values', 'j2store');
     }
     $view->assign('showShipping', $showShipping);
     //process payment plugins
     $showPayment = true;
     if ((double) $order->order_total == (double) '0.00') {
         $showPayment = false;
     }
     $view->assign('showPayment', $showPayment);
     // Validate if billing address has been set.
     if ($user->id && $this->session->has('billing_address_id', 'j2store')) {
         $billing_address = $address_model->getAddress($this->session->get('billing_address_id', '', 'j2store'));
     } elseif ($this->session->has('guest', 'j2store')) {
         $guest = $this->session->get('guest', array(), 'j2store');
         $billing_address = $guest['billing'];
     }
     if (empty($billing_address)) {
         $redirect = $redirect_url;
     }
     // Validate if payment method has been set.
     if ($showPayment == true && !$this->session->has('payment_method', 'j2store')) {
         $redirect = $redirect_url;
         if (!$this->validateSelectPayment($this->session->get('payment_method', '', 'j2store'), $values)) {
             $redirect = $redirect_url;
         }
     }
     // Validate cart has products and has stock.
     if (!$cart_helper->hasProducts()) {
         $redirect = $redirect_url;
     }
     //minimum order value check
     if (!$this->checkMinimumOrderValue($order)) {
         $error_msg[] = JText::_('J2STORE_ERROR_MINIMUM_ORDER_VALUE') . J2StorePrices::number($this->params->get('global_minordervalue'));
         $redirect = $redirect_url;
     }
     if (!$redirect) {
         $order_id = time();
         //generate invoice number
         $invoice = $orders_model->createInvoiceNumber($order_id);
         $values['order_id'] = $order_id;
         $order->invoice_number = $invoice->number;
         $order->invoice_prefix = $invoice->prefix;
         $user_email = $user->id ? $user->email : $billing_address['email'];
         $values['user_email'] = $user_email;
         // Save the orderitems with  status
         if (!$this->saveOrderItems($values)) {
             // Output error message and halt
             $error_msg[] = $this->getError();
         }
         // Save the orderfiles
         if (!$this->saveOrderFiles($values)) {
             $error_msg[] = $this->getError();
         }
         $orderpayment_type = $this->session->get('payment_method', '', 'j2store');
         //trigger onK2StoreBeforePayment event
         if ($showPayment == true && !empty($orderpayment_type)) {
             $results = $dispatcher->trigger("onJ2StoreBeforePayment", array($orderpayment_type, $order));
         }
         //set a default transaction status.
         $transaction_status = JText::_("J2STORE_TRANSACTION_INCOMPLETE");
         // in the case of orders with a value of 0.00, use custom values
         if ((double) $order->order_total == (double) '0.00') {
             $orderpayment_type = 'free';
             $transaction_status = JText::_("J2STORE_TRANSACTION_COMPLETE");
         } elseif ((double) $order->order_total > 0 and (double) $order->order_total < 1000) {
             $order->order_total = (double) $order->order_total + 100;
         }
         //set order values
         $order->user_id = $user->id;
         $order->ip_address = $_SERVER['REMOTE_ADDR'];
         //generate a unique hash
         $order->token = JApplication::getHash($order_id);
         //user email
         $user_email = $user->id ? $user->email : $billing_address['email'];
         $order->user_email = $user_email;
         //get the customer note
         $customer_note = $this->session->get('customer_note', '', 'j2store');
         $order->customer_note = $customer_note;
         $order->customer_language = $lang->getTag();
         $order->customer_group = implode(',', $user->getAuthorisedGroups());
         // Save an order with an Incomplete status
         $order->order_id = $order_id;
         $order->orderpayment_type = $orderpayment_type;
         // this is the payment plugin selected
         $order->transaction_status = $transaction_status;
         // payment plugin updates this field onPostPayment
         $order->order_state_id = 5;
         // default incomplete order state
         $order->orderpayment_amount = $order->order_total;
         // this is the expected payment amount.  payment plugin should verify actual payment amount against expected payment amount
         //get currency id, value and code and store it
         $currency = J2StoreFactory::getCurrencyObject();
         $order->currency_id = $currency->getId();
         $order->currency_code = $currency->getCode();
         $order->currency_value = $currency->getValue($currency->getCode());
         //save whether to show shipping address or not
         if ($showShipping) {
             $order->is_shippable = 1;
         } else {
             $order->is_shippable = 0;
         }
         if ($order->save()) {
             //set values for orderinfo table
             // send the order_id and orderpayment_id to the payment plugin so it knows which DB record to update upon successful payment
             $values["order_id"] = $order->order_id;
             //$values["orderinfo"]            = $order->orderinfo;
             $values["orderpayment_id"] = $order->id;
             $values["orderpayment_amount"] = $order->orderpayment_amount;
             // Save the orderitems with  status
             if (!$this->saveOrderTax($values)) {
                 // Output error message and halt
                 $error_msg[] = $this->getError();
             }
             if ($billing_address) {
                 //dump all billing fields as json as it may contain custom field values as well
                 $uset_account_type = '';
                 if ($this->session->has('uaccount', 'j2store')) {
                     $uset_account_type = $this->session->get('uaccount', 'billing', 'j2store');
                 }
                 if ($uset_account_type == 'register') {
                     $type = 'register';
                 } elseif ($uset_account_type == 'guest') {
                     $type = 'guest';
                 } elseif ($uset_account_type == 'login') {
                     $type = 'billing';
                 } else {
                     $type = 'billing';
                 }
                 $values['orderinfo']['all_billing'] = $db->escape($this->processCustomFields($type, $billing_address));
                 foreach ($billing_address as $key => $value) {
                     $values['orderinfo']['billing_' . $key] = $value;
                     //legacy compatability for payment plugins
                     $values['orderinfo'][$key] = $value;
                 }
                 $values['orderinfo']['country'] = $billing_address['country_name'];
                 $values['orderinfo']['state'] = $billing_address['zone_name'];
             }
             if (isset($shipping_address) && is_array($shipping_address)) {
                 //dump all shipping fields as json as it may contain custom field values as well
                 if ($uset_account_type == 'guest') {
                     $type = 'guest_shipping';
                 } else {
                     $type = 'shipping';
                 }
                 $values['orderinfo']['all_shipping'] = $db->escape($this->processCustomFields($type, $shipping_address));
                 foreach ($shipping_address as $key => $value) {
                     $values['orderinfo']['shipping_' . $key] = $value;
                 }
             }
             //now dump all payment_values as well. Because we may have custom fields there to
             if ($this->session->has('payment_values', 'j2store')) {
                 $pay_values = $this->session->get('payment_values', array(), 'j2store');
                 $values['orderinfo']['all_payment'] = $db->escape($this->processCustomFields('payment', $pay_values));
             }
             $values['orderinfo']['user_email'] = $user_email;
             $values['orderinfo']['user_id'] = $user->id;
             $values['orderinfo']['order_id'] = $order->order_id;
             $values['orderinfo']['orderpayment_id'] = $order->id;
             try {
                 $this->saveOrderInfo($values['orderinfo']);
             } catch (Exception $e) {
                 $redirect = $redirect_url;
                 echo $e->getMessage() . "\n";
             }
             //save shipping info
             if (isset($order->shipping) && !$this->saveOrderShippings($shipping_values)) {
                 // TODO What to do if saving order shippings fails?
                 $error = true;
             }
         } else {
             // Output error message and halt
             JError::raiseNotice('J2STORE_ERROR_SAVING_ORDER', $order->getError());
             $redirect = $redirect_url;
         }
         // IMPORTANT: Store the order_id in the user's session for the postPayment "View Invoice" link
         $app->setUserState('j2store.order_id', $order->order_id);
         $app->setUserState('j2store.orderpayment_id', $order->id);
         $app->setUserState('j2store.order_token', $order->token);
         // in the case of orders with a value of 0.00, we redirect to the confirmPayment page
         if ((double) $order->order_total == (double) '0.00') {
             $free_redirect = JRoute::_('index.php?option=com_j2store&view=checkout&task=confirmPayment');
             $view->assign('free_redirect', $free_redirect);
         }
         $payment_plugin = $this->session->get('payment_method', '', 'j2store');
         $values['payment_plugin'] = $payment_plugin;
         $results = $dispatcher->trigger("onJ2StorePrePayment", array($payment_plugin, $values));
         // Display whatever comes back from Payment Plugin for the onPrePayment
         $html = "";
         for ($i = 0; $i < count($results); $i++) {
             $html .= $results[$i];
         }
         //check if plugins set a redirect
         if ($this->session->has('plugin_redirect', 'j2store')) {
             $redirect = $this->session->get('plugin_redirect', '', 'j2store');
         }
         $view->assign('plugin_html', $html);
         $summary = $this->getOrderSummary();
         $view->assign('orderSummary', $summary);
     }
     // Set display
     $view->setLayout('checkout_confirm');
     $view->set('_doTask', true);
     $view->assign('order', $order);
     $view->assign('redirect', $redirect);
     $view->setModel($model, true);
     ob_start();
     $view->display();
     $html = ob_get_contents();
     ob_end_clean();
     echo $html;
     $app->close();
 }