<?php include dirname(__FILE__) . '/../../../../config/config.inc.php'; require_once dirname(__FILE__) . '/../../../../init.php'; include dirname(__FILE__) . '/kiala.php'; // make sure a point was selected if (!isset($_REQUEST['shortkpid'])) { echo 'Kiala did not return anything'; var_dump($_REQUEST); exit; } // $kiala = new CartAPI_Module_Kiala(); // kiala does not have code to parse a Point class from $_REQUEST (only from xml), so parse manually // code taken from module kiala kiala.php displayPoint $kiala_order = KialaOrder::getEmptyKialaOrder($cart->id); $kiala_order->point_short_id = $_REQUEST['shortkpid']; $kiala_order->point_name = $_REQUEST['kpname']; $kiala_order->point_street = $_REQUEST['street']; $kiala_order->point_zip = $_REQUEST['zip']; $kiala_order->point_city = $_REQUEST['city']; $kiala_order->point_location_hint = $_REQUEST['locationhint']; $kiala_order->id_cart = (int) $cart->id; $kiala_order->save(); Tools::redirect('');
/** * 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(); }