/**
  * Get Zone Id by Address Id
  */
 public function getZoneIdByAddress($address_id)
 {
     if (!is_numeric($address_id)) {
         return false;
     }
     require_once 'models/client/client_address.php';
     $Address = new client_address();
     $address = $Address->getDetail($address_id);
     return $this->getZoneIdByCountry($address['country_id']);
 }
Example #2
0
 /**
  * insertCustomerAddress
  */
 public function insertCustomerAddress($customer_data, $address_data)
 {
     if (!is_array($customer_data)) {
         return false;
     }
     if (!is_array($address_data)) {
         return false;
     }
     require_once 'models/client/client_address.php';
     $Address = new client_address();
     /**
      * insert delivery address
      */
     $address_data['delivery']['customer_id'] = $customer_data['id'];
     if ($delivery_address_id = $Address->insert($address_data['delivery'])) {
         $customer_data['delivery_address_id'] = $delivery_address_id;
     } else {
         msg("Your delivery address is not set!", 'error');
     }
     /**
      * insert invoice address
      */
     if (trim($address_data['invoices']['city']) != '') {
         $address_data['invoices']['customer_id'] = $customer_data['id'];
         if ($invoices_address_id = $Address->insert($address_data['invoices'])) {
             $customer_data['invoices_address_id'] = $invoices_address_id;
         } else {
             msg("Your invoices address is not set! If your invoices address is same as the delivery address, please leave the invoices address fields empty.", 'error');
         }
     } else {
         $customer_data['invoices_address_id'] = $delivery_address_id;
     }
     /**
      * update customer record after setting addresses id
      */
     return $this->update($customer_data);
 }
Example #3
0
 /**
  * Return true if given address and customer is VAT eligible
  * 
  * @param  int    $delivery_address_id Delivery address id to check EU status
  * @param  int    $customer_id         Customer id to check whole sale status (not implemented yet!)
  * @return boolean
  */
 function isVatEligible($delivery_address_id, $customer_id)
 {
     $order_conf = ecommerce_order::initConfiguration();
     require_once 'models/client/client_address.php';
     $Address = new client_address();
     $delivery = $Address->getDetail($delivery_address_id);
     $exclude_vat = $order_conf['non_eu_zero_vat'] && !$delivery['country']['eu_status'];
     return !$exclude_vat;
 }
Example #4
0
 /**
  * main action
  */
 public function mainAction()
 {
     /**
      * include node configuration
      */
     require_once 'models/common/common_node.php';
     $node_conf = common_node::initConfiguration();
     $this->tpl->assign('NODE_CONF', $node_conf);
     /**
      * client
      */
     require_once 'models/client/client_address.php';
     $Address = new client_address();
     if (is_numeric($this->GET['invoices_address_id'])) {
         $invoices_address_id = $this->GET['invoices_address_id'];
     }
     if (is_numeric($this->GET['delivery_address_id'])) {
         $delivery_address_id = $this->GET['delivery_address_id'];
     }
     //if we have not address_ids, we'll use session data
     if (!is_numeric($invoices_address_id) && !is_numeric($delivery_address_id)) {
         $invoices_address_id = $_SESSION['client']['customer']['invoices_address_id'];
         $delivery_address_id = $_SESSION['client']['customer']['delivery_address_id'];
     }
     if (is_numeric($invoices_address_id)) {
         $invoices = $Address->getDetail($invoices_address_id);
     } else {
         $invoices = false;
     }
     if (is_numeric($delivery_address_id)) {
         $delivery = $Address->getDetail($delivery_address_id);
     } else {
         $delivery = false;
     }
     $addr['invoices'] = $invoices;
     $addr['delivery'] = $delivery;
     $this->tpl->assign('ADDRESS', $addr);
     if (is_array($addr['invoices'])) {
         if ($addr['invoices']['line_2'] != '') {
             $this->tpl->parse('content.invoices.line_2');
         }
         if ($addr['invoices']['line_3'] != '') {
             $this->tpl->parse('content.invoices.line_3');
         }
         if ($this->GET['hide_button'] == 0) {
             $this->tpl->parse('content.invoices.button');
         }
         $this->tpl->parse('content.invoices');
     } else {
         if ($this->GET['hide_button'] == 0) {
             $this->tpl->parse('content.invoices_add_button');
         }
     }
     if (is_array($addr['delivery'])) {
         if ($addr['delivery']['line_2'] != '') {
             $this->tpl->parse('content.delivery.line_2');
         }
         if ($addr['delivery']['line_3'] != '') {
             $this->tpl->parse('content.delivery.line_3');
         }
         if ($this->GET['hide_button'] == 0) {
             $this->tpl->parse('content.delivery.button');
         }
         $this->tpl->parse('content.delivery');
     } else {
         if ($this->GET['hide_button'] == 0) {
             $this->tpl->parse('content.delivery_add_button');
         }
     }
     return true;
 }
 /**
  * Calculate delivery rate for given carrier and basket content
  * 
  * @param  Array  $basket              Basket content 
  * @param  int    $carrier_id          Carrier id
  * @param  int    $delivery_address_id Delivery address id
  * @return Array                       Delivery rate and VAT
  */
 function calculateDelivery($basket, $carrier_id, $delivery_address_id, $promotion_detail)
 {
     require_once 'models/client/client_address.php';
     $Address = new client_address();
     $address_detail = $Address->detail($delivery_address_id);
     $country_id = (int) $address_detail['country_id'];
     return $this->calculateDeliveryForCountry($basket, $carrier_id, $country_id, $promotion_detail);
 }
Example #6
0
 /**
  * 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;
 }
 /**
  * main action
  */
 public function mainAction()
 {
     /**
      * include node configuration
      */
     require_once 'models/common/common_node.php';
     $node_conf = common_node::initConfiguration();
     /**
      * client
      */
     require_once 'models/client/client_address.php';
     $Address = new client_address();
     if (is_numeric($this->GET['invoices_address_id'])) {
         $invoices_address_id = $this->GET['invoices_address_id'];
     }
     if (is_numeric($this->GET['delivery_address_id'])) {
         $delivery_address_id = $this->GET['delivery_address_id'];
     }
     // is guest checkout required?
     $guest_checkout = $_SESSION['client']['customer']['guest'];
     // address edit link
     if ($guest_checkout) {
         $this->tpl->assign('UPDATE_PAGE_ID', $node_conf['id_map-guest_registration']);
     } else {
         $this->tpl->assign('UPDATE_PAGE_ID', $node_conf['id_map-checkout_delivery_options']);
     }
     //if we have not address_ids, we'll use session data
     if (!is_numeric($invoices_address_id) && !is_numeric($delivery_address_id)) {
         $invoices_address_id = $_SESSION['client']['customer']['invoices_address_id'];
         $delivery_address_id = $_SESSION['client']['customer']['delivery_address_id'];
     }
     if (is_numeric($invoices_address_id)) {
         $invoices = $Address->getDetail($invoices_address_id);
     } else {
         if ($guest_checkout) {
             $invoices = $_SESSION['client']['address']['invoices'];
             $invoices['country']['name'] = $this->getCountryName($invoices['country_id']);
         } else {
             $invoices = false;
         }
     }
     if (is_numeric($delivery_address_id)) {
         $delivery = $Address->getDetail($delivery_address_id);
     } else {
         if ($guest_checkout) {
             $delivery = $_SESSION['client']['address']['delivery'];
             $delivery['country']['name'] = $this->getCountryName($delivery['country_id']);
         } else {
             $delivery = false;
         }
     }
     $addr['invoices'] = $invoices;
     $addr['delivery'] = $delivery;
     $this->tpl->assign('ADDRESS', $addr);
     if (is_array($addr['invoices'])) {
         if ($addr['invoices']['line_2'] != '') {
             $this->tpl->parse('content.invoices.line_2');
         }
         if ($addr['invoices']['line_3'] != '') {
             $this->tpl->parse('content.invoices.line_3');
         }
         if ($this->GET['hide_button'] == 0) {
             $this->tpl->parse('content.invoices.button');
         }
         $this->tpl->parse('content.invoices');
     }
     if (is_array($addr['delivery'])) {
         if ($addr['delivery']['line_2'] != '') {
             $this->tpl->parse('content.delivery.line_2');
         }
         if ($addr['delivery']['line_3'] != '') {
             $this->tpl->parse('content.delivery.line_3');
         }
         if ($this->GET['hide_button'] == 0) {
             $this->tpl->parse('content.delivery.button');
         }
         $this->tpl->parse('content.delivery');
     }
     return true;
 }