shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

order.php (8567B)


      1 <?php
      2 class ModelAccountOrder extends Model {
      3 	public function getOrder($order_id) {
      4 		$order_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order` WHERE order_id = '" . (int)$order_id . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND order_status_id > '0'");
      5 
      6 		if ($order_query->num_rows) {
      7 			$country_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE country_id = '" . (int)$order_query->row['payment_country_id'] . "'");
      8 
      9 			if ($country_query->num_rows) {
     10 				$payment_iso_code_2 = $country_query->row['iso_code_2'];
     11 				$payment_iso_code_3 = $country_query->row['iso_code_3'];
     12 			} else {
     13 				$payment_iso_code_2 = '';
     14 				$payment_iso_code_3 = '';
     15 			}
     16 
     17 			$zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE zone_id = '" . (int)$order_query->row['payment_zone_id'] . "'");
     18 
     19 			if ($zone_query->num_rows) {
     20 				$payment_zone_code = $zone_query->row['code'];
     21 			} else {
     22 				$payment_zone_code = '';
     23 			}
     24 
     25 			$country_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE country_id = '" . (int)$order_query->row['shipping_country_id'] . "'");
     26 
     27 			if ($country_query->num_rows) {
     28 				$shipping_iso_code_2 = $country_query->row['iso_code_2'];
     29 				$shipping_iso_code_3 = $country_query->row['iso_code_3'];
     30 			} else {
     31 				$shipping_iso_code_2 = '';
     32 				$shipping_iso_code_3 = '';
     33 			}
     34 
     35 			$zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE zone_id = '" . (int)$order_query->row['shipping_zone_id'] . "'");
     36 
     37 			if ($zone_query->num_rows) {
     38 				$shipping_zone_code = $zone_query->row['code'];
     39 			} else {
     40 				$shipping_zone_code = '';
     41 			}
     42 
     43 			return array(
     44 				'order_id'                => $order_query->row['order_id'],
     45 				'invoice_no'              => $order_query->row['invoice_no'],
     46 				'invoice_prefix'          => $order_query->row['invoice_prefix'],
     47 				'store_id'                => $order_query->row['store_id'],
     48 				'store_name'              => $order_query->row['store_name'],
     49 				'store_url'               => $order_query->row['store_url'],
     50 				'customer_id'             => $order_query->row['customer_id'],
     51 				'firstname'               => $order_query->row['firstname'],
     52 				'lastname'                => $order_query->row['lastname'],
     53 				'telephone'               => $order_query->row['telephone'],
     54 				'email'                   => $order_query->row['email'],
     55 				'payment_firstname'       => $order_query->row['payment_firstname'],
     56 				'payment_lastname'        => $order_query->row['payment_lastname'],
     57 				'payment_company'         => $order_query->row['payment_company'],
     58 				'payment_address_1'       => $order_query->row['payment_address_1'],
     59 				'payment_address_2'       => $order_query->row['payment_address_2'],
     60 				'payment_postcode'        => $order_query->row['payment_postcode'],
     61 				'payment_city'            => $order_query->row['payment_city'],
     62 				'payment_zone_id'         => $order_query->row['payment_zone_id'],
     63 				'payment_zone'            => $order_query->row['payment_zone'],
     64 				'payment_zone_code'       => $payment_zone_code,
     65 				'payment_country_id'      => $order_query->row['payment_country_id'],
     66 				'payment_country'         => $order_query->row['payment_country'],
     67 				'payment_iso_code_2'      => $payment_iso_code_2,
     68 				'payment_iso_code_3'      => $payment_iso_code_3,
     69 				'payment_address_format'  => $order_query->row['payment_address_format'],
     70 				'payment_method'          => $order_query->row['payment_method'],
     71 				'shipping_firstname'      => $order_query->row['shipping_firstname'],
     72 				'shipping_lastname'       => $order_query->row['shipping_lastname'],
     73 				'shipping_company'        => $order_query->row['shipping_company'],
     74 				'shipping_address_1'      => $order_query->row['shipping_address_1'],
     75 				'shipping_address_2'      => $order_query->row['shipping_address_2'],
     76 				'shipping_postcode'       => $order_query->row['shipping_postcode'],
     77 				'shipping_city'           => $order_query->row['shipping_city'],
     78 				'shipping_zone_id'        => $order_query->row['shipping_zone_id'],
     79 				'shipping_zone'           => $order_query->row['shipping_zone'],
     80 				'shipping_zone_code'      => $shipping_zone_code,
     81 				'shipping_country_id'     => $order_query->row['shipping_country_id'],
     82 				'shipping_country'        => $order_query->row['shipping_country'],
     83 				'shipping_iso_code_2'     => $shipping_iso_code_2,
     84 				'shipping_iso_code_3'     => $shipping_iso_code_3,
     85 				'shipping_address_format' => $order_query->row['shipping_address_format'],
     86 				'shipping_method'         => $order_query->row['shipping_method'],
     87 				'comment'                 => $order_query->row['comment'],
     88 				'total'                   => $order_query->row['total'],
     89 				'order_status_id'         => $order_query->row['order_status_id'],
     90 				'language_id'             => $order_query->row['language_id'],
     91 				'currency_id'             => $order_query->row['currency_id'],
     92 				'currency_code'           => $order_query->row['currency_code'],
     93 				'currency_value'          => $order_query->row['currency_value'],
     94 				'date_modified'           => $order_query->row['date_modified'],
     95 				'date_added'              => $order_query->row['date_added'],
     96 				'ip'                      => $order_query->row['ip']
     97 			);
     98 		} else {
     99 			return false;
    100 		}
    101 	}
    102 
    103 	public function getOrders($start = 0, $limit = 20) {
    104 		if ($start < 0) {
    105 			$start = 0;
    106 		}
    107 
    108 		if ($limit < 1) {
    109 			$limit = 1;
    110 		}
    111 
    112 		$query = $this->db->query("SELECT o.order_id, o.firstname, o.lastname, os.name as status, o.date_added, o.total, o.currency_code, o.currency_value FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "order_status os ON (o.order_status_id = os.order_status_id) WHERE o.customer_id = '" . (int)$this->customer->getId() . "' AND o.order_status_id > '0' AND o.store_id = '" . (int)$this->config->get('config_store_id') . "' AND os.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY o.order_id DESC LIMIT " . (int)$start . "," . (int)$limit);
    113 
    114 		return $query->rows;
    115 	}
    116 
    117 	public function getOrderProduct($order_id, $order_product_id) {
    118 		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$order_product_id . "'");
    119 
    120 		return $query->row;
    121 	}
    122 
    123 	public function getOrderProducts($order_id) {
    124 		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
    125 
    126 		return $query->rows;
    127 	}
    128 
    129 	public function getOrderOptions($order_id, $order_product_id) {
    130 		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$order_product_id . "'");
    131 
    132 		return $query->rows;
    133 	}
    134 
    135 	public function getOrderVouchers($order_id) {
    136 		$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_voucher` WHERE order_id = '" . (int)$order_id . "'");
    137 
    138 		return $query->rows;
    139 	}
    140 
    141 	public function getOrderTotals($order_id) {
    142 		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "' ORDER BY sort_order");
    143 
    144 		return $query->rows;
    145 	}
    146 
    147 	public function getOrderHistories($order_id) {
    148 		$query = $this->db->query("SELECT date_added, os.name AS status, oh.comment, oh.notify FROM " . DB_PREFIX . "order_history oh LEFT JOIN " . DB_PREFIX . "order_status os ON oh.order_status_id = os.order_status_id WHERE oh.order_id = '" . (int)$order_id . "' AND os.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY oh.date_added");
    149 
    150 		return $query->rows;
    151 	}
    152 
    153 	public function getTotalOrders() {
    154 		$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` o WHERE customer_id = '" . (int)$this->customer->getId() . "' AND o.order_status_id > '0' AND o.store_id = '" . (int)$this->config->get('config_store_id') . "'");
    155 
    156 		return $query->row['total'];
    157 	}
    158 
    159 	public function getTotalOrderProductsByOrderId($order_id) {
    160 		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
    161 
    162 		return $query->row['total'];
    163 	}
    164 
    165 	public function getTotalOrderVouchersByOrderId($order_id) {
    166 		$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order_voucher` WHERE order_id = '" . (int)$order_id . "'");
    167 
    168 		return $query->row['total'];
    169 	}
    170 }