* LICENCE : Tous droits réservés, le droit d'auteur s'applique - COPIE ET REDISTRIBUTION INTERDITES SANS ACCORD EXPRES D'OXILEO * * @author Oxileo SAS <*****@*****.**> * @copyright 2001-2015 Oxileo SAS * @license Proprietary - no redistribution without authorization */ include '../libraries/QuickcostServiceWSService.php'; include '../../../config/config.inc.php'; /* Check secret */ if (!Tools::getIsset('shared_secret') || Tools::getValue('shared_secret') != Configuration::get('CHRONOPOST_SECRET')) { die('Secret does not match.'); } if (!Tools::getIsset('account') || !Tools::getIsset('password')) { die('Parameter Error'); } $service = new QuickcostServiceWSService(); $quick = new quickCost(); $quick->accountNumber = Tools::getValue('account'); $quick->password = Tools::getValue('password'); $quick->depCode = '92500'; $quick->arrCode = '75001'; $quick->weight = '1'; $quick->productCode = '1'; $quick->type = 'D'; $res = $service->quickCost($quick); if ($res->return->errorCode == 0) { die('OK'); } elseif ($res->return->errorCode == 3) { echo 'Le nom d\'utilisateur ou le mot de passe saisi est incorrect.'; } else { echo 'Une erreur système est survenue, contactez le support Chronopost si le problème persiste.';
/** CARRIER-RELATED FUNCTIONS **/ public function getOrderShippingCost($cart, $shipping_cost) { $productCode = 1; $classicAvailable = true; $relaisAvailable = true; if ($cart->id_address_delivery == 0) { return $shipping_cost; } // CASE NOT LOGGED IN $a = new Address($cart->id_address_delivery); $c = new Country($a->id_country); foreach ($cart->getProducts() as $p) { // check if no product > 20 kg if ($p['weight'] * Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF') > 20) { $relaisAvailable = false; } if ($p['weight'] * Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF') > 30) { $classicAvailable = false; break; } } if (!$classicAvailable) { return false; } // CALCULATE PRODUCTS if ($this->id_carrier == Configuration::get('CHRONO10_CARRIER_ID') || $this->id_carrier == Configuration::get('CHRONOCLASSIC_CARRIER_ID') || $this->id_carrier == Configuration::get('CHRONO18_CARRIER_ID')) { $calculatedProducts = self::calculateProducts($cart); } switch ($this->id_carrier) { case Configuration::get('CHRONORELAIS_CARRIER_ID'): $productCode = self::$productCodes['CHRONORELAIS_CARRIER_ID']; if ($c->iso_code != 'FR' && $c->iso_code != 'FX') { return false; } if (!$relaisAvailable) { return false; } break; case Configuration::get('CHRONOPOST_CARRIER_ID'): $productCode = self::$productCodes['CHRONOPOST_CARRIER_ID']; if ($c->iso_code != 'FR' && $c->iso_code != 'FX') { return false; } break; case Configuration::get('CHRONO10_CARRIER_ID'): if ($calculatedProducts['chrono10'] == false) { return false; } $productCode = self::$productCodes['CHRONO10_CARRIER_ID']; break; case Configuration::get('CHRONO18_CARRIER_ID'): if ($c->iso_code != 'FR' && $c->iso_code != 'FX') { return false; } if ($calculatedProducts['chrono18'] == false) { return false; } $productCode = self::$productCodes['CHRONO18_CARRIER_ID']; break; case Configuration::get('CHRONOEXPRESS_CARRIER_ID'): if ($c->iso_code == 'FR' || $c->iso_code == 'FX') { return false; } $productCode = self::$productCodes['CHRONOEXPRESS_CARRIER_ID']; break; case Configuration::get('CHRONOCLASSIC_CARRIER_ID'): if ($calculatedProducts['chronoclassic'] == false) { return false; } $productCode = self::$productCodes['CHRONOCLASSIC_CARRIER_ID']; break; } if (Configuration::get('CHRONOPOST_QUICKCOST_ENABLED') == 0) { if ($c->iso_code == 'FR' && $a->postcode >= 20000 && $a->postcode < 21000) { return $shipping_cost + (double) Configuration::get('CHRONOPOST_CORSICA_SUPPLEMENT'); } // Let's just use Prestashop's native calculations return $shipping_cost; } $arrcode = $c->iso_code == 'FR' || $c->iso_code == 'FX' ? $a->postcode : $c->iso_code; $cache = Db::getInstance()->executeS('SELECT price, last_updated FROM `' . _DB_PREFIX_ . 'chrono_quickcost_cache` WHERE arrcode = "' . pSQL($arrcode) . '" && product_code="' . $productCode . '" && weight="' . $cart->getTotalWeight() . '"'); if (!empty($cache) && $cache[0]['last_updated'] + 24 * 3600 > time()) { // return from cache return $cache[0]['price']; } include_once _MYDIR_ . '/libraries/QuickcostServiceWSService.php'; $ws = new QuickcostServiceWSService(); $qc = new quickCost(); $qc->accountNumber = Configuration::get('CHRONOPOST_GENERAL_ACCOUNT'); $qc->password = Configuration::get('CHRONOPOST_GENERAL_PASSWORD'); $qc->depCode = Configuration::get('CHRONOPOST_SHIPPER_ZIPCODE'); $qc->arrCode = $arrcode; $qc->weight = $cart->getTotalWeight(); if ($qc->weight == 0) { $qc->weight = 0.1; } // 0 yeilds an error $qc->productCode = $productCode; $qc->type = 'M'; try { $res = $ws->quickCost($qc); } catch (Exception $e) { return $shipping_cost; } if ($res->return->amountTTC != 0) { if (empty($cache)) { DB::getInstance()->query('INSERT INTO ' . _DB_PREFIX_ . 'chrono_quickcost_cache (product_code, arrcode, weight, price, last_updated) VALUES ( "' . pSQL($productCode) . '", "' . pSQL($arrcode) . '", "' . (double) $cart->getTotalWeight() . '", "' . (double) $res->return->amountTTC . '", "' . time() . '") '); } else { DB::getInstance()->query('UPDATE ' . _DB_PREFIX_ . 'chrono_quickcost_cache SET price="' . (double) $res->return->amount . '", last_updated="' . time() . ' WHERE arrcode = "' . pSQL($arrcode) . '" && product_code="' . pSQL($productCode) . '" && weight="' . (double) $cart->getTotalWeight() . '" '); } return $res->return->amountTTC; } if ($res->return->amount != 0) { return $res->return->amount; } return $shipping_cost; }