155 lines
5.9 KiB
PHP
155 lines
5.9 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* NOTICE OF LICENSE
|
||
|
*
|
||
|
* This source file is subject to a commercial license from Common-Services Co., Ltd.
|
||
|
* Use, copy, modification or distribution of this source file without written
|
||
|
* license agreement from the SARL SMC is strictly forbidden.
|
||
|
* In order to obtain a license, please contact us: contact@common-services.com
|
||
|
* ...........................................................................
|
||
|
* INFORMATION SUR LA LICENCE D'UTILISATION
|
||
|
*
|
||
|
* L'utilisation de ce fichier source est soumise a une licence commerciale
|
||
|
* concedee par la societe Common-Services Co., Ltd.
|
||
|
* Toute utilisation, reproduction, modification ou distribution du present
|
||
|
* fichier source sans contrat de licence ecrit de la part de la Common-Services Co. Ltd. est
|
||
|
* expressement interdite.
|
||
|
* Pour obtenir une licence, veuillez contacter Common-Services Co., Ltd. a l'adresse: contact@common-services.com
|
||
|
* ...........................................................................
|
||
|
*
|
||
|
* @package Colissimo Flexibilite
|
||
|
* @author Alexandre D.
|
||
|
* @copyright Copyright (c) 2011-2015 Common Services Co Ltd - 90/25 Sukhumvit 81 - 10260 Bangkok - Thailand
|
||
|
* @license Commercial license
|
||
|
* Support by mail : support.soflexibilite@common-services.com
|
||
|
*/
|
||
|
|
||
|
if (isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] == 'localhost') {
|
||
|
require_once(readlink(dirname($_SERVER['SCRIPT_FILENAME']) . '/../../../config/config.inc.php'));
|
||
|
require_once(readlink(dirname($_SERVER['SCRIPT_FILENAME']) . '/../../../init.php'));
|
||
|
} else {
|
||
|
@require_once(dirname(__FILE__) . '/../../../config/config.inc.php');
|
||
|
@require_once(dirname(__FILE__) . '/../../../init.php');
|
||
|
}
|
||
|
|
||
|
require_once(dirname(__FILE__).'/../soflexibilite.php');
|
||
|
require_once(dirname(__FILE__).'/../classes/SoFlexibiliteDelivery.php');
|
||
|
require_once(dirname(__FILE__).'/../classes/SoFlexibiliteCarrierFeeChecker.php');
|
||
|
|
||
|
|
||
|
class SoFlexibiliteDeliverySave extends SoFlexibilite
|
||
|
{
|
||
|
|
||
|
public function save()
|
||
|
{
|
||
|
ob_start();
|
||
|
|
||
|
$id = null;
|
||
|
$type = null;
|
||
|
$pass = true;
|
||
|
$debug = false || Tools::getValue('debug');
|
||
|
|
||
|
// Ocarat change to invoice address
|
||
|
$address = new Address((int)$this->context->cart->id_address_invoice);
|
||
|
|
||
|
if (!Validate::isLoadedObject($address) && Tools::getValue('id_cart')) {
|
||
|
$cart = new Cart((int)Tools::getValue('id_cart'));
|
||
|
|
||
|
if (Validate::isLoadedObject($cart)) {
|
||
|
$address = new Address((int)$cart->id_address_invoice);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!Validate::isLoadedObject($address)) {
|
||
|
if ($debug) {
|
||
|
die(sprintf(
|
||
|
'%s(#%d): Validate::isLoadedObject(%d) failed' . "\n",
|
||
|
basename(__FILE__),
|
||
|
__LINE__,
|
||
|
(int)$this->context->cart->id_address_delivery
|
||
|
));
|
||
|
}
|
||
|
$pass = false;
|
||
|
}
|
||
|
|
||
|
if (!(Tools::getValue('id') && Tools::getValue('type') && Tools::getValue('id_cart') &&
|
||
|
Tools::getValue('libelle') && Tools::getValue('adresse1') && Tools::getValue('code_postal')
|
||
|
&& Tools::getValue('commune'))
|
||
|
) {
|
||
|
if ($debug) {
|
||
|
die(sprintf(
|
||
|
'%s(#%d): Missing Parameter' . "\n",
|
||
|
basename(__FILE__),
|
||
|
__LINE__,
|
||
|
(int)$this->context->cart->id_address_delivery
|
||
|
));
|
||
|
}
|
||
|
$pass = false;
|
||
|
}
|
||
|
|
||
|
if ($pass) {
|
||
|
if (!isset($this->context->customer) || !Validate::isLoadedObject($this->context->customer)) {
|
||
|
if (isset($cart) && Validate::isLoadedObject($cart)) {
|
||
|
$this->context->customer = new Customer((int)$cart->id_customer);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$id = (int)Tools::getValue('id');
|
||
|
$type = Tools::getValue('type');
|
||
|
$id_cart = (int)Tools::getValue('id_cart');
|
||
|
$phone = Tools::getValue('phone');
|
||
|
$libelle = Tools::getValue('libelle');
|
||
|
$indice = Tools::getValue('indice');
|
||
|
$codePostal = Tools::getValue('code_postal');
|
||
|
$commune = Tools::getValue('commune');
|
||
|
$adresse1 = Tools::getValue('adresse1');
|
||
|
$country = Tools::getValue('country');
|
||
|
$reseau = Tools::getValue('reseau');
|
||
|
|
||
|
$so_delivery = new SoFlexibiliteDelivery();
|
||
|
$so_delivery->id_cart = (int)$id_cart;
|
||
|
$so_delivery->id_order = -time();
|
||
|
$so_delivery->id_point = pSQL(sprintf('%06s', $id));
|
||
|
$so_delivery->id_customer = (int)$this->context->customer->id;
|
||
|
$so_delivery->firstname = $address->firstname;
|
||
|
$so_delivery->lastname = $address->lastname;
|
||
|
$so_delivery->company = $address->company;
|
||
|
$so_delivery->telephone = pSQL($phone);
|
||
|
$so_delivery->email = pSQL($this->context->customer->email);
|
||
|
$so_delivery->type = $type;
|
||
|
$so_delivery->libelle = pSQL($libelle);
|
||
|
$so_delivery->indice = pSQL($indice);
|
||
|
$so_delivery->postcode = pSQL($codePostal);
|
||
|
$so_delivery->city = pSQL($commune);
|
||
|
$so_delivery->country = pSQL($country);
|
||
|
$so_delivery->address1 = pSQL($adresse1);
|
||
|
$so_delivery->address2 = pSQL('');
|
||
|
$so_delivery->lieudit = pSQL('');
|
||
|
$so_delivery->reseau = pSQL($reseau);
|
||
|
|
||
|
$status = (bool)$so_delivery->saveDelivery();
|
||
|
SoFlexibiliteCarrierFeeChecker::set($id_cart, $this->context->customer->id, $country);
|
||
|
} else {
|
||
|
$status = false;
|
||
|
}
|
||
|
|
||
|
$result = ob_get_clean();
|
||
|
|
||
|
if ($result) {
|
||
|
$output = $result;
|
||
|
} else {
|
||
|
$output = null;
|
||
|
}
|
||
|
|
||
|
$json = array(
|
||
|
'output' => $output,
|
||
|
'status' => $status
|
||
|
);
|
||
|
die(Tools::jsonEncode($json));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
$so_flexibilite_delivery_save = new SoFlexibiliteDeliverySave();
|
||
|
$so_flexibilite_delivery_save->save();
|