예제 #1
0
 public function addInvoice($orderId, $order_items, $weight = 0)
 {
     $orderModel = $this->load->model('sale/order');
     /// Get customer and shipping data from the primary order
     $order = $orderModel->getOrder($orderId);
     /// Calculate total weight and price
     $tmpWeight = 0;
     $subtotal = 0;
     foreach ($order_items as $order_item) {
         /// If weight isn't defined by administrator it's calculated
         if (!$weight) {
             $tmpWeight += $this->weight->format($order_item['weight'], $this->config->get('config_weight_class_id')) * $order_item['quantity'];
         }
         $subtotal += $order_item['price'] * $order_item['quantity'];
     }
     if (!$weight) {
         $weight = $tmpWeight;
     }
     /// Get shipping cost according to destination and weight
     $shippingCost = ShippingMethodDAO::getInstance()->getMethod(explode('.', $order['shipping_method'])[0])->getCost(explode('.', $order['shipping_method'])[1], $order_items, ['weight' => $weight]);
     /// Calculate total. Currently it's just subtotal and shipping. In the future it can be something else
     $total = $subtotal + $shippingCost;
     /// Add invoice record to the database
     $this->getDb()->query("\r\n            INSERT INTO " . DB_PREFIX . "invoices\r\n            SET\r\n                customer_id = " . (int) $order['customer_id'] . ",\r\n                date_added = NOW(),\r\n                shipping_address_id = " . $orderModel->getShippingAddressId($orderId) . ",\r\n                shipping_method = '" . $order['shipping_method'] . "'',\r\n                shipping_cost = {$shippingCost},\r\n                subtotal = {$subtotal},\r\n                total = {$total},\r\n                weight = " . (double) $weight);
     /// Add invoice items
     $this->addInvoiceItems($this->getDb()->getLastId(), $order_items);
 }
예제 #2
0
 public function getCost()
 {
     $modelShipping = \model\shipping\ShippingMethodDAO::getInstance()->getMethod('pickup');
     $shippingMethodElements = explode('.', $this->request->request['method']);
     $cost = $modelShipping->getCost($shippingMethodElements[1], $this->request->request['weight']);
     $json = array('cost' => $cost);
     $this->getResponse()->setOutput(json_encode($json));
 }
예제 #3
0
 public function getCost()
 {
     //        $this->log->write(print_r($this->request->request, true));
     $shippingMethodDostavkaGuru = ShippingMethodDAO::getInstance()->getMethod('dostavkaGuru');
     $shippingMethodElements = explode('.', $this->request->request['method']);
     $cost = $shippingMethodDostavkaGuru->getCost($shippingMethodElements[1], null, array('weight' => $this->request->request['weight']));
     $json = array('cost' => $cost);
     $this->getResponse()->setOutput(json_encode($json));
 }
예제 #4
0
 public function getCost()
 {
     //        $this->log->write(print_r($this->request->request, true));
     $model = \model\shipping\ShippingMethodDAO::getInstance()->getMethod('emsDiscounted');
     $shippingMethodElements = explode('.', $this->parameters['method']);
     $cost = $model->getCost($shippingMethodElements[1], null, array('weight' => $this->parameters['weight']));
     $json = array('cost' => $cost);
     $this->getResponse()->setOutput(json_encode($json));
 }
예제 #5
0
 /**
  * @param int $orderId
  * @param OrderItem[] $orderItems
  * @param mixed $shippingMethod
  * @param float $weight
  * @param float $discount
  * @param string $comment
  * @param string $shippingDate
  * @return int
  */
 public function addInvoice($orderId, $orderItems, $shippingMethod = null, $weight = 0.0, $discount = 0.0, $comment = "", $shippingDate = '')
 {
     /** @var \ModelSaleOrder $orderModel */
     $orderModel = $this->getLoader()->model('sale/order');
     /// Get customer and shipping data from the primary order
     $order = $orderModel->getOrder($orderId);
     $customer = CustomerDAO::getInstance()->getCustomer($order['customer_id']);
     /// Calculate total weight and price in shop currency and customer currency
     $tmpWeight = 0;
     $tmpSubtotal = 0;
     $subtotalCustomerCurrency = 0;
     foreach ($orderItems as $orderItem) {
         /// If weight isn't defined by administrator it's calculated
         if (!$weight) {
             $tmpWeight += $this->weight->format($orderItem->getWeight(), $this->getConfig()->get('config_weight_class_id')) * $orderItem->getQuantity();
         }
         $itemCost = $orderItem->getPrice() * $orderItem->getQuantity() + $orderItem->getShippingCost();
         $tmpSubtotal += $itemCost;
         $subtotalCustomerCurrency += $orderItem->getTotal(true);
     }
     $subtotal = $tmpSubtotal;
     /// It seems to originate from time when subtotal could be edited manually.
     /// Now it's done by specifying discount (I hope)
     //        if (!isset($subtotal)) {
     //            $subtotal = $tmpSubtotal;
     //        } else {
     //            $subtotalCustCurr = $this->getCurrency()->convert(
     //                $subtotal,
     //                $this->config->get('config_currency'),
     //                $customer['base_currency_code']
     //            );
     //        }
     if (!$weight) {
         $weight = $tmpWeight;
     }
     /// Get shipping cost according to destination and order items
     /// The shipping cost calculation can take different order items factors into account
     /// Therefore it's better to pass whole items and let shipping calculation classes use it
     if (empty($shippingMethod)) {
         $shippingMethod = $order['shipping_method'];
     }
     $shippingMethodComponents = explode('.', $shippingMethod);
     $shippingCost = ShippingMethodDAO::getInstance()->getMethod($shippingMethodComponents[0])->getCost($shippingMethodComponents[1], $orderItems, ['weight' => $weight]);
     /// Calculate total. Currently it's subtotal, shipping and discount. In the future it can be something else
     $total = $subtotal + $shippingCost - $discount;
     $totalCustomerCurrency = $subtotalCustomerCurrency + $this->getCurrency()->convert($shippingCost - $discount, $this->getConfig()->get('config_currency'), $customer['base_currency_code']);
     /// Add invoice record to the database
     $this->getDb()->query("\n            INSERT INTO invoices\n            SET\n                customer_id = :customerId,\n                comment = :comment,\n                discount = :discount,\n                shipping_address_id = :shippingAddressId,\n                shipping_method = :shippingMethod,\n                shipping_date = :shippingDate,\n                shipping_cost = :shippingCost,\n                subtotal = :subtotal,\n                time_modified = NOW(),\n                total = :total,\n                total_customer_currency = :totalCustomerCurrency,\n                currency_code = :currencyCode,\n                weight = :weight\n            ", array(':customerId' => $order['customer_id'], ':comment' => $comment, ':discount' => $discount, ':shippingAddressId' => $orderModel->getShippingAddressId($orderId), ':shippingMethod' => $shippingMethod, ':shippingDate' => $shippingDate, ':shippingCost' => $shippingCost, ':subtotal' => $subtotal, ':total' => $total, ':totalCustomerCurrency' => $totalCustomerCurrency, ':currencyCode' => $customer['base_currency_code'], ':weight' => $weight));
     /// Add invoice items
     $invoiceId = $this->getDb()->getLastId();
     $this->addInvoiceItems($invoiceId, $orderItems);
     $this->getCache()->deleteAll('/^invoice/');
     return $invoiceId;
 }
예제 #6
0
 /**
  * index
  */
 public function index()
 {
     $orders = $this->orderModel->getOrders();
     foreach ($orders as $order) {
         if ($order['order_status_id'] == 2) {
             $fullOrder = $this->orderModel->getOrder($order['order_id']);
             $this->data['open_orders'][] = array('date_added' => $order['date_added'], 'order_id' => $order['order_id'], 'order_items_quantity' => $this->orderModel->getTotalOrderProductsByOrderId($order['order_id']), 'orderTotal' => $this->currency->format($order['total']), 'shipping_address' => sprintf("%s %s<br />%s<br />%s<br />%s<br />%s<br />%s<br />%s", $fullOrder['shipping_firstname'], $fullOrder['shipping_lastname'], $fullOrder['shipping_company'], $fullOrder['shipping_address_1'], $fullOrder['shipping_address_2'], $fullOrder['shipping_postcode'], $fullOrder['shipping_city'], $fullOrder['shipping_country']), 'shipping_method' => ShippingMethodDAO::getInstance()->getMethod(explode('.', $fullOrder['shipping_method'])[0])->getName());
         }
     }
     $templateFileName = '/template/checkout/options.tpl';
     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . $templateFileName)) {
         $this->template = $this->config->get('config_template') . $templateFileName;
     } else {
         $this->template = 'default' . $templateFileName;
     }
     $json['output'] = $this->render();
     //$this->log->write(print_r($json, true));
     $this->getResponse()->setOutput(json_encode($json));
 }
예제 #7
0
 public function index()
 {
     $this->load->language('extension/shipping');
     $this->document->setTitle($this->language->get('heading_title'));
     $this->data['breadcrumbs'] = array();
     $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'), 'separator' => false);
     $this->data['breadcrumbs'][] = array('text' => $this->language->get('heading_title'), 'href' => $this->url->link('extension/shipping', 'token=' . $this->session->data['token'], 'SSL'), 'separator' => ' :: ');
     $this->data['heading_title'] = $this->language->get('heading_title');
     $this->data['text_no_results'] = $this->language->get('text_no_results');
     $this->data['text_confirm'] = $this->language->get('text_confirm');
     $this->data['column_name'] = $this->language->get('column_name');
     $this->data['column_status'] = $this->language->get('column_status');
     $this->data['column_sort_order'] = $this->language->get('column_sort_order');
     $this->data['column_action'] = $this->language->get('column_action');
     if (isset($this->session->data['success'])) {
         $this->data['success'] = $this->session->data['success'];
         unset($this->session->data['success']);
     } else {
         $this->data['success'] = '';
     }
     if (isset($this->session->data['error'])) {
         $this->data['error'] = $this->session->data['error'];
         unset($this->session->data['error']);
     } else {
         $this->data['error'] = '';
     }
     $this->load->model('setting/extension');
     $extensions = \model\setting\ExtensionDAO::getInstance()->getExtensions('shipping', true, false);
     foreach ($extensions as $key => $value) {
         if (!file_exists(DIR_APPLICATION . 'controller/shipping/' . $value->getCode() . '.php')) {
             \model\setting\ExtensionDAO::getInstance()->uninstall('shipping', $value->getCode());
             unset($extensions[$key]);
         }
     }
     $this->data['extensions'] = array();
     $files = glob(DIR_APPLICATION . 'controller/shipping/*.php');
     //        $this->log->write(print_r($files, true));
     if ($files) {
         foreach ($files as $file) {
             $extensionFileName = basename($file, '.php');
             //$this->load->language('shipping/' . $extension);
             $action = array();
             $installed = false;
             foreach ($extensions as $extension) {
                 if ($extension->getCode() == $extensionFileName) {
                     $installed = true;
                     break;
                 }
             }
             if (!$installed) {
                 $action[] = array('text' => $this->language->get('text_install'), 'href' => $this->url->link('extension/shipping/install', 'token=' . $this->session->data['token'] . '&extension=' . $extensionFileName, 'SSL'));
             } else {
                 $action[] = array('text' => $this->language->get('text_edit'), 'href' => $this->url->link('shipping/' . $extensionFileName . '', 'token=' . $this->session->data['token'], 'SSL'));
                 $action[] = array('text' => $this->language->get('text_uninstall'), 'href' => $this->url->link('extension/shipping/uninstall', 'token=' . $this->session->data['token'] . '&extension=' . $extensionFileName, 'SSL'));
             }
             $shippingMethod = ShippingMethodDAO::getInstance()->getMethod($extensionFileName);
             $this->data['extensions'][] = array('name' => $shippingMethod->getName(), 'status' => $shippingMethod->isEnabled() ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), 'sort_order' => $shippingMethod->getSortOrder(), 'action' => $action);
         }
         //            $this->log->write(print_r($this->data['extensions'], true));
     }
     $this->template = 'extension/shipping.tpl';
     $this->children = array('common/header', 'common/footer');
     $this->getResponse()->setOutput($this->render());
 }
 public function index()
 {
     if (!$this->cart->hasShipping()) {
         return;
     }
     $this->language->load('checkout/simplecheckout');
     $this->data['address_empty'] = false;
     $address = $this->simple->shipping_address;
     $address_fields = $this->simple->shipping_address_fields;
     $reload = explode(',', $this->config->get('simple_set_for_reload'));
     if ($address['country_id'] == '' && in_array('main_country_id', $reload) && !empty($address_fields['main_country_id']) && $address_fields['main_country_id']['type'] != 'hidden') {
         $this->data['address_empty'] = true;
     }
     if ($address['zone_id'] === '' && in_array('main_zone_id', $reload) && !empty($address_fields['main_zone_id']) && $address_fields['main_zone_id']['type'] != 'hidden') {
         $this->data['address_empty'] = true;
     }
     if ($address['city'] == '' && in_array('main_city', $reload) && !empty($address_fields['main_city']) && $address_fields['main_city']['type'] != 'hidden') {
         $this->data['address_empty'] = true;
     }
     if ($address['postcode'] == '' && in_array('main_postcode', $reload) && !empty($address_fields['main_postcode']) && $address_fields['main_postcode']['type'] != 'hidden') {
         $this->data['address_empty'] = true;
     }
     $this->data['simple_debug'] = $this->config->get('simple_debug');
     $this->data['address'] = $address;
     $this->data['simple_shipping_view_title'] = $this->config->get('simple_shipping_view_title');
     $this->data['simple_shipping_view_address_empty'] = $this->config->get('simple_shipping_view_address_empty');
     $simple_shipping_view_address_full = $this->config->get('simple_shipping_view_address_full');
     $simple_shipping_view_autoselect_first = $this->config->get('simple_shipping_methods_hide') ? true : $this->config->get('simple_shipping_view_autoselect_first');
     $simple_shipping_methods_hide = $this->config->get('simple_shipping_methods_hide');
     if ($this->customer->isLogged()) {
         $customer_group_id = $this->customer->getCustomerGroupId();
     } else {
         $customer_group_id = $this->config->get('config_customer_group_id');
     }
     if ($this->config->get('simple_customer_view_customer_type')) {
         $customer_groups = $this->simple->get_customer_groups();
         if (isset($this->request->post['customer_group_id']) && array_key_exists($this->request->post['customer_group_id'], $customer_groups)) {
             $customer_group_id = $this->request->post['customer_group_id'];
         }
     }
     $filter_methods = array();
     $simple_group_shipping = $this->config->get('simple_group_shipping');
     if (!empty($simple_group_shipping[$customer_group_id])) {
         $filter_methods = explode(',', $simple_group_shipping[$customer_group_id]);
     }
     $this->data['shipping_methods'] = array();
     $quote_data = array();
     $this->load->model('setting/extension');
     $results = \model\setting\ExtensionDAO::getInstance()->getExtensions('shipping');
     $simple_shipping_titles = $this->config->get('simple_shipping_titles');
     $simple_links = $this->config->get('simple_links_2');
     $simple_links = !empty($simple_links) && is_array($simple_links) ? $simple_links : array();
     $payment_method_code = false;
     if ($this->config->get('simple_childs_payment_first')) {
         $payment_method = $this->simple->payment_method;
         $payment_method_code = !empty($payment_method['code']) ? $payment_method['code'] : false;
     }
     foreach ($results as $result) {
         $show_module = true;
         if ($this->data['address_empty'] && !empty($simple_shipping_view_address_full[$result['code']])) {
             $show_module = false;
         }
         if (is_array($filter_methods) && !empty($filter_methods)) {
             if (in_array($result['code'], $filter_methods)) {
                 $show_module = true;
             } else {
                 $show_module = false;
             }
         }
         if ($this->config->get($result['code'] . '_status') && $show_module) {
             $for_payment_methods = array();
             if ($this->config->get('simple_childs_payment_first') && !empty($simple_links[$result['code']])) {
                 $for_payment_methods = explode(",", $simple_links[$result['code']]);
             }
             if (empty($for_payment_methods) || $payment_method_code && in_array($payment_method_code, $for_payment_methods)) {
                 $quote = ShippingMethodDAO::getInstance()->getMethod($result['code'])->getQuote($address);
                 if ($quote) {
                     $quote_data[$result['code']] = array('title' => $quote['title'], 'quote' => $quote['quote'], 'sort_order' => $quote['sort_order'], 'error' => $quote['error'], 'warning' => isset($quote['warning']) ? $quote['warning'] : '', 'description' => !empty($simple_shipping_titles[$result['code']]['use_description']) && !empty($simple_shipping_titles[$result['code']]['description'][$this->simple->get_language_code()]) ? html_entity_decode($simple_shipping_titles[$result['code']]['description'][$this->simple->get_language_code()]) : '');
                 }
             }
         }
     }
     $sort_order = array();
     foreach ($quote_data as $key => $value) {
         $sort_order[$key] = $value['sort_order'];
     }
     array_multisort($sort_order, SORT_ASC, $quote_data);
     $this->data['shipping_methods'] = $quote_data;
     $this->data['shipping_method'] = null;
     $this->data['error_warning'] = '';
     $this->data['checked_code'] = '';
     $this->data['disabled_methods'] = array();
     if (!empty($simple_shipping_titles)) {
         foreach ($simple_shipping_titles as $key => $value) {
             if (!array_key_exists($key, $this->data['shipping_methods']) && !empty($value['show']) && ($value['show'] == 1 || $value['show'] == 2 && $this->data['address_empty'])) {
                 $this->data['disabled_methods'][$key]['title'] = !empty($value['title'][$this->simple->get_language_code()]) ? html_entity_decode($value['title'][$this->simple->get_language_code()]) : $key;
                 $this->data['disabled_methods'][$key]['description'] = !empty($value['description'][$this->simple->get_language_code()]) ? html_entity_decode($value['description'][$this->simple->get_language_code()]) : '';
             }
         }
     }
     if ($this->request->server['REQUEST_METHOD'] == 'POST' && !empty($this->request->post['shipping_method_checked'])) {
         $shipping = explode('.', $this->request->post['shipping_method_checked']);
         if (isset($this->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]])) {
             $this->data['checked_code'] = $this->request->post['shipping_method_checked'];
         }
     }
     if ($this->request->server['REQUEST_METHOD'] == 'POST' && isset($this->request->post['shipping_method'])) {
         $shipping = explode('.', $this->request->post['shipping_method']);
         if (isset($this->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]])) {
             $this->data['shipping_method'] = $this->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]];
             if (isset($this->request->post['shipping_method_current']) && $this->request->post['shipping_method_current'] != $this->request->post['shipping_method']) {
                 $this->data['checked_code'] = $this->request->post['shipping_method'];
             }
         }
     }
     if ($this->request->server['REQUEST_METHOD'] == 'GET' && (isset($this->session->data['shipping_method']) || isset($this->request->cookie['shipping_method']))) {
         $user_checked = false;
         if (isset($this->session->data['shipping_method'])) {
             $shipping = explode('.', $this->session->data['shipping_method']['code']);
             $user_checked = true;
         } elseif (isset($this->request->cookie['shipping_method'])) {
             $shipping = explode('.', $this->request->cookie['shipping_method']);
         }
         if (isset($this->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]])) {
             $this->data['shipping_method'] = $this->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]];
             if ($user_checked) {
                 $this->data['checked_code'] = $this->session->data['shipping_method']['code'];
             }
         }
     }
     if (!empty($this->data['shipping_methods'])) {
         $first = reset($this->data['shipping_methods']);
         if (!empty($first['quote'])) {
             $first_method = reset($first['quote']);
         }
     }
     if (!empty($first_method) && ($simple_shipping_methods_hide || $simple_shipping_view_autoselect_first && $this->data['checked_code'] == '')) {
         $this->data['shipping_method'] = $first_method;
     }
     if (isset($this->data['shipping_method'])) {
         setcookie('shipping_method', $this->data['shipping_method']['code'], time() + 60 * 60 * 24 * 30);
     }
     $this->data['code'] = !empty($this->data['shipping_method']) ? $this->data['shipping_method']['code'] : '';
     $this->simple->shipping_methods = $this->data['shipping_methods'];
     $this->simple->shipping_method = $this->data['shipping_method'];
     $this->data['simple_show_errors'] = !empty($this->request->post['simple_create_order']) || !empty($this->request->post['simple_step_next']) && !empty($this->request->post['simple_step']) && $this->request->post['simple_step'] == 'simplecheckout_shipping';
     $this->validate();
     $this->save_to_session();
     $this->data['text_checkout_shipping_method'] = $this->language->get('text_checkout_shipping_method');
     $this->data['text_shipping_address'] = $this->language->get('text_shipping_address');
     $this->data['error_no_shipping'] = sprintf($this->language->get('error_no_shipping'), $this->url->link('information/contact'));
     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/simplecheckout_shipping.tpl')) {
         $this->template = $this->config->get('config_template') . '/template/checkout/simplecheckout_shipping.tpl';
     } else {
         $this->template = 'default/template/checkout/simplecheckout_shipping.tpl';
     }
     $this->response->setOutput($this->render());
 }
예제 #9
0
 private function getShippingCost($shipping_method, $orderItems, $ext = array())
 {
     $shipping_method = explode(".", $shipping_method);
     //		$this->load->model("shipping/" . $shipping_method[0]);
     return ShippingMethodDAO::getInstance()->getMethod($shipping_method[0])->getCost($shipping_method[1], $orderItems, $ext);
 }
예제 #10
0
 public function quote()
 {
     $this->language->load('total/shipping');
     $json = array();
     if (!$this->cart->hasProducts()) {
         $json['redirect'] = $this->url->link('checkout/cart');
     }
     if (isset($this->request->post['country_id']) && isset($this->request->post['zone_id']) && isset($this->request->post['postcode'])) {
         if ($this->request->post['country_id'] == '') {
             $json['error']['country'] = $this->language->get('error_country');
         }
         if ($this->request->post['zone_id'] == '') {
             $json['error']['zone'] = $this->language->get('error_zone');
         }
         $this->load->model('localisation/country');
         $country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']);
         if ($country_info && $country_info['postcode_required'] && utf8_strlen($this->request->post['postcode']) < 2 || utf8_strlen($this->request->post['postcode']) > 10) {
             $json['error']['postcode'] = $this->language->get('error_postcode');
         }
         if (!isset($json['error'])) {
             $this->tax->setShippingAddress($this->request->post['country_id'], $this->request->post['zone_id']);
             $this->session->data['guest']['shipping']['country_id'] = $this->request->post['country_id'];
             $this->session->data['guest']['shipping']['zone_id'] = $this->request->post['zone_id'];
             $this->session->data['guest']['shipping']['postcode'] = $this->request->post['postcode'];
             if ($country_info) {
                 $country = $country_info['name'];
                 $iso_code_2 = $country_info['iso_code_2'];
                 $iso_code_3 = $country_info['iso_code_3'];
                 $address_format = $country_info['address_format'];
             } else {
                 $country = '';
                 $iso_code_2 = '';
                 $iso_code_3 = '';
                 $address_format = '';
             }
             $this->load->model('localisation/zone');
             $zone_info = $this->model_localisation_zone->getZone($this->request->post['zone_id']);
             if ($zone_info) {
                 $zone = $zone_info['name'];
                 $code = $zone_info['code'];
             } else {
                 $zone = '';
                 $code = '';
             }
             $address_data = array('firstname' => '', 'lastname' => '', 'company' => '', 'address_1' => '', 'address_2' => '', 'postcode' => $this->request->post['postcode'], 'city' => '', 'zone_id' => $this->request->post['zone_id'], 'zone' => $zone, 'zone_code' => $code, 'country_id' => $this->request->post['country_id'], 'country' => $country, 'iso_code_2' => $iso_code_2, 'iso_code_3' => $iso_code_3, 'address_format' => $address_format);
             $quote_data = array();
             $this->load->model('setting/extension');
             $results = \model\setting\ExtensionDAO::getInstance()->getExtensions('shipping');
             foreach ($results as $result) {
                 if ($this->config->get($result->getCode() . '_status')) {
                     $quote = ShippingMethodDAO::getInstance()->getMethod($result->getCode())->getQuote($address_data);
                     if ($quote) {
                         $quote_data[$result->getCode()] = array('title' => $quote['title'], 'quote' => $quote['quote'], 'sort_order' => $quote['sort_order'], 'error' => $quote['error']);
                     }
                 }
             }
             $sort_order = array();
             foreach ($quote_data as $key => $value) {
                 $sort_order[$key] = $value['sort_order'];
             }
             array_multisort($sort_order, SORT_ASC, $quote_data);
             $this->session->data['shipping_methods'] = $quote_data;
             if (isset($this->session->data['shipping_methods'])) {
                 $json['shipping_methods'] = $this->session->data['shipping_methods'];
             }
             if (!isset($this->session->data['shipping_methods']) || !$this->session->data['shipping_methods']) {
                 $json['error']['warning'] = sprintf($this->language->get('error_no_shipping'), $this->url->link('information/contact'));
             }
         }
     }
     $this->getResponse()->setOutput(json_encode($json));
 }
예제 #11
0
 public function index()
 {
     if (!$this->cart->hasProducts() && (!isset($this->session->data['vouchers']) || !$this->session->data['vouchers']) || !$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) {
         $json['redirect'] = $this->url->link('checkout/cart');
     }
     $this->load->model('account/address');
     if ($this->cart->hasShipping()) {
         $this->load->model('account/address');
         if ($this->customer->isLogged()) {
             $shippingAddress = $this->model_account_address->getAddress($this->session->data['shipping_address_id']);
         } elseif (isset($this->session->data['guest'])) {
             $shippingAddress = $this->session->data['guest']['shipping'];
         }
         if (!isset($shippingAddress)) {
             $json['redirect'] = $this->url->link('checkout/checkout', '', 'SSL');
         }
         if (!isset($this->session->data['shipping_method'])) {
             $json['redirect'] = $this->url->link('checkout/checkout', '', 'SSL');
         }
     } else {
         unset($this->session->data['guest']['shipping']);
         unset($this->session->data['shipping_address_id']);
         unset($this->session->data['shipping_method']);
         unset($this->session->data['shipping_methods']);
     }
     $json = array();
     if (!$json) {
         $total_data = array();
         $total = 0;
         $taxes = $this->cart->getTaxes(true);
         $this->modelCheckoutOrder->getTotals($total_data, $total, $taxes, null, true);
         //
         //			$this->load->model('setting/extension');
         //
         //			$sort_order = array();
         //
         //			$results = \model\setting\ExtensionDAO::getInstance()->getExtensions('total');
         //
         //			foreach ($results as $key => $value) {
         //				$sort_order[$key] = $this->config->get($value['code'] . '_sort_order');
         //			}
         //
         //			array_multisort($sort_order, SORT_ASC, $results);
         //
         //			foreach ($results as $result) {
         //				if ($this->config->get($result['code'] . '_status')) {
         //					$this->load->model('total/' . $result['code']);
         //
         //					$this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes, true);
         //				}
         //			}
         //
         //			$sort_order = array();
         //
         //			foreach ($total_data as $key => $value) {
         //				$sort_order[$key] = $value['sort_order'];
         //			}
         //
         //			array_multisort($sort_order, SORT_ASC, $total_data);
         $this->language->load('checkout/checkout');
         $data = array();
         $data['invoice_prefix'] = $this->config->get('config_invoice_prefix');
         $data['store_id'] = $this->config->get('config_store_id');
         $data['store_name'] = $this->config->get('config_name');
         if ($data['store_id']) {
             $data['store_url'] = $this->config->get('config_url');
         } else {
             $data['store_url'] = HTTP_SERVER;
         }
         if ($this->customer->isLogged()) {
             $data['customer_id'] = $this->customer->getId();
             $data['customer_group_id'] = $this->customer->getCustomerGroupId();
             $data['firstname'] = $this->customer->getFirstName();
             $data['lastname'] = $this->customer->getLastName();
             $data['email'] = $this->customer->getEmail();
             $data['telephone'] = $this->customer->getTelephone();
             $data['fax'] = $this->customer->getFax();
             $this->load->model('account/address');
             //$payment_address = $this->model_account_address->getAddress($this->session->data['payment_address_id']);
         } elseif (isset($this->session->data['guest'])) {
             $data['customer_id'] = 0;
             $data['customer_group_id'] = $this->config->get('config_customer_group_id');
             $data['firstname'] = $this->session->data['guest']['firstname'];
             $data['lastname'] = $this->session->data['guest']['lastname'];
             $data['email'] = $this->session->data['guest']['email'];
             $data['telephone'] = $this->session->data['guest']['telephone'];
             $data['fax'] = $this->session->data['guest']['fax'];
             //				$payment_address = $this->session->data['guest']['payment'];
         }
         if (isset($this->session->data['payment_method']['title'])) {
             $data['payment_method'] = $this->session->data['payment_method']['title'];
         } else {
             $data['payment_method'] = '';
         }
         if ($this->cart->hasShipping()) {
             $shippingAddress = [];
             if ($this->customer->isLogged()) {
                 $this->load->model('account/address');
                 $shippingAddress = $this->model_account_address->getAddress($this->session->data['shipping_address_id']);
             } elseif (isset($this->session->data['guest'])) {
                 $shippingAddress = $this->session->data['guest']['shipping'];
             }
             try {
                 $shippingMethod = explode('.', $this->session->data['shipping_method']['code']);
                 $shippingAddress = array_merge($shippingAddress, ShippingMethodDAO::getInstance()->getMethod($shippingMethod[0])->getAddress($shippingMethod[1]));
             } catch (Exception $exc) {
             }
             $data['shipping_firstname'] = $shippingAddress['firstname'];
             $data['shipping_lastname'] = $shippingAddress['lastname'];
             $data['shipping_company'] = $shippingAddress['company'];
             $data['shipping_phone'] = $shippingAddress['phone'];
             $data['shipping_address_1'] = $shippingAddress['address_1'];
             $data['shipping_address_2'] = $shippingAddress['address_2'];
             $data['shipping_city'] = $shippingAddress['city'];
             $data['shipping_postcode'] = $shippingAddress['postcode'];
             $data['shipping_zone'] = $shippingAddress['zone'];
             $data['shipping_zone_id'] = $shippingAddress['zone_id'];
             $data['shipping_country'] = $shippingAddress['country'];
             $data['shipping_country_id'] = $shippingAddress['country_id'];
             $data['shipping_address_format'] = $shippingAddress['address_format'];
             if (isset($this->session->data['shipping_method']['title'])) {
                 //$this->log->write(print_r($this->session->data['shipping_method'], true));
                 //$data['shipping_method'] = $this->session->data['shipping_method']['title'];
                 $data['shipping_method'] = $this->session->data['shipping_method']['code'];
             } else {
                 $data['shipping_method'] = '';
             }
         } else {
             $data['shipping_firstname'] = '';
             $data['shipping_lastname'] = '';
             $data['shipping_company'] = '';
             $data['shipping_phone'] = '';
             $data['shipping_address_1'] = '';
             $data['shipping_address_2'] = '';
             $data['shipping_city'] = '';
             $data['shipping_postcode'] = '';
             $data['shipping_zone'] = '';
             $data['shipping_zone_id'] = '';
             $data['shipping_country'] = '';
             $data['shipping_country_id'] = '';
             $data['shipping_address_format'] = '';
             $data['shipping_method'] = '';
         }
         $this->load->library('encryption');
         $product_data = array();
         foreach ($this->cart->getProducts(true) as $product) {
             $option_data = array();
             foreach ($product['option'] as $option) {
                 if ($option['type'] != 'file') {
                     $option_data[] = array('product_option_id' => $option['product_option_id'], 'product_option_value_id' => $option['product_option_value_id'], 'option_id' => $option['option_id'], 'option_value_id' => $option['option_value_id'], 'name' => $option['name'], 'value' => $option['option_value'], 'type' => $option['type']);
                 } else {
                     $encryption = new Encryption($this->config->get('config_encryption'));
                     $option_data[] = array('product_option_id' => $option['product_option_id'], 'product_option_value_id' => $option['product_option_value_id'], 'option_id' => $option['option_id'], 'option_value_id' => $option['option_value_id'], 'name' => $option['name'], 'value' => $encryption->decrypt($option['option_value']), 'type' => $option['type']);
                 }
             }
             $product_data[] = array('product_id' => $product['product_id'], 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'download' => $product['download'], 'quantity' => $product['quantity'], 'subtract' => $product['subtract'], 'price' => $product['price'], 'total' => $product['total'], 'tax' => $this->tax->getTax($product['total'], $product['tax_class_id']));
         }
         // Gift Voucher
         if (isset($this->session->data['vouchers']) && $this->session->data['vouchers']) {
             foreach ($this->session->data['vouchers'] as $voucher) {
                 $product_data[] = array('product_id' => 0, 'name' => $voucher['description'], 'model' => '', 'option' => array(), 'download' => array(), 'quantity' => 1, 'subtract' => false, 'price' => $voucher['amount'], 'total' => $voucher['amount'], 'tax' => 0);
             }
         }
         $data['products'] = $product_data;
         $data['totals'] = $total_data;
         $data['comment'] = $this->session->data['comment'];
         $data['total'] = $total;
         $data['reward'] = $this->cart->getTotalRewardPoints(true);
         $this->customer->setAffiliateId();
         $data['affiliate_id'] = $this->customer->getAffiliateId();
         $data['commission'] = 0;
         $data['language_id'] = $this->config->get('config_language_id');
         $data['currency_id'] = $this->currency->getId();
         $data['currency_code'] = $this->currency->getCode();
         $data['currency_value'] = $this->currency->getValue($this->currency->getCode());
         $data['ip'] = $this->request->server['REMOTE_ADDR'];
         $this->session->data['order_id'] = $this->modelCheckoutOrder->create($data);
         // Gift Voucher
         if (isset($this->session->data['vouchers']) && is_array($this->session->data['vouchers'])) {
             $this->load->model('checkout/voucher');
             foreach ($this->session->data['vouchers'] as $voucher) {
                 $this->model_checkout_voucher->addVoucher($this->session->data['order_id'], $voucher);
             }
         }
         $this->data['column_name'] = $this->language->get('column_name');
         $this->data['column_model'] = $this->language->get('column_model');
         $this->data['column_quantity'] = $this->language->get('column_quantity');
         $this->data['column_price'] = $this->language->get('column_price');
         $this->data['column_total'] = $this->language->get('column_total');
         $this->data['products'] = array();
         foreach ($this->cart->getProducts(true) as $product) {
             $option_data = array();
             foreach ($product['option'] as $option) {
                 if ($option['type'] != 'file') {
                     $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($option['option_value']));
                 } else {
                     $this->load->library('encryption');
                     $encryption = new Encryption($this->config->get('config_encryption'));
                     $file = substr($encryption->decrypt($option['option_value']), 0, strrpos($encryption->decrypt($option['option_value']), '.'));
                     $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($file));
                 }
             }
             $this->data['products'][] = array('product_id' => $product['product_id'], 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'subtract' => $product['subtract'], 'tax' => $this->tax->getTax($product['total'], $product['tax_class_id']), 'price' => $this->currency->format($product['price']), 'total' => $this->currency->format($product['total']), 'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']));
         }
         // Gift Voucher
         $this->data['vouchers'] = array();
         if (isset($this->session->data['vouchers']) && $this->session->data['vouchers']) {
             foreach ($this->session->data['vouchers'] as $key => $voucher) {
                 $this->data['vouchers'][] = array('description' => $voucher['description'], 'amount' => $this->currency->format($voucher['amount']));
             }
         }
         $this->data['totals'] = $total_data;
         $this->data['payment'] = $this->getChild('payment/' . $this->getSession()->data['payment_method']['code']);
         $this->data['button_confirm'] = $this->language->get('button_confirm');
         $this->data['urlConfirm'] = $this->url->link('checkout/confirm/confirm', '', 'SSL');
         $this->data['continue'] = $this->url->link('checkout/success');
         $templateName = '/template/checkout/confirm.tpl.php';
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . $templateName)) {
             $this->template = $this->config->get('config_template') . $templateName;
         } else {
             $this->template = 'default' . $templateName;
         }
         $json['output'] = $this->render();
     }
     //		$this->log->write(print_r($json, true));
     $this->getResponse()->setOutput(json_encode($json));
 }
예제 #12
0
 public function index()
 {
     //        $this->log->write("Opening checkout/shipping");
     $this->language->load('checkout/checkout');
     $json = array();
     $this->load->model('account/address');
     if ($this->customer->isLogged()) {
         $shipping_address = $this->model_account_address->getAddress($this->session->data['shipping_address_id']);
     } elseif (isset($this->session->data['guest'])) {
         $shipping_address = $this->session->data['guest']['shipping'];
     }
     if (empty($shipping_address)) {
         $json['redirect'] = $this->url->link('checkout/checkout', '', 'SSL');
     }
     if (!$this->cart->hasProducts() && (!isset($this->session->data['vouchers']) || !$this->session->data['vouchers']) || !$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) {
         $json['redirect'] = $this->url->link('checkout/cart');
     }
     if ($this->request->server['REQUEST_METHOD'] == 'POST') {
         if (!$json) {
             if (!isset($this->request->post['shipping_method'])) {
                 $json['error']['warning'] = $this->language->get('error_shipping');
             } else {
                 $shipping = explode('.', $this->request->post['shipping_method']);
                 if (!isset($this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]])) {
                     $json['error']['warning'] = $this->language->get('error_shipping');
                 }
             }
         }
         if (!$json) {
             $shipping = explode('.', $this->request->post['shipping_method']);
             $this->session->data['shipping_method'] = $this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]];
             $this->session->data['comment'] = strip_tags($this->request->post['comment']);
         }
     } else {
         if (isset($shipping_address)) {
             if (!isset($this->session->data['shipping_methods'])) {
                 $quote_data = array();
                 $this->load->model('setting/extension');
                 $this->load->model('localisation/description');
                 $results = \model\setting\ExtensionDAO::getInstance()->getExtensions('shipping');
                 $this->log->write(print_r($results, true));
                 //print_r($results); die();
                 foreach ($results as $result) {
                     $shippingMethod = ShippingMethodDAO::getInstance()->getMethod($result->getCode());
                     if ($shippingMethod->isEnabled()) {
                         //						if ($this->config->get($result['code'] . '_status')) {
                         //                            $this->log->write("Trying to load shipping/" . $result['code']);
                         //							$this->load->model('shipping/' . $result['code']);
                         $quote = $shippingMethod->getQuote($shipping_address);
                         //                            $this->log->write(print_r($quote, true));
                         if ($quote) {
                             //$res = $this->model_localisation_description->getDescription(null, $quote['quote'][$result['code']]['title']);
                             //$tempArr = reset($quote['quote']);
                             //$desc = '' . print_r($tempArr[@description], true);
                             //print_r($quote['quote']); die();
                             $quote_data[$result->getCode()] = array('title' => $quote['title'], 'quote' => $quote['quote'], 'sort_order' => $quote['sort_order'], 'error' => $quote['error']);
                         }
                     }
                 }
                 $sort_order = array();
                 foreach ($quote_data as $key => $value) {
                     $sort_order[$key] = $value['sort_order'];
                 }
                 array_multisort($sort_order, SORT_ASC, $quote_data);
                 //print_r($quote_data); die();
                 $this->session->data['shipping_methods'] = $quote_data;
             }
         }
         $this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
         $this->data['text_comments'] = $this->language->get('text_comments');
         $this->data['button_continue'] = $this->language->get('button_continue');
         if (isset($this->session->data['shipping_methods']) && !$this->session->data['shipping_methods']) {
             $this->data['error_warning'] = sprintf($this->language->get('error_no_shipping'), $this->url->link('information/contact'));
         } else {
             $this->data['error_warning'] = '';
         }
         if (isset($this->session->data['shipping_methods'])) {
             $this->data['shipping_methods'] = $this->session->data['shipping_methods'];
         } else {
             $this->data['shipping_methods'] = array();
         }
         if (isset($this->session->data['shipping_method']['code'])) {
             $this->data['code'] = $this->session->data['shipping_method']['code'];
         } else {
             $this->data['code'] = '';
         }
         if (isset($this->session->data['comment'])) {
             $this->data['comment'] = $this->session->data['comment'];
         } else {
             $this->data['comment'] = '';
         }
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/shipping.tpl.php')) {
             $this->template = $this->config->get('config_template') . '/template/checkout/shipping.tpl.php';
         } else {
             $this->template = 'default/template/checkout/shipping.tpl.php';
         }
         $json['output'] = $this->render();
     }
     //$this->log->write(print_r($json, true));
     $this->getResponse()->setOutput(json_encode($json));
 }
예제 #13
0
 public function info()
 {
     if (isset($this->session->data['note'])) {
         $this->data['note'] = $this->session->data['note'];
         unset($this->session->data['note']);
     } else {
         $this->data['note'] = '';
     }
     $this->modelToolImage = $this->load->model('tool/image');
     if (isset($this->request->get['order_id'])) {
         $order_id = $this->request->get['order_id'];
     } else {
         $order_id = 0;
     }
     if (!$this->customer->isLogged()) {
         $this->session->data['redirect'] = $this->url->link('account/order/info', 'order_id=' . $order_id, 'SSL');
         $this->redirect($this->url->link('account/login', '', 'SSL'));
     }
     $this->language->load('account/order');
     $this->load->model('account/order');
     $order_info = $this->model_account_order->getOrder($order_id);
     if ($order_info) {
         $orderItems = OrderItemDAO::getInstance()->getOrderItems(array('filterOrderId' => $order_id), null, true);
         if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) {
             if ($this->request->post['action'] == 'reorder') {
                 foreach ($orderItems as $orderItem) {
                     if (in_array($orderItem->getId(), $this->request->post['selected'])) {
                         $option_data = array();
                         $order_options = $this->model_account_order->getOrderOptions($order_id, $orderItem->getId());
                         foreach ($order_options as $order_option) {
                             if ($order_option['type'] == 'select' || $order_option['type'] == 'radio') {
                                 $option_data[$order_option['product_option_id']] = $order_option['product_option_value_id'];
                             } elseif ($order_option['type'] == 'checkbox') {
                                 $option_data[$order_option['product_option_id']][] = $order_option['product_option_value_id'];
                             } elseif ($order_option['type'] == 'input' || $order_option['type'] == 'textarea' || $order_option['type'] == 'file' || $order_option['type'] == 'date' || $order_option['type'] == 'datetime' || $order_option['type'] == 'time') {
                                 $option_data[$order_option['product_option_id']] = $order_option['value'];
                             }
                         }
                         $this->cart->add($orderItem->getProductId(), $orderItem->getQuantity(), $option_data);
                     }
                 }
                 $this->redirect($this->url->link('checkout/cart', '', 'SSL'));
             }
         }
         $this->setBreadcrumbs();
         $url = '';
         if (isset($this->request->get['page'])) {
             $url .= '&page=' . $this->request->get['page'];
         }
         $this->data['text_order_detail'] = $this->language->get('text_order_detail');
         $this->data['text_invoice_no'] = $this->language->get('text_invoice_no');
         $this->data['text_order_id'] = $this->language->get('text_order_id');
         $this->data['text_date_added'] = $this->language->get('text_date_added');
         $this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
         $this->data['text_shipping_address'] = $this->language->get('text_shipping_address');
         $this->data['text_payment_method'] = $this->language->get('text_payment_method');
         $this->data['text_payment_address'] = $this->language->get('text_payment_address');
         $this->data['text_history'] = $this->language->get('text_history');
         $this->data['text_comment'] = $this->language->get('text_comment');
         $this->data['text_action'] = $this->language->get('text_action');
         $this->data['text_selected'] = $this->language->get('text_selected');
         $this->data['text_reorder'] = $this->language->get('text_reorder');
         $this->data['text_return'] = $this->language->get('text_return');
         $this->data['textAction'] = $this->language->get('ACTION');
         $this->data['textComment'] = $this->language->get('COMMENT');
         $this->data['textOrderItemId'] = $this->language->get('ORDER_ITEM_ID');
         $this->data['textOrderItemImage'] = $this->language->get('IMAGE');
         $this->data['column_name'] = $this->language->get('column_name');
         $this->data['column_model'] = $this->language->get('column_model');
         $this->data['column_quantity'] = $this->language->get('column_quantity');
         $this->data['column_price'] = $this->language->get('column_price');
         $this->data['column_total'] = $this->language->get('column_total');
         $this->data['column_date_added'] = $this->language->get('column_date_added');
         $this->data['column_status'] = $this->language->get('column_status');
         $this->data['button_continue'] = $this->language->get('button_continue');
         $this->data['button_invoice'] = $this->language->get('button_invoice');
         if (isset($this->error['warning'])) {
             $this->data['error_warning'] = $this->error['warning'];
         } else {
             $this->data['error_warning'] = '';
         }
         $this->data['action'] = $this->url->link('account/order/info', 'order_id=' . $this->request->get['order_id'], 'SSL');
         if ($order_info['invoice_no']) {
             $this->data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no'];
         } else {
             $this->data['invoice_no'] = '';
         }
         $this->data['order_id'] = $this->request->get['order_id'];
         $this->data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
         if ($order_info['shipping_address_format']) {
             $format = $order_info['shipping_address_format'];
         } else {
             $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
         }
         $find = array('{firstname}', '{lastname}', '{company}', '{address_1}', '{address_2}', '{city}', '{postcode}', '{zone}', '{zone_code}', '{country}');
         $replace = 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'], 'zone_code' => $order_info['shipping_zone_code'], 'country' => $order_info['shipping_country']);
         $this->data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\\s\\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
         $this->data['shipping_method'] = ShippingMethodDAO::getInstance()->getMethod(explode('.', $order_info['shipping_method'])[0])->getName();
         if ($order_info['payment_address_format']) {
             $format = $order_info['payment_address_format'];
         } else {
             $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
         }
         $find = array('{firstname}', '{lastname}', '{company}', '{address_1}', '{address_2}', '{city}', '{postcode}', '{zone}', '{zone_code}', '{country}');
         $replace = 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'], 'zone_code' => $order_info['payment_zone_code'], 'country' => $order_info['payment_country']);
         $this->data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\\s\\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
         $this->data['payment_method'] = $order_info['payment_method'];
         // ----- deposit modules START -----
         $this->data['text_payment_method'] = '';
         $this->load->model('account/multi_pay');
         $this->data['payment_method'] = $this->model_account_multi_pay->order_info($order_info);
         // ----- deposit modules END -----
         $this->data['products'] = array();
         //			$orderItems = OrderItemDAO::getInstance()->getOrderItems(
         //                array('filterOrderId' => $this->request->get['order_id']), null, true
         //            );
         //            $products = $this->model_account_order->getOrderProducts($this->request->get['order_id']);
         foreach ($orderItems as $orderItem) {
             $actions = array();
             if (($orderItem->getStatusId() & 0xffff) <= 2) {
                 $actions[] = array('text' => $this->language->get('CANCEL'), 'href' => $this->url->link('account/orderItems/cancel', 'orderItemId=' . $orderItem->getId() . '&returnUrl=' . urlencode($this->selfUrl)));
             }
             $option_data = array();
             $options = OrderItemDAO::getInstance()->getOptions($orderItem->getId());
             foreach ($options as $option) {
                 if ($option['type'] != 'file') {
                     $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($option['value']));
                 } else {
                     $filename = substr($option['value'], 0, strrpos($option['value'], '.'));
                     $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($filename));
                 }
             }
             $product_image = ProductDAO::getInstance()->getImage($orderItem->getProductId());
             if ($orderItem->getImagePath() == '' || $orderItem->getImagePath() == "data/event/agent-moomidae.jpg") {
                 $options = OrderItemDAO::getInstance()->getOptions($orderItem->getId());
                 $itemUrl = !empty($options[REPURCHASE_ORDER_IMAGE_URL_OPTION_ID]['value']) ? $options[REPURCHASE_ORDER_IMAGE_URL_OPTION_ID]['value'] : '';
                 $orderItem->setImagePath(!empty($itemUrl) ? $itemUrl : $orderItem->getImagePath());
             }
             if ($orderItem->getImagePath() && file_exists(DIR_IMAGE . $orderItem->getImagePath())) {
                 $image = $this->modelToolImage->resize($orderItem->getImagePath(), 100, 100);
             } else {
                 $image = $this->modelToolImage->resize($product_image, 100, 100);
             }
             $this->data['products'][] = array('order_product_id' => $orderItem->getId(), 'actions' => $actions, 'comment' => $orderItem->getPublicComment(), 'name' => $orderItem->getName(), 'model' => $orderItem->getModel(), 'option' => $option_data, 'quantity' => $orderItem->getModel(), 'price' => $this->getCurrency()->format($orderItem->getPrice(true), $order_info['currency_code'], 1), 'total' => $this->getCurrency()->format($orderItem->getTotal(true), $order_info['currency_code'], 1), 'imagePath' => $image, 'item_status' => Status::getStatus($orderItem->getStatusId(), $this->config->get('language_id'), true), 'selected' => false);
         }
         $this->data['totals'] = $this->model_account_order->getOrderTotals($this->request->get['order_id']);
         $this->data['comment'] = $order_info['comment'];
         $this->data['histories'] = array();
         $results = $this->model_account_order->getOrderHistories($this->request->get['order_id']);
         foreach ($results as $result) {
             $this->data['histories'][] = array('date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), 'status' => $result['status'], 'comment' => nl2br($result['comment']));
         }
         $this->data['continue'] = $this->url->link('account/order', '', 'SSL');
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/order_info.tpl.php')) {
             $this->template = $this->config->get('config_template') . '/template/account/order_info.tpl.php';
         } else {
             $this->template = 'default/template/account/order_info.tpl.php';
         }
         $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
         $this->getResponse()->setOutput($this->render());
     } else {
         $this->document->setTitle($this->language->get('text_order'));
         $this->data['heading_title'] = $this->language->get('text_order');
         $this->data['text_error'] = $this->language->get('text_error');
         $this->data['button_continue'] = $this->language->get('button_continue');
         $this->setBreadcrumbs();
         $this->data['continue'] = $this->url->link('account/order', '', 'SSL');
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
             $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
         } else {
             $this->template = 'default/template/error/not_found.tpl';
         }
         $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
         $this->getResponse()->setOutput($this->render());
     }
 }
예제 #14
0
 private function showEditForm()
 {
     if (!$this->parameters['invoiceId']) {
         return;
     }
     $invoice = InvoiceDAO::getInstance()->getInvoice($this->parameters['invoiceId']);
     /// Initialize interface values
     $this->data['button_action'] = $this->language->get('button_close');
     $this->data['readOnly'] = "disabled";
     $this->data['shippingMethods'] = ShippingMethodDAO::getInstance()->getShippingOptions($this->modelReferenceAddress->getAddress($invoice->getShippingAddressId()));
     $orderItemIdParam = '';
     foreach ($invoice->getOrderItems() as $orderItem) {
         $this->data['orderItems'][] = array('id' => $orderItem->getId(), 'comment' => $orderItem->getPublicComment(), 'image_path' => $this->registry->get('model_tool_image')->getImage($orderItem->getImagePath()), 'model' => $orderItem->getModel(), 'name' => $orderItem->getName(), 'options' => OrderItemDAO::getInstance()->getOrderItemOptionsString($orderItem->getId()), 'order_id' => $orderItem->getOrderId(), 'price' => $this->getCurrency()->format($orderItem->getPrice(), $this->getConfig()->get('config_currency')), 'quantity' => $orderItem->getQuantity(), 'subtotal' => $this->getCurrency()->format($orderItem->getTotal(), $this->getConfig()->get('config_currency')), 'subtotalCustomerCurrency' => $this->getCurrency()->format($orderItem->getTotal(true), $orderItem->getCustomer()['base_currency_code'], 1), 'shipping' => $this->getCurrency()->format($orderItem->getShippingCost(), $this->getConfig()->get('config_currency')));
         $orderItemIdParam .= '&orderItemId[]=' . $orderItem->getId();
     }
     foreach ($this->data['orderItems'] as $item) {
         $ids[] = $item['id'];
     }
     if (empty($this->data['orderItems'])) {
         $_invoice = InvoiceDAO::getInstance()->getInvoice($this->parameters['invoiceId']);
         foreach (InvoiceDAO::getInstance()->getInvoiceItems($_invoice['invoice_id']) as $invoiceItem) {
             $orderItem = OrderItemDAO::getInstance()->getOrderItem($invoiceItem['order_item_id']);
             $this->data['orderItems'][] = array('id' => $orderItem->getId(), 'comment' => $orderItem->getPublicComment(), 'image_path' => $this->registry->get('model_tool_image')->getImage($orderItem->getImagePath()), 'model' => $orderItem->getModel(), 'name' => $orderItem->getName(), 'options' => OrderItemDAO::getInstance()->getOrderItemOptionsString($orderItem->getId()), 'order_id' => $orderItem->getOrderId(), 'price' => $this->currency->format($orderItem->getPrice(), $this->getConfig()->get('config_currency')), 'quantity' => $orderItem->getQuantity(), 'subtotal' => $this->currency->format($orderItem->getPrice() * $orderItem->getQuantity(), $this->getConfig()->get('config_currency')));
             $orderItemIdParam .= '&orderItemId[]=' . $orderItem->getId();
         }
     }
     $add = $this->modelReferenceAddress->getAddress($invoice->getShippingAddressId());
     $this->getLoader()->model('sale/order');
     $order_info = $this->model_sale_order->getOrderByShippingAddressId($invoice->getShippingAddressId());
     /// Set invoice data
     //        $customer = CustomerDAO::getInstance()->getCustomer($invoice['customer_id']);
     $this->data['comment'] = $invoice->getComment();
     $this->data['discount'] = $invoice->getDiscount();
     $this->data['invoiceId'] = $invoice->getId();
     $this->data['packageNumber'] = $invoice->getPackageNumber();
     $this->data['shippingAddress'] = nl2br($this->modelReferenceAddress->toString($invoice->getShippingAddressId())) . "<br />" . $order_info['shipping_phone'];
     //$add['phone'];
     $this->data['shippingCost'] = $this->getCurrency()->format($invoice->getShippingCost(), $this->getConfig()->get('config_currency'));
     $this->data['shippingCostRaw'] = $invoice->getShippingCost();
     $this->data['shippingCostRoute'] = $this->url->link('sale/invoice/getShippingCost', 'token=' . $this->parameters['token'] . $orderItemIdParam, 'SSL');
     $this->data['shippingMethod'] = $invoice->getShippingMethod();
     $this->data['shippingDate'] = $invoice->getShippingDate();
     $this->data['total'] = $this->getCurrency()->format($invoice->getSubtotal(), $this->getConfig()->get('config_currency'));
     $this->data['totalRaw'] = $invoice->getSubtotal();
     $this->data['totalCustomerCurrency'] = $this->getCurrency()->format($invoice->getTotalCustomerCurrency(), $invoice->getCurrencyCode(), 1);
     $this->data['totalWeight'] = $invoice->getWeight();
     $this->data['grandTotal'] = $this->getCurrency()->format($invoice->getTotal(), $this->getConfig()->get('config_currency'));
     $this->data['customerCurrencyCode'] = $invoice->getCurrencyCode();
     //        $this->log->write(print_r($this->data, true));
 }
예제 #15
0
 public function showForm()
 {
     //        $this->log->write(print_r($this->session, true));
     if (is_null($this->getRequest()->getParam('invoiceId'))) {
         return;
     }
     $modelOrderItem = $this->load->model('account/order_item');
     $modelReferenceAddress = $this->load->model('reference/address');
     $invoice = InvoiceDAO::getInstance()->getInvoice($this->getRequest()->getParam('invoiceId'));
     /// Initialize interface values
     $this->data['headingTitle'] = sprintf($this->language->get('INVOICE'), $invoice->getId());
     $this->data['button_action'] = $this->language->get('button_close');
     $this->data['submit_action'] = $this->url->link('account/invoice/close', '', 'SSL');
     $this->data['textComment'] = $this->language->get('textComment');
     $this->data['textConfirm'] = $this->language->get('CONFIRM');
     $this->data['textDiscount'] = $this->language->get('DISCOUNT');
     $this->data['textGrandTotal'] = $this->language->get('textGrandTotal');
     $this->data['textItemImage'] = $this->language->get('textItemImage');
     $this->data['textItemName'] = $this->language->get('textItemName');
     $this->data['textOrderId'] = $this->language->get('textOrderId');
     $this->data['textOrderItemId'] = $this->language->get('textOrderItemId');
     $this->data['textPackageNumber'] = $this->language->get('PACKAGE_NUMBER');
     $this->data['textPrice'] = $this->language->get('textPrice');
     $this->data['textQuantity'] = $this->language->get('textQuantity');
     $this->data['textShippingAddress'] = $this->language->get('textShippingAddress');
     $this->data['textShippingCost'] = $this->language->get('textShippingCost');
     $this->data['textShippingMethod'] = $this->language->get('textShippingMethod');
     $this->data['textSubtotal'] = $this->language->get('SUBTOTAL');
     $this->data['textTotal'] = $this->language->get('TOTAL');
     $this->data['textWeight'] = $this->language->get('WEIGHT');
     $temp = $invoice->getCustomer();
     if ($temp['customer_id'] != $this->getCurrentCustomer()->getId()) {
         $invoice = null;
         $this->data['notifications']['error'] = $this->language->get('errorAccessDenied');
     } else {
         /// Prepare list
         $subTotalCustomerCurrency = 0;
         foreach ($invoice->getOrderItems() as $orderItem) {
             $this->data['orderItems'][] = array('id' => $orderItem->getId(), 'comment' => $orderItem->getPublicComment(), 'image_path' => $this->registry->get('model_tool_image')->getImage($orderItem->getImagePath()), 'model' => $orderItem->getModel(), 'name' => $orderItem->getName(), 'options' => OrderItemDAO::getInstance()->getOrderItemOptionsString($orderItem->getId()), 'order_id' => $orderItem->getOrderId(), 'price' => $orderItem->getCurrency()->getString($orderItem->getPrice(true)), 'quantity' => $orderItem->getQuantity(), 'shipping' => $orderItem->getCurrency()->getString($orderItem->getShippingCost(true)), 'subtotal' => $orderItem->getCurrency()->getString($orderItem->getTotal(true)));
             $subTotalCustomerCurrency += $orderItem->getTotal(true);
         }
         //            foreach ($this->data['orderItems'] as $item) {
         //                $ids[] = $item['id'];
         //            }
         //
         //            $_invoice = InvoiceDAO::getInstance()->getInvoice($this->getRequest()->getParam('invoiceId'));
         //
         //            foreach (InvoiceDAO::getInstance()->getInvoiceItems($_invoice->getId()) as $invoiceItem) {
         //                if (!in_array($invoiceItem['order_item_id'], $ids)) {
         //                    $orderItem = $this->model_account_order->getOrderProduct($invoiceItem['order_item_id']);
         //
         //                    $this->data['orderItems'][] = array(
         //                        'id' => $orderItem['order_product_id'],
         //                        'comment' => $orderItem['public_comment'],
         //                        'image_path' => $this->registry->get('model_tool_image')->getImage($orderItem['image_path']),
         //                        'model' => $orderItem['model'],
         //                        'name' => $orderItem['name'],
         //                        'options' => $modelOrderItem->getOrderItemOptionsString($orderItem['order_product_id']),
         //                        'order_id' => $orderItem['order_id'],
         //                        'price' => $this->getCurrency()->format($orderItem['price']),
         //                        'quantity' => $orderItem['quantity'],
         //                        'subtotal' => $this->getCurrency()->format($orderItem['price'] * $orderItem['quantity'])
         //                    );
         //                }
         //            }
         /// Set invoice data
         $this->data['invoiceId'] = $invoice->getId();
         $this->data['comment'] = $invoice->getComment();
         $this->data['discount'] = $this->getCurrency()->format($invoice->getDiscount(), $this->getCurrentCustomer()->getBaseCurrency());
         $this->data['packageNumber'] = $invoice->getPackageNumber();
         $this->data['shippingAddress'] = nl2br($modelReferenceAddress->toString($invoice->getShippingAddressId()));
         $this->data['shippingCost'] = $this->getCurrency()->format($invoice->getShippingCost());
         $this->data['shippingMethod'] = ShippingMethodDAO::getInstance()->getMethod(explode('.', $invoice->getShippingMethod())[0])->getName();
         $this->data['status'] = $this->load->model('localisation/invoice')->getInvoiceStatus($invoice->getStatusId(), $this->session->data['language_id']);
         $this->data['statusId'] = $invoice->getStatusId();
         $this->data['total'] = $this->getCurrency()->format($subTotalCustomerCurrency, $this->getCurrentCustomer()->getBaseCurrency(), 1);
         $this->data['totalWeight'] = $invoice->getWeight();
         $this->data['grandTotal'] = $this->getCurrency()->format($invoice->getTotalCustomerCurrency(), $this->getCurrentCustomer()->getBaseCurrency(), 1);
     }
     $templateName = '/template/account/invoiceForm.tpl.php';
     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . $templateName)) {
         $this->template = $this->config->get('config_template') . $templateName;
     } else {
         $this->template = 'default' . $templateName;
     }
     $this->setBreadcrumbs();
     $this->children = array('common/header', 'common/footer', 'common/content_top', 'common/content_bottom', 'common/column_left', 'common/column_right');
     $this->getResponse()->setOutput($this->render());
 }