Example #1
0
 /**
  * Each time a new order with Kiala delivery is passed, create the Kiala order in database
  *
  * @param array $params
  */
 public function hookNewOrder($params)
 {
     // Get the kiala order created when the user selected a Kiala point
     $kiala_order = KialaOrder::getEmptyKialaOrder($params['cart']->id);
     if (!Validate::isLoadedObject($kiala_order) || !$kiala_order->point_short_id) {
         return;
     }
     // If the kiala carrier was selected at some point, but another carrier was the final choice, delete the uncomplete kiala order
     if ($params['cart']->id_carrier != Configuration::get('KIALA_CARRIER_ID')) {
         $kiala_order->delete();
         return;
     }
     $kiala_order->id_customer = $params['customer']->id;
     $kiala_order->id_cart = $params['cart']->id;
     $kiala_order->id_order = $params['order']->id;
     $kiala_country_pickup = KialaCountry::getPickupCountry();
     $kiala_order->id_country_pickup = $kiala_country_pickup->id_country;
     // Get delivery country using the customer delivery address (not the kiala point address)
     $delivery_address = new Address($params['order']->id_address_delivery);
     $kiala_order->id_country_delivery = $delivery_address->id_country;
     // Create a new address with the Kiala point location
     $point_address = new Address();
     $point_address->id_customer = $kiala_order->id_customer;
     $point_address->id_country = $kiala_order->id_country_delivery;
     // Set id_state in case the merchant added this field to the required fields list
     $point_address->id_state = 0;
     $point_address->lastname = $delivery_address->lastname;
     $point_address->firstname = $delivery_address->firstname;
     $point_address->address1 = substr($kiala_order->point_name . ' - ' . $kiala_order->point_street, 0, 128);
     $point_address->postcode = $kiala_order->point_zip;
     $point_address->city = $kiala_order->point_city;
     $point_address->address2 = $kiala_order->point_location_hint;
     $point_address->alias = 'Kiala point - ' . date('d-m-Y');
     $point_address->deleted = true;
     $point_address->save();
     // Assign the kiala point address as delivery address in order
     if ($point_address->id) {
         $order = $params['order'];
         $order->id_address_delivery = $point_address->id;
         $order->update();
     }
     if (Configuration::get('KIALA_EXPORT_SINGLE')) {
         $export = new ExportFormat($this);
         $export->export($kiala_order);
         $kiala_order->exported = 1;
     }
     $kiala_order->save();
 }
Example #2
0
 public function postProcess()
 {
     global $currentIndex;
     $token = Tools::getValue('token') ? Tools::getValue('token') : $this->token;
     if (Tools::isSubmit('export')) {
         $export = new ExportFormat(Module::getInstanceByName('kiala'));
         $kiala_order = new KialaOrder(Tools::getValue('id_kiala_order'));
         $export->export($kiala_order);
         if (!$export->exportContent) {
             $this->_errors[] = Tools::displayError('Exporting failed.');
         } else {
             // Add the correct headers, this forces the file is saved
             ob_clean();
             header('Content-Type: text/plain');
             header('Content-Disposition: attachment; filename="' . Configuration::get('KIALA_LAST_EXPORT_FILE') . '"');
             echo $export->exportContent;
             exit;
         }
     } elseif (Tools::isSubmit('exportBatch')) {
         $kiala_orders = array();
         foreach (Tools::getValue($this->table . 'Box') as $id) {
             $kiala_order = new KialaOrder($id);
             $kiala_orders[] = $kiala_order;
         }
         $export = new ExportFormat(Module::getInstanceByName('kiala'));
         if (!$export->exportBatch($kiala_orders)) {
             $this->_errors[] = Tools::displayError('Exporting failed.');
         } else {
             ob_clean();
             // Add the correct headers, this forces the file is saved
             header('Content-Type: text/plain');
             header('Content-Disposition: attachment; filename="' . Configuration::get('KIALA_LAST_EXPORT_FILE') . '"');
             echo $export->exportContent;
             exit;
         }
     }
     parent::postProcess();
 }