From 535e5bbe0bc6303d962f45148a0662bc1375a761 Mon Sep 17 00:00:00 2001 From: Fabrice Lebas Date: Wed, 1 Jun 2016 12:31:31 +0200 Subject: [PATCH 1/2] Use order_carrier weight instead of cart total weight when dealing with skybill and number of parcels --- chronopost.php | 19 ++++++++++++++----- postSkybill.php | 7 +++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/chronopost.php b/chronopost.php index a62a501..0876f68 100755 --- a/chronopost.php +++ b/chronopost.php @@ -669,16 +669,25 @@ public static function getPointRelaisAddress($orderid) } + public static function getOrderCarrierWeight($id_order) + { + $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' + SELECT `weight` + FROM `'._DB_PREFIX_.'order_carrier` + WHERE `id_order` = '.(int)$id_order); + return (float)($result); + } + public static function minNumberOfPackages($orderid) { $order = new Order($orderid); $nblt = 1; - - if ($order->getTotalWeight() * Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF') > 20 && $order->id_carrier == Configuration::get('CHRONORELAIS_CARRIER_ID')) - $nblt = ceil($order->getTotalWeight() * Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF') / 20); - if ($order->getTotalWeight() * Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF') > 30) - $nblt = ceil($order->getTotalWeight() * Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF') / 30); + $w = Chronopost::getOrderCarrierWeight($orderid); + if ($w * Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF') > 20 && $order->id_carrier == Configuration::get('CHRONORELAIS_CARRIER_ID')) + $nblt = ceil($w * Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF') / 20); + if ($w * Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF') > 30) + $nblt = ceil($w * Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF') / 30); return $nblt; } diff --git a/postSkybill.php b/postSkybill.php index c6b4ada..a30c005 100755 --- a/postSkybill.php +++ b/postSkybill.php @@ -11,7 +11,7 @@ */ if (!defined('_MYDIR_')) define('_MYDIR_', dirname(__FILE__)); -require('../../config/config.inc.php'); +require($_SERVER['DOCUMENT_ROOT'].'/config/config.inc.php'); if (!Tools::getIsset('orderid') && !Tools::getIsset('orders') && !Tools::getIsset('orderid')) die('

Informations de commande non transmises

'); @@ -108,8 +108,7 @@ function createLT($orderid, $totalnb = 1, $isReturn = false) $cust = new Customer($o->id_customer); // at least 2 skybills for orders >= 30kg - $o = new Order($orderid); - if ($o->getTotalWeight() * Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF') >= 30 && $totalnb == 1) + if (Chronopost::getOrderCarrierWeight($o->id) * Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF') >= 30 && $totalnb == 1) { echo ''; exit(); @@ -290,7 +289,7 @@ function createLT($orderid, $totalnb = 1, $isReturn = false) // weight 0 when multishipping $skybill->weight = 0; // Only 1 skybill, put real weight. - if ($totalnb == 1) $skybill->weight = $o->getTotalWeight() * Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF'); + if ($totalnb == 1) $skybill->weight = Chronopost::getOrderCarrierWeight($o->id) * Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF'); $skybill->weightUnit = 'KGM'; From 50011d9e5544355ee633c227169395276ac12c5a Mon Sep 17 00:00:00 2001 From: Fabrice Lebas Date: Wed, 1 Jun 2016 15:09:36 +0200 Subject: [PATCH 2/2] back to original include --- postSkybill.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postSkybill.php b/postSkybill.php index a30c005..4a0e1be 100755 --- a/postSkybill.php +++ b/postSkybill.php @@ -11,7 +11,7 @@ */ if (!defined('_MYDIR_')) define('_MYDIR_', dirname(__FILE__)); -require($_SERVER['DOCUMENT_ROOT'].'/config/config.inc.php'); +require('../../config/config.inc.php'); if (!Tools::getIsset('orderid') && !Tools::getIsset('orders') && !Tools::getIsset('orderid')) die('

Informations de commande non transmises

');