function index()
 {
     $this->template->set('title', $this->language->get('heading_title'));
     $view = $this->locator->create('template');
     $view->set('heading_title', $this->language->get('heading_title'));
     $view->set('heading_description', $this->language->get('heading_description'));
     $view->set('button_list', $this->language->get('button_list'));
     $view->set('button_insert', $this->language->get('button_insert'));
     $view->set('button_update', $this->language->get('button_update'));
     $view->set('button_delete', $this->language->get('button_delete'));
     $view->set('button_save', $this->language->get('button_save'));
     $view->set('button_cancel', $this->language->get('button_cancel'));
     $view->set('button_print', $this->language->get('button_print'));
     $view->set('column_name', $this->language->get('column_name'));
     $view->set('column_viewed', $this->language->get('column_viewed'));
     $view->set('column_percent', $this->language->get('column_percent'));
     $product_data = array();
     $results = $this->modelReportViewed->get_viewed();
     $total = 0;
     $max = 0;
     foreach ($results as $result) {
         $total += $result['viewed'];
     }
     $max = $total ? number_format($results[0]['viewed'] / $total * 100, 2, '.', '') : 0;
     foreach ($results as $result) {
         $percent = $total ? roundDigits($result['viewed'] / $total * 100, 2) : 0;
         $product_data[] = array('name' => $result['name'], 'viewed' => $result['viewed'], 'percent' => $percent . '%', 'graph' => number_format(100 / $max * $percent, 2, '.', '') . '%');
     }
     $view->set('products', $product_data);
     $this->template->set('content', $view->fetch('content/report_viewed.tpl'));
     $this->template->set($this->module->fetch());
     $this->response->set($this->template->fetch('layout.tpl'));
 }
Beispiel #2
0
 function calculate($value, $tax_class_id, $calculate = TRUE)
 {
     if ($calculate && isset($this->taxes[$tax_class_id])) {
         return $value + roundDigits($value * $this->taxes[$tax_class_id]['rate'] / 100, $this->decimal_place);
     } else {
         return $value;
     }
 }
 function calculate()
 {
     $total_data = array();
     $this->decimal_place = $this->currency->currencies[$this->currency->code]['decimal_place'];
     if ($this->config->get('shipping_status') && $this->cart->hasShipping()) {
         $total_data[] = array('title' => $this->shipping->getTitle($this->session->get('shipping_method')) . ':', 'text' => $this->currency->format($this->tax->calculate($this->shipping->getCost($this->session->get('shipping_method')), $this->shipping->getTaxClassId($this->session->get('shipping_method')), $this->config->get('config_tax'))), 'value' => $this->tax->calculate($this->shipping->getCost($this->session->get('shipping_method')), $this->shipping->getTaxClassId($this->session->get('shipping_method')), $this->config->get('config_tax')));
         $this->cart->increaseTotal($this->tax->calculate($this->shipping->getCost($this->session->get('shipping_method')), $this->shipping->getTaxClassId($this->session->get('shipping_method'))));
         $this->cart->addTax($this->shipping->getTaxClassId($this->session->get('shipping_method')), roundDigits($this->shipping->getCost($this->session->get('shipping_method')) * ($this->tax->getRate($this->shipping->getTaxClassId($this->session->get('shipping_method'))) / 100), $this->decimal_place));
     }
     return $total_data;
 }
 function format_products()
 {
     $products = $this->request->gethtml('products', 'post');
     $this->product_tax = 0;
     $currency = $this->request->gethtml('currency', 'post') ? $this->request->gethtml('currency', 'post') : $this->currency->getCode();
     $value = $this->request->gethtml('exchange_value', 'post') ? $this->request->gethtml('exchange_value', 'post') : $this->currency->getValue($currency);
     $taxed = $this->request->gethtml('taxed', 'post') ? $this->request->gethtml('taxed', 'post') : $this->config->get('config_tax');
     $this->product_extended_total = 0;
     $product_data = array();
     if (!$products) {
         return $product_data;
     }
     foreach ($products as $key => $product) {
         $this->product_tax += $product['tax_amount'];
         $this->product_extended_total += $product['extended'] + ($taxed ? $product['tax_amount'] : 0);
         $array = explode(':', $product['product_id']);
         $product_id = $array[0];
         if (isset($array[1])) {
             $option_ids = explode('.', $array[1]);
         } else {
             $option_ids = array();
         }
         $product_info = $this->modelOrderEdit->get_product($product_id);
         $option_price = 0;
         $option_weight = 0;
         $option_data = array();
         foreach ($option_ids as $product_to_option_id) {
             $option = $this->modelOrderEdit->get_product_to_option($product_id, $product_to_option_id);
             if ($option['prefix'] == '+') {
                 $option_price = $option_price + $option['price'];
             } elseif ($option['prefix'] == '-') {
                 $option_price = $option_price - $option['price'];
             }
             $temp_option_weight = $this->weight->convert($option['option_weight'], $option['option_weightclass_id'], $product_info['weight_class_id']);
             $option_weight = $option_weight + $temp_option_weight;
             $option_data[] = array('product_to_option_id' => $product_to_option_id, 'name' => $option['name'], 'value' => $option['value'], 'prefix' => $option['prefix'], 'price' => roundDigits($option['price'], $this->decimal_place), 'option_weight' => $temp_option_weight, 'option_weightclass_id' => $option['option_weightclass_id']);
         }
         if ($option_ids) {
             $product_option = $this->modelOrderEdit->product_with_options($product['product_id']);
         } else {
             $product_option = array();
         }
         $downloads = $this->modelOrderEdit->get_downloads($product_id);
         $download_data = array();
         foreach ($downloads as $download) {
             $download_data[] = array('download_id' => $download['download_id'], 'name' => $download['name'], 'filename' => $download['filename'], 'mask' => $download['mask'], 'remaining' => $download['remaining']);
         }
         $vendor_data = $this->modelOrderEdit->get_vendor($product_id);
         if (!$this->request->gethtml('order_status', 'post')) {
             $product['discount'] = 0;
             $product['special_price'] = 0;
             $product['general_discount'] = 0;
             $product['coupon'] = 0;
         }
         $tax = $product['extended'] > 0 ? $product['tax_amount'] : $product['tax_amount'] * -1;
         if ($this->request->gethtml('order_status', 'post')) {
             $product_data[] = array('product_key' => $product['product_id'], 'product_id' => $product_id, 'href' => $this->url->href('product', FALSE, array('product_id' => $product_id)), 'name' => $product_info['name'], 'model_number' => isset($product_option['model_number']) ? @$product_option['model_number'] : @$product_info['model_number'], 'vendor_id' => $vendor_data['vendor_id'], 'vendor_name' => $vendor_data['vendor_id'] != '0' ? $vendor_data['name'] : NULL, 'option' => $option_data, 'download' => $download_data, 'quantity' => $product['quantity'], 'barcode' => isset($product_option['barcode']) ? @$product_option['barcode'] : @$product_info['barcode'], 'price' => $this->currency->format($product['quantity'] > 0 ? $product['price'] : $product['price'] * -1, $currency, $value), 'discount' => $product['discount'] != 0 ? $this->currency->format($product['discount'], $currency, $value) : NULL, 'special_price' => $product['special_price'] != 0 ? $this->currency->format($product['special_price'], $currency, $value) : NULL, 'general_discount' => $product['general_discount'] != 0 ? $this->currency->format($product['general_discount'] * -1, $currency, $value) : NULL, 'product_tax' => $this->currency->format($product['total'] > 0 ? $product['tax_amount'] : $product['tax_amount'] * -1, $currency, $value), 'net' => $this->currency->format($product['extended'], $currency, $value), 'coupon' => $product['coupon'] != 0 ? $this->currency->format($product['coupon'] * -1, $currency, $value) : NULL, 'total' => $this->currency->format($product['total'], $currency, $value), 'total_discounted' => $this->currency->format($product['extended'] + ($taxed ? 0 : $tax), $currency, $value), 'tax' => $this->currency->format($product['tax_rate'], '', 1, FALSE), 'shipping' => $product_info['shipping']);
         } else {
             $product_data[] = array('product_key' => $product['product_id'], 'product_id' => $product_id, 'href' => $this->url->href('product', FALSE, array('product_id' => $product_id)), 'name' => $product_info['name'], 'model_number' => isset($product_option['model_number']) ? @$product_option['model_number'] : @$product_info['model_number'], 'vendor_id' => NULL, 'vendor_name' => NULL, 'option' => $option_data, 'download' => $download_data, 'quantity' => $product['quantity'], 'barcode' => isset($product_option['barcode']) ? @$product_option['barcode'] : @$product_info['barcode'], 'price' => $this->currency->format($product['quantity'] > 0 ? $product['price'] : $product['price'] * -1, $currency, $value), 'discount' => NULL, 'coupon' => NULL, 'special_price' => NULL, 'general_discount' => NULL, 'net' => $this->currency->format($product['extended'], $currency, $value), 'total' => $this->currency->format($product['extended'], $currency, $value), 'product_tax' => $this->currency->format($product['tax_amount'], $currency, $value), 'total_discounted' => $this->currency->format($product['extended'] + $product['tax_amount'], $currency, $value), 'tax' => $this->currency->format($this->tax->getRate($product['tax_rate']), '', 1, FALSE), 'shipping' => $product_info['shipping']);
         }
     }
     return $product_data;
 }
Beispiel #5
0
 function getForm()
 {
     $view = $this->locator->create('template');
     $view->set('heading_title', $this->language->get('heading_form_title'));
     $view->set('heading_description', $this->language->get('heading_description'));
     $view->set('text_order', $this->language->get('text_order'));
     $view->set('text_invoice_number', $this->language->get('text_invoice_number'));
     $view->set('text_email', $this->language->get('text_email'));
     $view->set('text_telephone', $this->language->get('text_telephone'));
     $view->set('text_fax', $this->language->get('text_fax'));
     $view->set('text_shipping_address', $this->language->get('text_shipping_address'));
     $view->set('text_shipping_method', $this->language->get('text_shipping_method'));
     $view->set('text_payment_address', $this->language->get('text_payment_address'));
     $view->set('text_payment_method', $this->language->get('text_payment_method'));
     $view->set('text_currency', $this->language->get('text_currency'));
     $view->set('text_order_history', $this->language->get('text_order_history'));
     $view->set('text_order_download', $this->language->get('text_order_download'));
     $view->set('text_order_update', $this->language->get('text_order_update'));
     $view->set('text_product', $this->language->get('text_product'));
     $view->set('text_model_number', $this->language->get('text_model_number'));
     $view->set('text_soldby', $this->language->get('text_soldby'));
     $view->set('text_quantity', $this->language->get('text_quantity'));
     $view->set('text_price', $this->language->get('text_price'));
     $view->set('text_total', $this->language->get('text_total'));
     $view->set('text_special', $this->language->get('text_special'));
     $view->set('text_extended', $this->language->get('text_extended'));
     $view->set('text_coupon_value', $this->language->get('text_coupon_value'));
     $view->set('text_discount_value', $this->language->get('text_discount_value'));
     $view->set('text_net', $this->language->get('text_net'));
     $view->set('text_tax_rate', $this->language->get('text_tax_rate'));
     $view->set('text_tax', $this->language->get('text_tax'));
     $view->set('text_tax_amount', $this->language->get('text_tax_amount'));
     $view->set('text_product_totals', $this->language->get('text_product_totals'));
     $view->set('text_shipping_cost', $this->language->get('text_shipping_cost'));
     $view->set('text_free_shipping', $this->language->get('text_free_shipping'));
     $view->set('text_cart_totals', $this->language->get('text_cart_totals'));
     $view->set('text_shipping', $this->language->get('text_shipping'));
     $view->set('text_shippable', $this->language->get('text_shippable'));
     $view->set('text_non_shippable', $this->language->get('text_non_shippable'));
     $view->set('text_downloadable', $this->language->get('text_downloadable'));
     $view->set('column_date_added', $this->language->get('column_date_added'));
     $view->set('column_status', $this->language->get('column_status'));
     $view->set('column_download', $this->language->get('column_download'));
     $view->set('column_filename', $this->language->get('column_filename'));
     $view->set('column_remaining', $this->language->get('column_remaining'));
     $view->set('column_notify', $this->language->get('column_notify'));
     $view->set('column_comment', $this->language->get('column_comment'));
     $view->set('entry_status', $this->language->get('entry_status'));
     $view->set('entry_comment', $this->language->get('entry_comment'));
     $view->set('entry_notify', $this->language->get('entry_notify'));
     $view->set('cancelled_status', $this->language->get('cancelled_status'));
     $view->set('button_list', $this->language->get('button_list'));
     $view->set('button_insert', $this->language->get('button_insert'));
     $view->set('button_update', $this->language->get('button_update'));
     $view->set('button_delete', $this->language->get('button_delete'));
     $view->set('button_save', $this->language->get('button_save'));
     $view->set('button_cancel', $this->language->get('button_cancel'));
     $view->set('button_print', $this->language->get('button_print'));
     $view->set('tab_general', $this->language->get('tab_general'));
     $view->set('error', @$this->error['message']);
     $view->set('action', $this->url->ssl('order', 'update', array('order_id' => $this->request->gethtml('order_id'))));
     $view->set('list', $this->url->ssl('order'));
     $view->set('cancel', $this->url->ssl('order'));
     if ($this->request->gethtml('order_id')) {
         $view->set('update', 'update');
         $view->set('delete', $this->url->ssl('order', 'delete', array('order_id' => $this->request->gethtml('order_id'), 'order_validation' => $this->session->get('order_validation'))));
     }
     $this->session->set('cdx', md5(mt_rand()));
     $view->set('cdx', $this->session->get('cdx'));
     $this->session->set('validation', md5(time()));
     $view->set('validation', $this->session->get('validation'));
     $order_info = $this->modelOrder->get_order();
     if ($order_info['modified']) {
         $new_order = $this->modelOrder->get_modified_order($order_info['new_reference']);
         $new_order_date = $this->language->formatDate($this->language->get('date_format_short'), strtotime($new_order['date_added']));
         $view->set('modified', $this->language->get('text_modified', $new_order['order_id'], $order_info['new_reference'], $new_order_date));
     }
     $view->set('reference', $order_info['reference']);
     $view->set('invoice_number', $order_info['invoice_number']);
     $view->set('order_id', $order_info['order_id']);
     $view->set('email', $order_info['email']);
     $view->set('telephone', $order_info['telephone']);
     $view->set('fax', $order_info['fax']);
     $view->set('currency', $order_info['currency']);
     $this->decimal_place = $this->currency->currencies[$order_info['currency']]['decimal_place'];
     $view->set('coupon_sort_order', $order_info['coupon_sort_order']);
     $view->set('discount_sort_order', $order_info['discount_sort_order']);
     //$view->set('columns', $this->tpl_columns);
     $shipping_address = array('firstname' => $order_info['shipping_firstname'], 'lastname' => $order_info['shipping_lastname'], 'company' => $order_info['shipping_company'], 'address_1' => $order_info['shipping_address_1'], 'address_2' => $order_info['shipping_address_2'], 'city' => $order_info['shipping_city'], 'postcode' => $order_info['shipping_postcode'], 'zone' => $order_info['shipping_zone'], 'country' => $order_info['shipping_country']);
     if (array_filter($shipping_address)) {
         $view->set('shipping_address', $this->address->format($shipping_address, $order_info['shipping_address_format'], '<br />'));
     } else {
         $store_address = str_replace(array("\r\n", "\r", "\n"), '<br>', $this->config->get('warehouse_location') ? $this->config->get('warehouse_location') : $this->config->get('config_address'));
         $view->set('shipping_address', $this->config->get('config_store') . "<br />" . $store_address);
     }
     $view->set('shipping_method', $order_info['shipping_method']);
     $payment_address = array('firstname' => $order_info['payment_firstname'], 'lastname' => $order_info['payment_lastname'], 'company' => $order_info['payment_company'], 'address_1' => $order_info['payment_address_1'], 'address_2' => $order_info['payment_address_2'], 'city' => $order_info['payment_city'], 'postcode' => $order_info['payment_postcode'], 'zone' => $order_info['payment_zone'], 'country' => $order_info['payment_country']);
     $view->set('payment_address', nl2br($this->address->format($payment_address, $order_info['payment_address_format'])));
     $view->set('payment_method', $order_info['payment_method']);
     $products = $this->modelOrder->get_products();
     $product_data = array();
     $tax_total = 0;
     $coupon_total = 0;
     $net = 0;
     $net_total = 0;
     $producttax = 0;
     $discount_total = 0;
     $totals_total = 0;
     $shipping_tax = 0;
     $extended_total = 0;
     $freeshipping_tax = 0;
     $cart_net_total = 0;
     $cart_tax_total = 0;
     $cart_totals_total = 0;
     $shipping_net = $order_info['shipping_net'];
     $freeshipping_net = $order_info['freeshipping_net'] * -1;
     $shipping_tax = roundDigits($order_info['shipping_tax_rate'] * $order_info['shipping_net'] / 100, $this->decimal_place);
     $freeshipping_tax = roundDigits($order_info['shipping_tax_rate'] * $order_info['freeshipping_net'] / 100, $this->decimal_place);
     $shipping_total = $order_info['shipping_net'] + $shipping_tax;
     $freeshipping_total = $order_info['freeshipping_net'] + $freeshipping_tax;
     $view->set('shipping_net', $this->currency->format($order_info['shipping_net'] + ($order_info['taxed'] ? $shipping_tax : 0), $order_info['currency'], $order_info['value']));
     $view->set('shipping_tax_rate', round($order_info['shipping_tax_rate'], $this->decimal_place) . '%');
     if ($order_info['freeshipping_net'] != 0) {
         $view->set('freeshipping_net', $this->currency->format($order_info['freeshipping_net'] * -1 + ($order_info['taxed'] ? $freeshipping_tax * -1 : 0), $order_info['currency'], $order_info['value']));
     } else {
         $view->set('freeshipping_net', NULL);
     }
     foreach ($products as $product) {
         $options = $this->modelOrder->get_options($product['order_product_id']);
         $option_data = array();
         foreach ($options as $option) {
             $option_data[] = array('name' => $option['name'], 'value' => $option['value']);
         }
         $download = $this->modelOrder->check_downloads($product['order_product_id']);
         $special_pr = $product['special_price'];
         $net = $product['total'] - ($product['coupon'] != 0 ? $product['coupon'] : NULL) - ($product['general_discount'] != 0 ? $product['general_discount'] : NULL);
         $producttax = $order_info['taxed'] ? $net - roundDigits($net / ((100 + $product['tax']) / 100), $this->decimal_place) : roundDigits($net * ($product['tax'] / 100), $this->decimal_place);
         $tax_total += $producttax;
         $coupon_total += $product['coupon'] != 0 ? $product['coupon'] : NULL;
         $discount_total += $product['general_discount'] != 0 ? $product['general_discount'] : NULL;
         $net_total += $net;
         $total_discounted = $order_info['taxed'] ? $net : $net + $producttax;
         $totals_total += $total_discounted;
         $extended_total += $product['total'];
         $cart_net_total = $net_total + ($shipping_net != 0 ? $shipping_net : NULL) - ($freeshipping_net != 0 ? $freeshipping_net * -1 : NULL);
         $cart_tax_total = $tax_total + ($shipping_net != 0 ? $shipping_tax : NULL) - ($freeshipping_net != 0 ? $freeshipping_tax : NULL);
         //$cart_totals_total = $order_info['taxed'] ? $cart_net_total : $cart_net_total + $cart_tax_total;
         $cart_totals_total = $order_info['taxed'] ? $cart_net_total + ($shipping_tax - $freeshipping_tax) : $cart_net_total + $cart_tax_total;
         $product_data[] = array('name' => $product['name'], 'model_number' => $product['model_number'], 'vendor_name' => $product['vendor_id'] != '0' ? $product['vendor_name'] : NULL, 'option' => $option_data, 'download' => $download, 'quantity' => $product['quantity'], 'barcode' => $product['barcode'], 'barcode_url' => $product['barcode'] ? $this->barcode->show($product['barcode']) : NULL, 'special_price' => $special_pr != 0 ? $this->currency->format($special_pr, $order_info['currency'], $order_info['value']) : "\$0.00", 'price' => $this->currency->format($product['price'], $order_info['currency'], $order_info['value']), 'discount' => ceil($product['discount']) ? $this->currency->format($product['discount'], $order_info['currency'], $order_info['value']) : NULL, 'coupon' => $product['coupon'] != 0 ? $this->currency->format($product['coupon'] * -1, $order_info['currency'], $order_info['value']) : NULL, 'general_discount' => $product['general_discount'] != 0 ? $this->currency->format($product['general_discount'] * -1, $order_info['currency'], $order_info['value']) : NULL, 'tax' => round($product['tax'], $this->decimal_place), 'shipping' => $product['shipping'], 'total' => $this->currency->format($product['total'], $order_info['currency'], $order_info['value']), 'net' => $this->currency->format($net, $order_info['currency'], $order_info['value']), 'product_tax' => $this->currency->format($producttax, $order_info['currency'], $order_info['value']), 'total_discounted' => $this->currency->format($total_discounted, $order_info['currency'], $order_info['value']));
     }
     $view->set('taxed', $order_info['taxed']);
     $view->set('products', $product_data);
     $view->set('totals', $this->modelOrder->get_totals($order_info['order_id']));
     $view->set('tax_total', $this->currency->format($tax_total, $order_info['currency'], $order_info['value']));
     $view->set('coupon_total', $coupon_total ? $this->currency->format($coupon_total * -1, $order_info['currency'], $order_info['value']) : NULL);
     $view->set('discount_total', $discount_total ? $this->currency->format($discount_total * -1, $order_info['currency'], $order_info['value']) : NULL);
     $view->set('extended_total', $this->currency->format($extended_total, $order_info['currency'], $order_info['value']));
     $view->set('net_total', $this->currency->format($net_total, $order_info['currency'], $order_info['value']));
     $view->set('cart_net_total', $this->currency->format($cart_net_total, $order_info['currency'], $order_info['value']));
     $view->set('shipping_tax', $shipping_tax ? $this->currency->format($shipping_tax, $order_info['currency'], $order_info['value']) : NULL);
     $view->set('freeshipping_tax', $freeshipping_tax ? $this->currency->format($freeshipping_tax * -1, $order_info['currency'], $order_info['value']) : NULL);
     $view->set('cart_tax_total', $this->currency->format($cart_tax_total, $order_info['currency'], $order_info['value']));
     $view->set('totals_total', $this->currency->format($totals_total, $order_info['currency'], $order_info['value']));
     $view->set('shipping_total', $shipping_total ? $this->currency->format($shipping_total, $order_info['currency'], $order_info['value']) : NULL);
     $view->set('freeshipping_total', $freeshipping_total ? $this->currency->format($freeshipping_total * -1, $order_info['currency'], $order_info['value']) : NULL);
     $view->set('cart_totals_total', $this->currency->format($cart_totals_total, $order_info['currency'], $order_info['value']));
     $history_data = array();
     $results = $this->modelOrder->get_history();
     foreach ($results as $result) {
         $history_data[] = array('date_added' => $this->language->formatDate($this->language->get('date_format_short'), strtotime($result['date_added'])), 'status' => $result['status'], 'comment' => $result['comment'], 'notify' => $result['notify']);
     }
     $view->set('historys', $history_data);
     $download_data = array();
     $results = $this->modelOrder->get_downloads();
     foreach ($results as $result) {
         $download_data[] = array('name' => $result['name'], 'filename' => $result['filename'], 'remaining' => $result['remaining']);
     }
     $view->set('downloads', $download_data);
     $view->set('order_status_id', $order_info['order_status_id']);
     $view->set('order_statuses', $this->modelOrder->get_order_statuses());
     return $view->fetch('content/order.tpl');
 }
 function index()
 {
     if (!$this->customer->isLogged()) {
         $this->session->set('redirect', $this->url->ssl('checkout_shipping'));
         $this->response->redirect($this->url->ssl('account_login'));
     }
     if (!$this->cart->hasProducts() || !$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) {
         $this->response->redirect($this->url->ssl('cart'));
     }
     if ($this->cart->hasShipping()) {
         if (!$this->session->get('shipping_method')) {
             $this->response->redirect($this->url->ssl('checkout_shipping'));
         }
         if (!$this->shipping->getQuote($this->session->get('shipping_method'))) {
             $this->response->redirect($this->url->ssl('checkout_shipping'));
         }
         if (!$this->session->get('shipping_address_id')) {
             $this->response->redirect($this->url->ssl('checkout_address', 'shipping'));
         }
     } else {
         $this->session->delete('shipping_address_id');
         $this->session->delete('shipping_method');
     }
     if (!$this->session->get('payment_method')) {
         $this->response->redirect($this->url->ssl('checkout_payment'));
     }
     if (!$this->payment->hasMethod($this->session->get('payment_method'))) {
         $this->response->redirect($this->url->ssl('checkout_payment'));
     }
     if (!$this->address->has($this->session->get('payment_address_id'))) {
         $this->response->redirect($this->url->ssl('checkout_address', 'payment'));
     }
     $this->language->load('controller/checkout_confirm.php');
     $this->template->set('title', $this->language->get('heading_title'));
     if ($this->request->isPost() && $this->validate() && $this->request->has('coupon', 'post')) {
         $this->session->set('message', $this->language->get('text_coupon'));
         $this->response->redirect($this->url->ssl('checkout_confirm'));
     }
     if ($this->request->isPost() && $this->validate() && $this->request->has('agreed')) {
         //$this->session->set('message', $this->language->get('text_coupon'));
         $this->response->redirect($this->url->ssl('checkout_confirm'));
     }
     $view = $this->locator->create('template');
     $view->set('head_def', $this->head_def);
     $view->set('heading_title', $this->language->get('heading_title'));
     $view->set('text_shipping_address', $this->language->get('text_shipping_address'));
     $view->set('text_shipping_method', $this->language->get('text_shipping_method'));
     $view->set('text_payment_address', $this->language->get('text_payment_address'));
     $view->set('text_payment_method', $this->language->get('text_payment_method'));
     $view->set('text_comments', $this->language->get('text_comments'));
     $view->set('text_change', $this->language->get('text_change'));
     $view->set('text_product', $this->language->get('text_product'));
     $view->set('text_model_number', $this->language->get('text_model_number'));
     $view->set('text_soldby', $this->language->get('text_soldby'));
     $view->set('text_quantity', $this->language->get('text_quantity'));
     $view->set('text_price', $this->language->get('text_price'));
     $view->set('text_special', $this->language->get('text_special'));
     $view->set('text_total', $this->language->get('text_total'));
     $view->set('text_cart_totals', $this->language->get('text_cart_totals'));
     $view->set('text_product_totals', $this->language->get('text_product_totals'));
     $view->set('text_extended', $this->language->get('text_extended'));
     $view->set('text_coupon_value', $this->language->get('text_coupon_value'));
     $view->set('text_discount_value', $this->language->get('text_discount_value'));
     $view->set('text_tax_rate', $this->language->get('text_tax_rate'));
     $view->set('text_tax_amount', $this->language->get('text_tax_amount'));
     $view->set('text_net', $this->language->get('text_net'));
     $view->set('text_tax', $this->language->get('text_tax'));
     $view->set('text_shipping_cost', $this->language->get('text_shipping_cost'));
     $view->set('text_free_shipping', $this->language->get('text_free_shipping'));
     $view->set('text_shipping', $this->language->get('text_shipping'));
     $view->set('text_shippable', $this->language->get('text_shippable'));
     $view->set('text_non_shippable', $this->language->get('text_non_shippable'));
     $view->set('text_warehouse_pickup', $this->language->get('text_warehouse_pickup'));
     $view->set('text_currency', $this->language->get('text_currency'));
     $view->set('text_downloadable', $this->language->get('text_downloadable'));
     $view->set('entry_coupon', $this->language->get('entry_coupon'));
     $view->set('couponproducts', $this->coupon->hasProducts());
     $view->set('button_continue', $this->language->get('button_continue'));
     $view->set('button_back', $this->language->get('button_back'));
     $view->set('button_update', $this->language->get('button_update'));
     $view->set('error', @$this->error['message']);
     if ($this->session->has('error')) {
         $view->set('error', $this->session->get('error'));
         $this->session->delete('error');
     }
     $view->set('action', $this->url->ssl('checkout_confirm'));
     if ($this->request->has('coupon', 'post')) {
         $view->set('coupon', $this->request->gethtml('coupon', 'post'));
     } else {
         $view->set('coupon', $this->coupon->getCode());
     }
     $view->set('message', $this->session->get('message'));
     $this->session->delete('message');
     $this->session->delete('payment_form_enctype');
     $view->set('payment_url', $this->payment->getActionUrl($this->session->get('payment_method')));
     /*if ($this->session->get('payment_form_enctype')) {
     			$view->set('payment_form_enctype', $this->session->get('payment_form_enctype'));
     		}*/
     if ($this->payment->formType($this->session->get('payment_method'))) {
         $view->set('payment_form_enctype', $this->payment->formType($this->session->get('payment_method')));
     }
     if ($this->session->get('shipping_method') != 'warehouse_warehouse') {
         $view->set('shipping_address', $this->address->getFormatted($this->session->get('shipping_address_id'), '<br />'));
     } else {
         $store_address = str_replace(array("\r\n", "\r", "\n"), '<br>', $this->config->get('warehouse_location') ? $this->config->get('warehouse_location') : $this->config->get('config_address'));
         $view->set('shipping_address', $this->config->get('config_store') . "<br />" . $store_address);
     }
     $view->set('shipping_method', $this->shipping->getDescription($this->session->get('shipping_method')));
     $view->set('checkout_shipping', $this->url->ssl('checkout_shipping'));
     $view->set('checkout_shipping_address', $this->url->ssl('checkout_address', 'shipping'));
     $view->set('payment_address', $this->address->getFormatted($this->session->get('payment_address_id'), '<br />'));
     $view->set('payment_method', $this->payment->getTitle($this->session->get('payment_method')));
     $view->set('checkout_payment', $this->url->ssl('checkout_payment'));
     $view->set('checkout_payment_address', $this->url->ssl('checkout_address', 'payment'));
     $currency = $this->modelCheckout->get_currency();
     $view->set('currency', $currency);
     $totals = $this->calculate->getTotals();
     if (!$this->cart->moreThanMinov($this->cart->getNetTotal())) {
         $this->response->redirect($this->url->ssl('cart'));
     }
     $this->decimal_place = $this->currency->currencies[$this->currency->code]['decimal_place'];
     $product_data = array();
     $tax_total = 0;
     $extended_total = 0;
     $coupon_total = NULL;
     $discount_total = 0;
     $net_total = 0;
     $totals_total = 0;
     foreach ($this->cart->getProducts() as $product) {
         $option_data = array();
         foreach ($product['option'] as $option) {
             $option_data[] = array('name' => $option['name'], 'value' => $option['value']);
         }
         $view->set('hasnoshipping', $this->cart->hasNoShipping());
         $tax_total += $product['product_tax'];
         $extended_total += $this->tax->calculate($product['total'], $product['tax_class_id'], $this->config->get('config_tax'));
         $coupon_total += $product['coupon'] ? $product['coupon'] : NULL;
         $discount_total += $product['general_discount'] ? $product['general_discount'] : NULL;
         $net_total += $product['total_discounted'] + ($this->config->get('config_tax') ? $product['product_tax'] : 0);
         $totals_total += $product['total_discounted'] + $product['product_tax'];
         $special_price = $product['special_price'] ? $product['special_price'] - $product['discount'] : 0;
         if ($product['special_price']) {
             $discount_percent = (100 - $product['discount_percent']) / 100;
             $discount = $product['discount'] ? $this->currency->format($this->tax->calculate($product['price'] * $discount_percent, $product['tax_class_id'], $this->config->get('config_tax'))) : NULL;
         } else {
             $discount = $product['discount'] ? $this->currency->format($this->tax->calculate($product['price'] - $product['discount'], $product['tax_class_id'], $this->config->get('config_tax'))) : NULL;
         }
         if ($product['vendor_id'] != '0' && $this->config->get('config_registered')) {
             $vendor = $this->modelCheckout->get_vendor($product['vendor_id']);
             $vendor_name = $vendor['name'];
         } else {
             $vendor_name = NULL;
         }
         $product_data[] = array('product_id' => $product['product_id'], 'href' => $this->url->href('product', FALSE, array('product_id' => $product['product_id'])), 'name' => $product['name'], 'model_number' => $product['model_number'], 'vendor_name' => $vendor_name, 'vendor_id' => $product['vendor_id'], 'shipping' => $this->session->get('shipping_method') == 'warehouse_warehouse' ? FALSE : $product['shipping'], 'download' => $product['download'], 'option' => $option_data, 'quantity' => $product['quantity'], 'tax' => round($this->tax->getRate($product['tax_class_id']), $this->decimal_place), 'price' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'))), 'base_price' => $this->currency->format($product['price']), 'special_price' => $special_price ? $this->currency->format($this->tax->calculate($special_price, $product['tax_class_id'], $this->config->get('config_tax'))) : NULL, 'base_special_price' => $special_price ? $this->currency->format($special_price) : NULL, 'discount' => $discount, 'coupon' => $product['coupon'] ? '-' . $this->currency->format($product['coupon']) : NULL, 'general_discount' => $product['general_discount'] ? '-' . $this->currency->format($product['general_discount']) : NULL, 'net' => $this->currency->format($product['total_discounted'] + ($this->config->get('config_tax') ? $product['product_tax'] : 0)), 'product_tax' => $this->currency->format($product['product_tax']), 'total_discounted' => $this->currency->format($product['total_discounted'] + $product['product_tax']), 'total' => $this->currency->format($this->tax->calculate($product['total'], $product['tax_class_id'], $this->config->get('config_tax'))));
     }
     if ($this->cart->hasShipping()) {
         $shipping_net = $this->shipping->getCost($this->session->get('shipping_method'));
         $shipping_tax = roundDigits($shipping_net / 100 * $this->tax->getRate($this->shipping->getTaxClassId($this->session->get('shipping_method'))), $this->decimal_place);
         $shipping_total = $shipping_net + $shipping_tax;
         $shipping_tax_rate = round($this->tax->getRate($this->shipping->getTaxClassId($this->session->get('shipping_method'))), $this->decimal_place);
         $view->set('shipping_tax_rate', $shipping_tax_rate . '%');
         $view->set('shipping_net', $this->currency->format($shipping_net + ($this->config->get('config_tax') ? $shipping_tax : NULL)));
         $view->set('shipping_tax', $this->currency->format($shipping_tax));
         $view->set('shipping_total', $this->currency->format($shipping_total));
         if ($this->coupon->getShipping()) {
             $freeshipping_net = $shipping_net;
             $freeshipping_tax = $shipping_tax;
             $freeshipping_total = $shipping_total;
             $view->set('freeshipping_net', '-' . $this->currency->format($freeshipping_net + ($this->config->get('config_tax') ? $freeshipping_tax : NULL)));
             $view->set('freeshipping_tax', '-' . $this->currency->format($freeshipping_tax));
             $view->set('freeshipping_total', '-' . $this->currency->format($freeshipping_total));
         }
     }
     $cart_net_total = $net_total + (isset($shipping_net) ? $shipping_net : 0) - (isset($freeshipping_net) ? $freeshipping_net : 0) + ($this->config->get('config_tax') ? (isset($shipping_tax) ? $shipping_tax : 0) - (isset($freeshipping_tax) ? $freeshipping_tax : 0) : 0);
     $cart_tax_total = $tax_total + (isset($shipping_tax) ? $shipping_tax : 0) - (isset($freeshipping_tax) ? $freeshipping_tax : 0);
     $cart_totals_total = $totals_total + (isset($shipping_total) ? $shipping_total : 0) - (isset($freeshipping_total) ? $freeshipping_total : 0);
     $coupon_sort_order = $this->config->get('coupon_sort_order');
     $discount_sort_order = $this->config->get('discount_sort_order');
     $view->set('tax_included', $this->config->get('config_tax'));
     $view->set('products', $product_data);
     $view->set('columns', $this->tpl_columns);
     $view->set('extended_total', $this->currency->format($extended_total));
     $view->set('coupon_total', $coupon_total ? '-' . $this->currency->format($coupon_total) : NULL);
     $view->set('discount_total', $discount_total ? '-' . $this->currency->format($discount_total) : NULL);
     $view->set('net_total', $this->currency->format($net_total));
     $view->set('tax_total', $this->currency->format($tax_total));
     $view->set('totals_total', $this->currency->format($totals_total));
     $view->set('cart_net_total', $this->currency->format($cart_net_total));
     $view->set('cart_tax_total', $this->currency->format($cart_tax_total));
     $view->set('cart_totals_total', $this->currency->format($cart_totals_total));
     $view->set('totals', $totals);
     $view->set('coupon_sort_order', $coupon_sort_order);
     $view->set('discount_sort_order', $discount_sort_order);
     $view->set('comment', $this->session->get('comment'));
     $view->set('one_payment_method', $this->session->get('one_payment_method'));
     if (!$this->cart->hasShipping() && $this->session->get('one_payment_method')) {
         $view->set('back', $this->url->ssl('cart'));
     } elseif ($this->cart->hasShipping() && $this->session->get('one_payment_method')) {
         $view->set('back', $this->url->ssl('checkout_shipping'));
     } else {
         $view->set('back', $this->url->ssl('checkout_payment'));
     }
     $this->order->set('customer_id', $this->customer->getId());
     $this->order->set('firstname', $this->customer->getFirstName());
     $this->order->set('lastname', $this->customer->getLastName());
     $this->order->set('email', $this->customer->getEmail());
     $this->order->set('telephone', $this->customer->getTelephone());
     $this->order->set('fax', $this->customer->getFax());
     $this->order->set('order_status_id', $this->config->get('config_order_status_id'));
     $this->order->set('total', $this->cart->getTotal());
     $this->order->set('currency', $this->currency->getCode());
     $this->order->set('value', $this->currency->getValue($this->currency->getCode()));
     $this->order->set('ip', $_SERVER['REMOTE_ADDR']);
     $this->order->set('coupon_sort_order', $coupon_sort_order);
     $this->order->set('discount_sort_order', $discount_sort_order);
     $this->order->set('shipping_net', isset($shipping_net) ? $shipping_net : 0);
     $this->order->set('shipping_tax_rate', isset($shipping_tax_rate) ? $shipping_tax_rate : 0);
     $this->order->set('freeshipping_net', isset($freeshipping_net) ? $freeshipping_net : 0);
     $this->order->set('taxed', $this->config->get('config_tax'));
     $this->order->set('shipping_firstname', $this->session->get('shipping_method') != 'warehouse_warehouse' ? $this->address->getFirstName($this->session->get('shipping_address_id')) : NULL);
     $this->order->set('shipping_lastname', $this->session->get('shipping_method') != 'warehouse_warehouse' ? $this->address->getLastName($this->session->get('shipping_address_id')) : NULL);
     $this->order->set('shipping_company', $this->session->get('shipping_method') != 'warehouse_warehouse' ? $this->address->getCompany($this->session->get('shipping_address_id')) : NULL);
     $this->order->set('shipping_address_1', $this->session->get('shipping_method') != 'warehouse_warehouse' ? $this->address->getAddress1($this->session->get('shipping_address_id')) : NULL);
     $this->order->set('shipping_address_2', $this->session->get('shipping_method') != 'warehouse_warehouse' ? $this->address->getAddress2($this->session->get('shipping_address_id')) : NULL);
     $this->order->set('shipping_city', $this->session->get('shipping_method') != 'warehouse_warehouse' ? $this->address->getCity($this->session->get('shipping_address_id')) : NULL);
     $this->order->set('shipping_postcode', $this->session->get('shipping_method') != 'warehouse_warehouse' ? $this->address->getPostCode($this->session->get('shipping_address_id')) : NULL);
     $this->order->set('shipping_zone', $this->session->get('shipping_method') != 'warehouse_warehouse' ? $this->address->getZone($this->session->get('shipping_address_id')) : NULL);
     $this->order->set('shipping_country', $this->session->get('shipping_method') != 'warehouse_warehouse' ? $this->address->getCountry($this->session->get('shipping_address_id')) : NULL);
     $this->order->set('shipping_address_format', $this->session->get('shipping_method') != 'warehouse_warehouse' ? $this->address->getFormat($this->session->get('shipping_address_id')) : NULL);
     $this->order->set('shipping_method', $this->shipping->getDescription($this->session->get('shipping_method')));
     $this->order->set('payment_firstname', $this->address->getFirstName($this->session->get('payment_address_id')));
     $this->order->set('payment_lastname', $this->address->getLastName($this->session->get('payment_address_id')));
     $this->order->set('payment_company', $this->address->getCompany($this->session->get('payment_address_id')));
     $this->order->set('payment_address_1', $this->address->getAddress1($this->session->get('payment_address_id')));
     $this->order->set('payment_address_2', $this->address->getAddress2($this->session->get('payment_address_id')));
     $this->order->set('payment_city', $this->address->getCity($this->session->get('payment_address_id')));
     $this->order->set('payment_postcode', $this->address->getPostCode($this->session->get('payment_address_id')));
     $this->order->set('payment_zone', $this->address->getZone($this->session->get('payment_address_id')));
     $this->order->set('payment_country', $this->address->getCountry($this->session->get('payment_address_id')));
     $this->order->set('payment_address_format', $this->address->getFormat($this->session->get('payment_address_id')));
     $this->order->set('payment_method', $this->payment->getTitle($this->session->get('payment_method')));
     $email = $this->locator->create('template');
     $email->set('email_greeting', $this->language->get('email_greeting', $this->customer->getFirstName()));
     $email->set('email_thanks', $this->language->get('email_thanks', $this->config->get('config_store')));
     $email->set('email_order', $this->language->get('email_order', $this->order->getReference()));
     $email->set('email_date', $this->language->get('email_date', $this->language->formatDate($this->language->get('date_format_long'))));
     $email->set('email_invoice_number', $this->language->get('email_invoice_number'));
     $email->set('email_invoice', $this->language->get('email_invoice', $this->url->ssl('account_invoice', FALSE, array('reference' => $this->order->getReference())), $this->url->ssl('account_invoice', FALSE, array('reference' => $this->order->getReference()))));
     $email->set('email_shipping_address', $this->language->get('email_shipping_address'));
     $email->set('email_shipping_method', $this->language->get('email_shipping_method'));
     $email->set('email_email', $this->language->get('email_email'));
     $email->set('email_telephone', $this->language->get('email_telephone'));
     $email->set('email_fax', $this->language->get('email_fax'));
     $email->set('email_payment_address', $this->language->get('email_payment_address'));
     $email->set('email_payment_method', $this->language->get('email_payment_method'));
     $email->set('email_comment', $this->language->get('email_comment'));
     $email->set('email_thanks_again', $this->language->get('email_thanks_again', $this->config->get('config_store')));
     $email->set('email_product', $this->language->get('email_product'));
     $email->set('email_model_number', $this->language->get('email_model_number'));
     $email->set('email_soldby', $this->language->get('email_soldby'));
     $email->set('email_quantity', $this->language->get('text_quantity'));
     $email->set('email_price', $this->language->get('text_price'));
     $email->set('email_specialprice', $this->language->get('text_special'));
     $email->set('email_extended', $this->language->get('text_extended'));
     $email->set('email_coupon_value', $this->language->get('text_coupon_value'));
     $email->set('email_discount_value', $this->language->get('text_discount_value'));
     $email->set('email_net', $this->language->get('text_net'));
     $email->set('email_tax_rate', $this->language->get('text_tax_rate'));
     $email->set('email_tax_amount', $this->language->get('text_tax_amount'));
     $email->set('email_shipping', $this->language->get('text_shipping'));
     $email->set('email_total', $this->language->get('email_total'));
     $email->set('tax_included', $this->config->get('config_tax'));
     $email->set('email_ship', $this->language->get('email_ship'));
     $email->set('email_noship', $this->language->get('email_noship'));
     $email->set('email_download', $this->language->get('email_download'));
     $email->set('text_currency', $this->language->get('text_currency'));
     if ($this->cart->hasShipping()) {
         $email->set('shipping_net', $this->currency->format($shipping_net + ($this->config->get('config_tax') ? $shipping_tax : NULL)));
         $email->set('shipping_tax', $this->currency->format($shipping_tax));
         $email->set('shipping_total', $this->currency->format($shipping_total));
         $email->set('shipping_tax_rate', $shipping_tax_rate . '%');
         if ($this->coupon->getShipping()) {
             $email->set('freeshipping_net', '-' . $this->currency->format($freeshipping_net + ($this->config->get('config_tax') ? $freeshipping_tax : NULL)));
             $email->set('freeshipping_tax', '-' . $this->currency->format($freeshipping_tax));
             $email->set('freeshipping_total', '-' . $this->currency->format($freeshipping_total));
         }
     }
     $email->set('currency', $currency);
     $email->set('text_product_totals', $this->language->get('text_product_totals'));
     $email->set('text_shipping_cost', $this->language->get('text_shipping_cost'));
     $email->set('text_free_shipping', $this->language->get('text_free_shipping'));
     $email->set('text_cart_totals', $this->language->get('text_cart_totals'));
     $email->set('text_tax', $this->language->get('text_tax'));
     $email->set('store', $this->config->get('config_store'));
     $store_address = $this->config->get('config_address');
     $email->set('store_address', str_replace(array("\r\n", "\r", "\n"), '<br>', $store_address));
     $email->set('email', $this->customer->getEmail());
     $email->set('telephone', $this->customer->getTelephone());
     $email->set('fax', $this->customer->getFax());
     if ($this->session->get('shipping_method') != 'warehouse_warehouse') {
         $email->set('shipping_address', $this->address->getFormatted($this->session->get('shipping_address_id'), '<br />'));
     } else {
         $store_address = str_replace(array("\r\n", "\r", "\n"), '<br>', $this->config->get('warehouse_location') ? $this->config->get('warehouse_location') : $this->config->get('config_address'));
         $email->set('shipping_address', $this->config->get('config_store') . "<br />" . $store_address);
     }
     if ($this->session->get('payment_method') == 'banktr') {
         $email->set('email_banktr_message', $this->language->get('email_banktr_message', $this->order->getReference()));
         $email->set('banktr_address', str_replace(array("\r\n", "\r", "\n"), '<br>', $this->config->get('banktr_bank_name')));
         $email->set('email_banktr_bank_name', $this->language->get('email_banktr_bank_name'));
         $email->set('email_banktr_owner_name', $this->language->get('email_banktr_owner_name'));
         $email->set('banktr_owner', $this->config->get('banktr_owner'));
         $email->set('same_country', $this->customer->country_compare($this->session->get('payment_address_id')));
         $email->set('email_banktr_ban', $this->language->get('email_banktr_ban'));
         $email->set('banktr_ban', $this->config->get('banktr_ban'));
         $email->set('email_banktr_iban', $this->language->get('email_banktr_iban'));
         $email->set('email_banktr_swift', $this->language->get('email_banktr_swift'));
         $email->set('banktr_iban', $this->config->get('banktr_iban'));
         $email->set('banktr_swift', $this->config->get('banktr_swift'));
     } else {
         $email->set('email_banktr_message', NULL);
     }
     $email->set('shipping_method', $this->shipping->getDescription($this->session->get('shipping_method')));
     $email->set('payment_address', $this->address->getFormatted($this->session->get('payment_address_id'), '<br />'));
     $email->set('payment_method', $this->payment->getTitle($this->session->get('payment_method')));
     $email->set('products', $product_data);
     $email->set('totals', $totals);
     $email->set('extended_total', $this->currency->format($extended_total));
     $email->set('coupon_total', $coupon_total ? '-' . $this->currency->format($coupon_total) : NULL);
     $email->set('discount_total', $discount_total ? '-' . $this->currency->format($discount_total) : NULL);
     $email->set('net_total', $this->currency->format($net_total));
     $email->set('tax_total', $this->currency->format($tax_total));
     $email->set('totals_total', $this->currency->format($totals_total));
     $email->set('coupon_sort_order', $coupon_sort_order);
     $email->set('discount_sort_order', $discount_sort_order);
     $email->set('cart_net_total', $this->currency->format($cart_net_total));
     $email->set('cart_tax_total', $this->currency->format($cart_tax_total));
     $email->set('cart_totals_total', $this->currency->format($cart_totals_total));
     $email->set('comment', $this->session->get('comment'));
     $product_data = array();
     foreach ($this->cart->getProducts() as $product) {
         $option_data = array();
         foreach ($product['option'] as $option) {
             $option_data[] = array('name' => $option['name'], 'value' => $option['value'], 'prefix' => $option['prefix']);
         }
         $special_price = $product['special_price'] ? $product['special_price'] - $product['discount'] : 0;
         if ($product['special_price']) {
             $discount_percent = (100 - $product['discount_percent']) / 100;
             $discount = $product['discount'] ? $this->tax->calculate($product['price'] * $discount_percent, $product['tax_class_id'], $this->config->get('config_tax')) : NULL;
         } else {
             $discount = $product['discount'] ? $this->tax->calculate($product['price'] - $product['discount'], $product['tax_class_id'], $this->config->get('config_tax')) : NULL;
         }
         if ($product['vendor_id'] != '0' && $this->config->get('config_registered')) {
             $vendor = $this->modelCheckout->get_vendor($product['vendor_id']);
             $vendor_name = $vendor['name'];
         } else {
             $vendor_name = NULL;
         }
         $product_data[] = array('product_key' => $product['key'], 'product_id' => $product['product_id'], 'name' => $product['name'], 'model_number' => $product['model_number'], 'vendor_name' => $vendor_name, 'vendor_id' => $product['vendor_id'], 'option' => $option_data, 'download' => $product['download'], 'quantity' => $product['quantity'], 'barcode' => $product['barcode'], 'price' => $this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')), 'discount' => $discount, 'special_price' => $special_price ? $this->tax->calculate($special_price, $product['tax_class_id'], $this->config->get('config_tax')) : 0, 'coupon' => $product['coupon'], 'general_discount' => $product['general_discount'], 'total' => $this->tax->calculate($product['total'], $product['tax_class_id'], $this->config->get('config_tax')), 'tax' => $this->tax->getRate($product['tax_class_id']), 'shipping' => $this->session->get('shipping_method') == 'warehouse_warehouse' ? FALSE : $product['shipping']);
     }
     $this->order->set('discount_total', $discount_total);
     $this->order->set('products', $product_data);
     $this->order->set('totals', $totals);
     $this->order->set('coupon_id', $this->coupon->getId());
     $this->order->set('comment', $this->session->get('comment'));
     $this->order->set('email_subject', $this->language->get('email_subject', $this->order->getReference()));
     $this->order->set('email_html', $email->fetch('content/checkout_email.tpl'));
     $this->order->set('email_text', $this->language->get('email_message', $this->config->get('config_store'), $this->order->getReference(), $this->url->ssl('account_invoice', FALSE, array('reference' => $this->order->getReference())), $this->language->formatDate($this->language->get('date_format_long')), strip_tags($this->session->get('comment'))));
     $view->set('fields', $this->payment->getFields($this->session->get('payment_method')));
     if ($this->config->get('config_checkout_id')) {
         $information_info = $this->modelCheckout->get_information($this->config->get('config_checkout_id'));
         $view->set('agree', $this->language->get('text_agree', $this->url->href('information', FALSE, array('information_id' => $this->config->get('config_checkout_id'))), $information_info['title']));
     }
     $this->order->save($this->order->getReference());
     $this->template->set('content', $view->fetch('content/checkout_confirm.tpl'));
     $this->template->set('head_def', $this->head_def);
     $this->load_modules();
     // Template Manager
     $this->set_tpl_modules();
     // Template Manager
     $this->template->set($this->module->fetch());
     $this->response->set($this->template->fetch('layout.tpl'));
 }
 function index()
 {
     if (!$this->customer->isLogged()) {
         if ($this->request->has('order_id')) {
             $this->session->set('redirect', $this->url->ssl('account_invoice', FALSE, array('order_id' => $this->request->gethtml('order_id'))));
         } else {
             $this->session->set('redirect', $this->url->ssl('account_invoice', FALSE, array('reference' => $this->request->gethtml('reference'))));
         }
         $this->response->redirect($this->url->ssl('account_login'));
     }
     $this->language->load('controller/account_invoice.php');
     $this->template->set('title', $this->language->get('heading_title'));
     $view = $this->locator->create('template');
     $view->set('heading_title', $this->language->get('heading_title'));
     $view->set('head_def', $this->head_def);
     // New Header
     $this->template->set('head_def', $this->head_def);
     // New Header
     $view->set('button_continue', $this->language->get('button_continue'));
     $view->set('continue', $this->url->ssl('account_history'));
     if ($this->request->has('order_id')) {
         $order_info = $this->modelAccountInvoice->get_order($this->request->gethtml('order_id'));
     } else {
         $order_info = $this->modelAccountInvoice->get_order_ref($this->request->gethtml('reference'));
     }
     if ($order_info) {
         $view->set('text_order', $this->language->get('text_order'));
         $view->set('text_invoice_number', $this->language->get('text_invoice_number'));
         $view->set('text_email', $this->language->get('text_email'));
         $view->set('text_telephone', $this->language->get('text_telephone'));
         $view->set('text_fax', $this->language->get('text_fax'));
         $view->set('text_shipping_address', $this->language->get('text_shipping_address'));
         $view->set('text_shipping_method', $this->language->get('text_shipping_method'));
         $view->set('text_payment_address', $this->language->get('text_payment_address'));
         $view->set('text_payment_method', $this->language->get('text_payment_method'));
         $view->set('text_currency', $this->language->get('text_currency'));
         $view->set('text_order_history', $this->language->get('text_order_history'));
         $view->set('text_product', $this->language->get('text_product'));
         $view->set('text_model_number', $this->language->get('text_model_number'));
         $view->set('text_soldby', $this->language->get('text_soldby'));
         $view->set('text_quantity', $this->language->get('text_quantity'));
         $view->set('text_price', $this->language->get('text_price'));
         $view->set('text_special', $this->language->get('text_special'));
         $view->set('text_extended', $this->language->get('text_extended'));
         $view->set('text_coupon_value', $this->language->get('text_coupon_value'));
         $view->set('text_discount_value', $this->language->get('text_discount_value'));
         $view->set('text_net', $this->language->get('text_net'));
         $view->set('text_tax_rate', $this->language->get('text_tax_rate'));
         $view->set('text_tax', $this->language->get('text_tax'));
         $view->set('text_tax_amount', $this->language->get('text_tax_amount'));
         $view->set('text_product_totals', $this->language->get('text_product_totals'));
         $view->set('text_shipping_cost', $this->language->get('text_shipping_cost'));
         $view->set('text_free_shipping', $this->language->get('text_free_shipping'));
         $view->set('text_cart_totals', $this->language->get('text_cart_totals'));
         $view->set('text_shipping', $this->language->get('text_shipping'));
         $view->set('text_total', $this->language->get('text_total'));
         $view->set('column_date_added', $this->language->get('column_date_added'));
         $view->set('column_status', $this->language->get('column_status'));
         $view->set('column_comment', $this->language->get('column_comment'));
         $view->set('text_shippable', $this->language->get('text_shippable'));
         $view->set('text_non_shippable', $this->language->get('text_non_shippable'));
         $view->set('text_downloadable', $this->language->get('text_downloadable'));
         $this->decimal_place = $this->currency->currencies[$order_info['currency']]['decimal_place'];
         $view->set('reference', $order_info['reference']);
         $view->set('invoice_number', $order_info['invoice_number']);
         $view->set('email', $order_info['email']);
         $view->set('telephone', $order_info['telephone']);
         $view->set('fax', $order_info['fax']);
         $view->set('currency', $order_info['currency']);
         $view->set('coupon_sort_order', $order_info['coupon_sort_order']);
         $view->set('discount_sort_order', $order_info['discount_sort_order']);
         $view->set('columns', $this->tpl_columns);
         $shipping_address = array('firstname' => $order_info['shipping_firstname'], 'lastname' => $order_info['shipping_lastname'], 'company' => $order_info['shipping_company'], 'address_1' => $order_info['shipping_address_1'], 'address_2' => $order_info['shipping_address_2'], 'city' => $order_info['shipping_city'], 'postcode' => $order_info['shipping_postcode'], 'zone' => $order_info['shipping_zone'], 'country' => $order_info['shipping_country']);
         if (array_filter($shipping_address)) {
             $view->set('shipping_address', $this->address->format($shipping_address, $order_info['shipping_address_format'], '<br />'));
         } else {
             $store_address = str_replace(array("\r\n", "\r", "\n"), '<br>', $this->config->get('warehouse_location') ? $this->config->get('warehouse_location') : $this->config->get('config_address'));
             $view->set('shipping_address', $this->config->get('config_store') . "<br />" . $store_address);
         }
         $view->set('shipping_method', $order_info['shipping_method']);
         $payment_address = array('firstname' => $order_info['payment_firstname'], 'lastname' => $order_info['payment_lastname'], 'company' => $order_info['payment_company'], 'address_1' => $order_info['payment_address_1'], 'address_2' => $order_info['payment_address_2'], 'city' => $order_info['payment_city'], 'postcode' => $order_info['payment_postcode'], 'zone' => $order_info['payment_zone'], 'country' => $order_info['payment_country']);
         $view->set('payment_address', $this->address->format($payment_address, $order_info['payment_address_format'], '<br />'));
         $view->set('payment_method', $order_info['payment_method']);
         $products = $this->modelAccountInvoice->get_order_products($order_info['order_id']);
         $product_data = array();
         $tax_total = 0;
         $coupon_total = 0;
         $net = 0;
         $net_total = 0;
         $producttax = 0;
         $discount_total = 0;
         $totals_total = 0;
         $shipping_tax = 0;
         $extended_total = 0;
         $freeshipping_tax = 0;
         $shipping_net = $order_info['shipping_net'];
         $freeshipping_net = $order_info['freeshipping_net'];
         $shipping_tax = roundDigits($order_info['shipping_tax_rate'] * $order_info['shipping_net'] / 100, $this->decimal_place);
         $freeshipping_tax = roundDigits($order_info['shipping_tax_rate'] * $order_info['freeshipping_net'] / 100, $this->decimal_place);
         $shipping_total = $order_info['shipping_net'] + $shipping_tax;
         $freeshipping_total = $order_info['freeshipping_net'] + $freeshipping_tax;
         $view->set('shipping_net', $this->currency->format($order_info['shipping_net'] + ($order_info['taxed'] ? $shipping_tax : 0), $order_info['currency'], $order_info['value']));
         $view->set('shipping_tax_rate', round($order_info['shipping_tax_rate'], $this->decimal_place) . '%');
         if ($order_info['freeshipping_net'] > 0) {
             $view->set('freeshipping_net', '-' . $this->currency->format($order_info['freeshipping_net'] + ($order_info['taxed'] ? $freeshipping_tax : 0), $order_info['currency'], $order_info['value']));
         } else {
             $view->set('freeshipping_net', NULL);
         }
         foreach ($products as $product) {
             $options = $this->modelAccountInvoice->get_options($order_info['order_id'], $product['order_product_id']);
             $option_data = array();
             foreach ($options as $option) {
                 $option_data[] = array('name' => $option['name'], 'value' => $option['value']);
             }
             $download = $this->modelAccountInvoice->get_downloads($order_info['order_id'], $product['order_product_id']);
             $special_pr = $product['special_price'];
             $net = $product['total'] - ($product['coupon'] ? $product['coupon'] : NULL) - ($product['general_discount'] ? $product['general_discount'] : NULL);
             $producttax = $order_info['taxed'] ? $net - roundDigits($net / ((100 + $product['tax']) / 100), $this->decimal_place) : roundDigits($net * ($product['tax'] / 100), $this->decimal_place);
             $tax_total += $producttax;
             $coupon_total += $product['coupon'] ? $product['coupon'] : NULL;
             $discount_total += $product['general_discount'] ? $product['general_discount'] : NULL;
             $net_total += $net;
             $total_discounted = $order_info['taxed'] ? $net : $net + $producttax;
             $totals_total += $total_discounted;
             $extended_total += $product['total'];
             $cart_net_total = $net_total + ($shipping_net ? $shipping_net : NULL) - ($freeshipping_net ? $freeshipping_net : NULL);
             $cart_tax_total = $tax_total + ($shipping_tax ? $shipping_tax : NULL) - ($freeshipping_tax ? $freeshipping_tax : NULL);
             //$cart_totals_total = $cart_net_total + $cart_tax_total;
             $cart_totals_total = $order_info['taxed'] ? $cart_net_total + ($shipping_tax - $freeshipping_tax) : $cart_net_total + $cart_tax_total;
             $product_data[] = array('name' => $product['name'], 'model_number' => $product['model_number'], 'vendor_name' => $product['vendor_id'] != '0' && $this->config->get('config_registered') ? $product['vendor_name'] : NULL, 'option' => $option_data, 'download' => $download, 'quantity' => $product['quantity'], 'special_price' => $special_pr > 0 ? $this->currency->format($special_pr, $order_info['currency'], $order_info['value']) : NULL, 'price' => $this->currency->format($product['price'], $order_info['currency'], $order_info['value']), 'discount' => ceil($product['discount']) ? $this->currency->format($product['discount'], $order_info['currency'], $order_info['value']) : NULL, 'coupon' => $product['coupon'] > 0 ? '-' . $this->currency->format($product['coupon']) : NULL, 'general_discount' => $product['general_discount'] > 0 ? '-' . $this->currency->format($product['general_discount'], $order_info['currency'], $order_info['value']) : NULL, 'tax' => round($product['tax'], $this->decimal_place), 'shipping' => $product['shipping'], 'total' => $this->currency->format($product['total'], $order_info['currency'], $order_info['value']), 'net' => $this->currency->format($net, $order_info['currency'], $order_info['value']), 'product_tax' => $this->currency->format($producttax, $order_info['currency'], $order_info['value']), 'total_discounted' => $this->currency->format($total_discounted, $order_info['currency'], $order_info['value']));
         }
         $view->set('taxed', $order_info['taxed']);
         $view->set('tax_included', $this->config->get('config_tax'));
         $view->set('products', $product_data);
         $view->set('totals', $this->modelAccountInvoice->get_totals($order_info['order_id']));
         $view->set('tax_total', $this->currency->format($tax_total, $order_info['currency'], $order_info['value']));
         $view->set('coupon_total', $coupon_total ? '-' . $this->currency->format($coupon_total, $order_info['currency'], $order_info['value']) : NULL);
         $view->set('discount_total', $discount_total ? '-' . $this->currency->format($discount_total, $order_info['currency'], $order_info['value']) : NULL);
         $view->set('extended_total', $this->currency->format($extended_total, $order_info['currency'], $order_info['value']));
         $view->set('net_total', $this->currency->format($net_total, $order_info['currency'], $order_info['value']));
         $view->set('cart_net_total', $this->currency->format($cart_net_total + ($order_info['taxed'] ? $shipping_tax - $freeshipping_tax : Null), $order_info['currency'], $order_info['value']));
         $view->set('shipping_tax', $shipping_tax ? $this->currency->format($shipping_tax, $order_info['currency'], $order_info['value']) : NULL);
         $view->set('freeshipping_tax', $freeshipping_tax ? '-' . $this->currency->format($freeshipping_tax, $order_info['currency'], $order_info['value']) : NULL);
         $view->set('cart_tax_total', $this->currency->format($cart_tax_total, $order_info['currency'], $order_info['value']));
         $view->set('totals_total', $this->currency->format($totals_total, $order_info['currency'], $order_info['value']));
         $view->set('shipping_total', $shipping_total ? $this->currency->format($shipping_total, $order_info['currency'], $order_info['value']) : NULL);
         $view->set('freeshipping_total', $freeshipping_total ? '-' . $this->currency->format($freeshipping_total, $order_info['currency'], $order_info['value']) : NULL);
         $view->set('cart_totals_total', $this->currency->format($cart_totals_total, $order_info['currency'], $order_info['value']));
         $history_data = array();
         $results = $this->modelAccountInvoice->get_order_history($order_info['order_id']);
         foreach ($results as $result) {
             $history_data[] = array('date_added' => $this->language->formatDate($this->language->get('date_format_short'), strtotime($result['date_added'])), 'status' => $result['status'], 'comment' => $result['comment']);
         }
         $view->set('historys', $history_data);
         $view->set('order_print', $this->request->gethtml('order_print'));
         if ($this->request->gethtml('order_print')) {
             $this->template->set('continue', $this->url->ssl('account_history'));
             $this->template->set('config_owner', $this->config->get('config_owner'));
             $this->template->set('config_address', str_replace(array("\r\n", "\r", "\n"), '<br>', $this->config->get('config_address')));
             $this->template->set('store_logo', $this->image->href('logo/' . $this->config->get('config_store_logo')));
         }
         $this->template->set('content', $view->fetch('content/account_invoice.tpl'));
     } else {
         $view->set('text_error', $this->language->get('text_error'));
         $this->template->set('content', $view->fetch('content/error.tpl'));
     }
     $this->load_modules();
     // Template Manager
     $this->set_tpl_modules();
     // Template Manager
     if ($this->request->gethtml('order_print')) {
         $this->response->set($this->template->fetch('print_layout.tpl'));
     } else {
         $this->template->set($this->module->fetch());
         $this->response->set($this->template->fetch('layout.tpl'));
     }
 }
 function calculate()
 {
     $this->decimal_place = $this->currency->currencies[$this->currency->code]['decimal_place'];
     $total_data = array();
     $rawcouponvalue = 0;
     $freeshipavail = 0;
     $rawtaxvalue = 0;
     if ($this->coupon->get_minimum() > $this->cart->subtotal) {
         return $total_data;
     }
     if ($this->config->get('coupon_status') && $this->coupon->getId()) {
         if (!empty($this->coupon->product)) {
             // peritem code if empty
             foreach ($this->coupon->product as $result) {
                 // get Coupon to Product
                 $data[] = $result['product_id'];
             }
             foreach ($this->cart->getProducts() as $product) {
                 if (in_array($product['product_id'], $data)) {
                     $discount = $this->coupon->getDiscount($product['total_discounted']);
                     $coupon_value = $product['total_discounted'] >= $discount ? $discount : $product['total_discounted'];
                     $old_tax = roundDigits($product['total_discounted'] / 100 * $this->tax->getRate($product['tax_class_id']), $this->decimal_place);
                     $this->cart->products[$product['key']]['total_discounted'] = $product['total_discounted'] - $coupon_value;
                     if ($this->cart->products[$product['key']]['total_discounted'] > 0) {
                         $new_tax = roundDigits($this->cart->products[$product['key']]['total_discounted'] / 100 * $this->tax->getRate($product['tax_class_id']), $this->decimal_place);
                         $tax_decrease = $old_tax - $new_tax;
                     } else {
                         $tax_decrease = $old_tax;
                     }
                     $this->cart->products[$product['key']]['coupon'] = $coupon_value + ($this->config->get('config_tax') ? $tax_decrease : 0);
                     $rawtaxvalue += $tax_decrease;
                     $this->cart->decreaseTaxes($product['tax_class_id'], $tax_decrease);
                     $this->cart->decreaseProductTax($product['key'], $tax_decrease);
                     $rawcouponvalue += $coupon_value;
                     $freeshipavail++;
                     //freeshipping flag
                 }
             }
             if ($rawcouponvalue > 0) {
                 // If Discount
                 $total_data[] = array('title' => $this->language->get('text_coupon_title', $this->coupon->getName()), 'text' => '-' . $this->currency->format($this->config->get('config_tax') ? $rawcouponvalue + $rawtaxvalue : $rawcouponvalue), 'value' => $rawcouponvalue);
             }
             if ($this->cart->total <= $rawcouponvalue + $rawtaxvalue) {
                 $this->cart->decreaseTotal($this->cart->total);
             } else {
                 $this->cart->decreaseTotal($rawcouponvalue + $rawtaxvalue);
             }
             if ($freeshipavail) {
                 // Free shipping set
                 if ($this->coupon->getShipping() && $this->cart->hasShipping()) {
                     $total_data[] = array('title' => $this->language->get('text_coupon_shipping'), 'text' => '-' . $this->currency->format($this->tax->calculate($this->shipping->getCost($this->session->get('shipping_method')), $this->shipping->getTaxClassId($this->session->get('shipping_method')), $this->config->get('config_tax'))), 'value' => $this->tax->calculate($this->shipping->getCost($this->session->get('shipping_method')), $this->shipping->getTaxClassId($this->session->get('shipping_method')), $this->config->get('config_tax')));
                     $shipping_total = $this->tax->calculate($this->shipping->getCost($this->session->get('shipping_method')), $this->shipping->getTaxClassId($this->session->get('shipping_method')), $this->config->get('config_tax'));
                     if (!$this->config->get('config_tax')) {
                         $shipping_tax = roundDigits($this->shipping->getCost($this->session->get('shipping_method')) / 100 * $this->tax->getRate($this->shipping->getTaxClassId($this->session->get('shipping_method'))), $this->decimal_place);
                     } else {
                         $shipping_tax = 0;
                     }
                     if ($this->cart->total <= $shipping_total + $shipping_tax) {
                         $this->cart->decreaseTotal($this->cart->total);
                         $this->cart->decreaseTaxes($this->shipping->getTaxClassId($this->session->get('shipping_method'), $this->cart->taxes[$this->shipping->getTaxClassId($this->session->get('shipping_method'))]));
                     } else {
                         $this->cart->decreaseTotal($shipping_total + $shipping_tax);
                         $this->cart->decreaseTaxes($this->shipping->getTaxClassId($this->session->get('shipping_method')), roundDigits($this->shipping->getCost($this->session->get('shipping_method')) / 100 * $this->tax->getRate($this->shipping->getTaxClassId($this->session->get('shipping_method'))), $this->decimal_place));
                     }
                 }
             }
         } else {
             // per cart code
             foreach ($this->cart->getProducts() as $product) {
                 $discount = $this->coupon->getDiscount($product['total_discounted']);
                 $coupon_value = $product['total_discounted'] >= $discount ? $discount : $product['total_discounted'];
                 $old_tax = roundDigits($product['total_discounted'] / 100 * $this->tax->getRate($product['tax_class_id']), $this->decimal_place);
                 $this->cart->products[$product['key']]['total_discounted'] = $product['total_discounted'] - $coupon_value;
                 if ($this->cart->products[$product['key']]['total_discounted'] > 0) {
                     $new_tax = roundDigits($this->cart->products[$product['key']]['total_discounted'] / 100 * $this->tax->getRate($product['tax_class_id']), $this->decimal_place);
                     $tax_decrease = $old_tax - $new_tax;
                 } else {
                     $tax_decrease = $old_tax;
                 }
                 $this->cart->products[$product['key']]['coupon'] = $coupon_value + ($this->config->get('config_tax') ? $tax_decrease : 0);
                 $rawtaxvalue += $tax_decrease;
                 $this->cart->decreaseTaxes($product['tax_class_id'], $tax_decrease);
                 $this->cart->decreaseProductTax($product['key'], $tax_decrease);
                 $rawcouponvalue += $coupon_value;
             }
             if ($rawcouponvalue > 0) {
                 // If Discount
                 $total_data[] = array('title' => $this->language->get('text_coupon_title', $this->coupon->getName()), 'text' => '-' . $this->currency->format($this->config->get('config_tax') ? $rawcouponvalue + $rawtaxvalue : $rawcouponvalue), 'value' => $rawcouponvalue);
                 if ($this->cart->total <= $rawcouponvalue + $rawtaxvalue) {
                     $this->cart->decreaseTotal($this->cart->total);
                 } else {
                     $this->cart->decreaseTotal($rawcouponvalue + $rawtaxvalue);
                 }
             }
             if ($this->coupon->getShipping() && $this->cart->hasShipping()) {
                 $total_data[] = array('title' => $this->language->get('text_coupon_shipping'), 'text' => '-' . $this->currency->format($this->tax->calculate($this->shipping->getCost($this->session->get('shipping_method')), $this->shipping->getTaxClassId($this->session->get('shipping_method')), $this->config->get('config_tax'))), 'value' => $this->tax->calculate($this->shipping->getCost($this->session->get('shipping_method')), $this->shipping->getTaxClassId($this->session->get('shipping_method')), $this->config->get('config_tax')));
                 $shipping_total = $this->tax->calculate($this->shipping->getCost($this->session->get('shipping_method')), $this->shipping->getTaxClassId($this->session->get('shipping_method')), $this->config->get('config_tax'));
                 if (!$this->config->get('config_tax')) {
                     $shipping_tax = roundDigits($this->shipping->getCost($this->session->get('shipping_method')) / 100 * $this->tax->getRate($this->shipping->getTaxClassId($this->session->get('shipping_method'))), $this->decimal_place);
                 } else {
                     $shipping_tax = 0;
                 }
                 if ($this->cart->total <= $shipping_total + $shipping_tax) {
                     $this->cart->decreaseTotal($this->cart->total);
                     $this->cart->decreaseTaxes($this->shipping->getTaxClassId($this->session->get('shipping_method'), $this->cart->taxes[$this->shipping->getTaxClassId($this->session->get('shipping_method'))]));
                 } else {
                     $this->cart->decreaseTotal($shipping_total + $shipping_tax);
                     $this->cart->decreaseTaxes($this->shipping->getTaxClassId($this->session->get('shipping_method')), roundDigits($this->shipping->getCost($this->session->get('shipping_method')) / 100 * $this->tax->getRate($this->shipping->getTaxClassId($this->session->get('shipping_method'))), $this->decimal_place));
                 }
             }
         }
     }
     return $total_data;
 }
 function getDiscount($value)
 {
     if ($this->data) {
         if ($this->data['prefix'] == '%') {
             return roundDigits($value * $this->data['discount'] / 100, $this->decimal_place);
         } elseif ($this->data['prefix'] == '-') {
             return roundDigits($this->data['discount'], $this->decimal_place);
         }
     }
 }
Beispiel #10
0
 function data_refresh()
 {
     if ($this->controller->controller == 'cart') {
         $this->config->set('config_tax', $this->config->get('config_tax_store'));
     }
     foreach ($this->data as $key => $value) {
         $array = explode(':', $key);
         $product_id = $array[0];
         $quantity = $value;
         if (isset($array[1])) {
             $options = explode('.', $array[1]);
         } else {
             $options = array();
         }
         $product = $this->database->getRow("select * from product p left join product_description pd on (p.product_id = pd.product_id) left join image i on (p.image_id = i.image_id) where p.product_id = '" . (int) $product_id . "' and pd.language_id = '" . (int) $this->language->getId() . "' and p.date_available < now() and p.status = '1'");
         if ($product) {
             $option_price = 0;
             $option_weight = 0;
             $option_data = array();
             foreach ($options as $product_to_option_id) {
                 $option = $this->database->getRow("select o.name as name, ov.name as `value`, p2o.price, p2o.prefix, p2o.option_weight, p2o.option_weightclass_id from product_to_option p2o left join `option` o on p2o.option_id = o.option_id left join option_value ov on p2o.option_value_id = ov.option_value_id where p2o.product_to_option_id = '" . (int) $product_to_option_id . "' and product_id = '" . (int) $product_id . "' and o.language_id = '" . (int) $this->language->getId() . "' and ov.language_id = '" . (int) $this->language->getId() . "'");
                 if ($option['prefix'] == '+') {
                     $option_price = $option_price + $option['price'];
                 } elseif ($option['prefix'] == '-') {
                     $option_price = $option_price - $option['price'];
                 }
                 $temp_option_weight = $this->weight->convert($option['option_weight'], $option['option_weightclass_id'], $product['weight_class_id']);
                 $option_weight = $option_weight + $temp_option_weight;
                 $option_data[] = array('product_to_option_id' => $product_to_option_id, 'name' => $option['name'], 'value' => $option['value'], 'prefix' => $option['prefix'], 'price' => roundDigits($option['price'], $this->decimal_place), 'option_weight' => $temp_option_weight, 'option_weightclass_id' => $option['option_weightclass_id']);
             }
             if ($options) {
                 $product_option = $this->database->getRow("select * from product_options po left join image i on (po.image_id = i.image_id) where product_option = '" . $key . "'");
             } else {
                 $product_option = array();
             }
             if ($product['vendor_id'] != '0' && $this->config->get('config_unregistered')) {
                 $vendor_name = $this->database->getRow("select name from vendor where vendor_id = '" . (int) $product['vendor_id'] . "'");
             } else {
                 $vendor_name = NULL;
             }
             $product_discount = $this->database->getRow("select * from product_discount where product_id = '" . (int) $product['product_id'] . "' and quantity <= '" . (int) $quantity . "' order by quantity desc limit 1");
             if (!$product_discount) {
                 // changed to percent
                 $discount_percent = 0;
             } else {
                 $discount_percent = $product_discount['discount'];
             }
             $downloads = $this->database->getRows("select * from product_to_download p2d left join download d on (p2d.download_id = d.download_id) left join download_description dd on (d.download_id = dd.download_id) where p2d.product_id = '" . (int) $product_id . "' and p2d.free = ' 0 ' and dd.language_id = '" . (int) $this->language->getId() . "'");
             $download_data = array();
             foreach ($downloads as $download) {
                 $download_data[] = array('download_id' => $download['download_id'], 'name' => $download['name'], 'filename' => $download['filename'], 'mask' => $download['mask'], 'remaining' => $download['remaining']);
             }
             $price = roundDigits($product['price'], $this->decimal_place);
             $special_price = roundDigits($product['special_price'], $this->decimal_place);
             if ($special_price > 0 && date('Y-m-d H:i:s') >= $product['sale_start_date'] && date('Y-m-d') <= $product['sale_end_date']) {
                 $extended_price = roundDigits($special_price, $this->decimal_place);
                 $discount = $discount_percent > 0 ? roundDigits(($special_price + ($this->config->get('config_discount_options') ? $option_price : 0)) * ($discount_percent / 100), $this->decimal_place) : '0';
                 $special_price = roundDigits($product['special_price'] + $option_price, $this->decimal_place);
             } else {
                 $extended_price = $price;
                 $special_price = '0';
                 $discount = $discount_percent > 0 ? roundDigits(($price + ($this->config->get('config_discount_options') ? $option_price : 0)) * ($discount_percent / 100), $this->decimal_place) : '0';
             }
             $this->products[$key] = array('key' => $key, 'product_id' => $product['product_id'], 'name' => $product['name'], 'vendor_id' => $product['vendor_id'], 'vendor_name' => $vendor_name['name'], 'model_number' => isset($product_option['model_number']) ? @$product_option['model_number'] : @$product['model_number'], 'shipping' => isset($product_option['shipping']) ? @$product_option['shipping'] : @$product['shipping'], 'image' => isset($product_option['filename']) && @$product_option['filename'] ? @$product_option['filename'] : $product['filename'], 'option' => $option_data, 'download' => $download_data, 'quantity' => $quantity, 'barcode' => isset($product_option['barcode']) ? @$product_option['barcode'] : @$product['barcode'], 'min_qty' => $product['min_qty'], 'max_qty' => $product['max_qty'], 'multiple' => $product['multiple'], 'stock' => $quantity <= (isset($product_option['quantity']) ? @$product_option['quantity'] : @$product['quantity']), 'price' => roundDigits($product['price'] + $option_price, $this->decimal_place), 'special_price' => $special_price, 'discount' => $discount, 'coupon' => 0, 'general_discount' => 0, 'discount_percent' => $discount_percent, 'total' => roundDigits(($extended_price + $option_price - $discount) * $quantity, $this->decimal_place), 'total_discounted' => roundDigits(($extended_price + $option_price - $discount) * $quantity, $this->decimal_place), 'tax_class_id' => $product['tax_class_id'], 'product_tax' => roundDigits(($extended_price + $option_price - $discount) * $quantity / 100 * $this->tax->getRate($product['tax_class_id']), $this->decimal_place), 'weight' => $product['weight'] + $option_weight, 'weight_class_id' => $product['weight_class_id'], 'dimension_value' => isset($product_option['dimension_value']) && @$product_option['dimension_value'] ? @$product_option['dimension_value'] : $product['dimension_value'], 'dimension_id' => isset($product_option['dimension_id']) && @$product_option['dimension_id'] ? @$product_option['dimension_id'] : $product['dimension_id']);
             $this->subtotal += $this->tax->calculate(($extended_price + $option_price - $discount) * $quantity, $product['tax_class_id'], $this->config->get('config_tax'));
             if (!isset($this->taxes[$product['tax_class_id']])) {
                 $this->taxes[$product['tax_class_id']] = roundDigits(($extended_price + $option_price - $discount) * $quantity / 100 * $this->tax->getRate($product['tax_class_id']), $this->decimal_place);
             } else {
                 $this->taxes[$product['tax_class_id']] += roundDigits(($extended_price + $option_price - $discount) * $quantity / 100 * $this->tax->getRate($product['tax_class_id']), $this->decimal_place);
             }
             $this->total += $this->tax->calculate(($extended_price + $option_price - $discount) * $quantity, $product['tax_class_id']);
             if ($quantity > (isset($product_option['quantity']) ? @$product_option['quantity'] : $product['quantity'])) {
                 $this->stock = FALSE;
             }
             if ($product['max_qty'] != 0) {
                 $this->maxqty = TRUE;
             }
             if ($product['shipping']) {
                 $this->shipping = TRUE;
             } else {
                 if (!$download_data) {
                     $this->noshipping = TRUE;
                 }
             }
             if ($download_data) {
                 $this->downloads = TRUE;
             }
         } else {
             $this->remove($key);
         }
     }
 }
 function getDiscount($value)
 {
     if ($value) {
         return roundDigits($value * $this->dispercent / 100, $this->decimal_place);
     }
 }