bebeboutik/modules/soflexibilite/functions/saveDeliveryPoint.php
Marion Muszynski ffbb3232b9 modif soflex
2016-05-09 17:43:57 +02:00

131 lines
4.8 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 So 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
*/
require_once(dirname(__FILE__).'/../../../config/config.inc.php');
require_once(dirname(__FILE__).'/../../../init.php');
require_once(_PS_MODULE_DIR_.'soflexibilite/soflexibilite.php');
require_once(_PS_MODULE_DIR_.'soflexibilite/classes/SoFlexibiliteDelivery.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)) {
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) {
$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');
// TODO sent country
$soDelivery = new SoFlexibiliteDelivery();
$soDelivery->id_cart = (int)$id_cart;
$soDelivery->id_order = -time();
$soDelivery->id_point = pSQL(sprintf('%06s', $id));
$soDelivery->id_customer = (int)$this->context->customer->id;
$soDelivery->firstname = $address->firstname;
$soDelivery->lastname = $address->lastname;
$soDelivery->company = $address->company;
$soDelivery->telephone = pSQL($phone);
$soDelivery->email = pSQL($this->context->customer->email);
$soDelivery->type = $type;
$soDelivery->libelle = pSQL($libelle);
$soDelivery->indice = pSQL($indice);
$soDelivery->postcode = pSQL($codePostal);
$soDelivery->city = pSQL($commune);
$soDelivery->country = (($type == 'CMT' || $type == 'BDP') ? pSQL('BE') : pSQL('FR'));
$soDelivery->address1 = pSQL($adresse1);
$soDelivery->address2 = pSQL('');
$soDelivery->lieudit = pSQL('');
$status = $soDelivery->saveDelivery() ? true : false;
} 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();