/** * get detail of one order * * @param unknown_type $id * @return unknown */ function getOrder($id) { require_once 'models/ecommerce/ecommerce_basket.php'; require_once 'models/client/client_customer.php'; require_once 'models/ecommerce/ecommerce_order_log.php'; require_once 'models/ecommerce/ecommerce_delivery.php'; $Basket = new ecommerce_basket(); $Customer = new client_customer(); $OrderLog = new ecommerce_order_log(); $Delivery = new ecommerce_delivery(); $Basket->setCacheable(false); $Customer->setCacheable(false); $OrderLog->setCacheable(false); //this can be cached (submitted orders cannot change address) $Delivery->setCacheable(false); $order = $this->getDetail($id); //get promotion code $order['promotion_code'] = $this->getPromotionCode($id); //get basket detail $basket_detail = $Basket->getDetail($order['basket_id']); $include_vat = $this->isVatEligible($order['delivery_address_id'], $basket_detail['customer_id']); $basket_content = $Basket->getFullDetail($order['basket_id'], GLOBAL_DEFAULT_CURRENCY); $Basket->calculateBasketSubTotals($basket_content, $include_vat); $Basket->calculateBasketDiscount($basket_content, $order['promotion_code'], false); $basket_content['delivery'] = $Delivery->getDeliveryByOrderId($id); $Basket->calculateBasketTotals($basket_content); $order['basket'] = $basket_content; //get client detail $order['client'] = $Customer->getClientData($basket_content['customer_id']); //get status (log) detail $order['log'] = $OrderLog->getLog($id); $order['status_title'] = $this->getStatusTitle($order['status']); //get address detail require_once 'models/client/client_address.php'; $Address = new client_address(); $Address->setCacheable(false); $address_detail['delivery'] = $Address->getDetail($order['delivery_address_id']); $address_detail['invoices'] = $Address->getDetail($order['invoices_address_id']); $order['address'] = $address_detail; //get invoice detail $order['invoice'] = $this->getInvoiceDetail($id); //get transaction detail $order['transaction'] = $this->getTransactionDetail($id); // get stats $order['client']['stats'] = $this->getNumberOfCustomersOrders($basket_detail['customer_id']); //print_r($order); return $order; }
/** * main action */ public function mainAction() { $customer_id = $_SESSION['client']['customer']['id']; if (!is_numeric($customer_id)) { msg("Address management requires active customer ID"); return true; } /** * initialize */ require_once 'models/client/client_customer.php'; require_once 'models/client/client_address.php'; require_once 'models/international/international_country.php'; $Customer = new client_customer(); $Address = new client_address(); $Country = new international_country(); $Customer->setCacheable(false); $Address->setCacheable(false); /** * add address */ if ($_POST['add_address']) { $_POST['client']['address']['customer_id'] = $customer_id; if ($address_id = $Address->insert($_POST['client']['address'])) { msg('New address added to your list.'); } else { msg('Address is not valid', 'error'); } } /** * select address */ if ($_POST['select_address']) { $customer_detail = $Customer->detail($customer_id); $customer_detail["{$this->GET['type']}_address_id"] = $_POST['select_address']; if ($Customer->update($customer_detail)) { $_SESSION['client']['customer'] = $customer_detail; onxshopGoTo($_SESSION['referer'], 2); } else { msg("Cannot select this address", 'error'); } } /** * remove address */ if (is_numeric($_POST['remove_address'])) { $address_id_to_remove = $_POST['remove_address']; $address_detail = $Address->detail($address_id_to_remove); if ($address_detail['customer_id'] == $customer_id) { if ($Address->deleteAddress($address_id_to_remove)) { msg('Address has been removed'); } else { msg('Cannot remove address', 'error'); } } else { msg("This is not your address!", 'error'); } } /** * address list */ $addresses = $Address->listing("customer_id = {$customer_id} AND is_deleted IS NOT TRUE", "id DESC"); $current_invoices = $_SESSION['client']['customer']['invoices_address_id']; $current_delivery = $_SESSION['client']['customer']['delivery_address_id']; foreach ($addresses as $addr) { $country_detail = $Country->detail($addr['country_id']); $addr['country'] = $country_detail; $this->tpl->assign('address', $addr); if ($addr['line_2'] != '') { $this->tpl->parse('content.address.line_2'); } if ($addr['line_3'] != '') { $this->tpl->parse('content.address.line_3'); } if ($this->GET['type'] != '') { $this->tpl->parse('content.address.select'); } else { if ($addr['id'] != $current_invoices && $addr['id'] != $current_delivery) { $this->tpl->parse('content.address.delete'); } } if ($current_invoices == $addr['id']) { $this->tpl->parse('content.address.is_invoices'); } if ($current_delivery == $addr['id']) { $this->tpl->parse('content.address.is_delivery'); } $this->tpl->parse('content.address'); } /** * country list */ $countries = $Country->listing("", "name ASC"); if (!isset($_POST['client']['address']['country_id'])) { $_POST['client']['address']['country_id'] = $Country->conf['default_id']; } foreach ($countries as $c) { if ($c['publish'] == 1) { if ($c['id'] == $_POST['client']['address']['country_id']) { $c['selected'] = "selected='selected'"; } else { $c['selected'] = ''; } $this->tpl->assign('country', $c); $this->tpl->parse('content.country.item'); } } $this->tpl->parse('content.country'); /** * assign to template */ $this->tpl->assign('client', $_POST['client']); return true; }