« Pourquoi Prestashop n’utilise pas la bonne grille de frais de port ? » voici la question ou la réponse n’a pas été aussi évidente.

Pour les plus impatient(e)s, voici le lien pour la solution. Pour les autres, voici le contexte qui a tout son importance.

Pour certaines occasions et certains clients, nous sommes amené à scripter les modifications de frais de port sous Prestashop.

En effet, si vous devez déployer une grosse grille de frais de port sur plusieurs environnements (Développement, préproduction, production, ….), il est préférable de faire un script qui pourra se jouer autant de fois que nécessaire, qui pourra se copier sur les différents environnements et qui se jouera quasiment instantanément.

Suite à la mise à jour des tarifs d’un prestataire de livraison (Colissimo), un de nos clients nous a donc demandé de mettre à jour ses plateformes avec ces nouveaux tarifs et remettre à plat toute sa gestion de frais de port.

Pour cela, nous utilisons un de nos module, le module Developper Tools.

Ce module permet, en autre, aux équipes intervenant à plusieurs sur un environnement Prestashop de mettre à jour cette plateforme.

Le mécanisme de mise à jour est inspiré de la plateforme de e-commerce Plici que nous avions développé il y a quelques années. Ce mécanisme a été repris dans les mises à jour de Prestashop.

Pour ce faire, le module vient lire des fichiers séquentiellement pour exécuter les fichiers php ou lancer des scripts sql.

En fin de cet article, vous trouverez le fichier script que nous avons utilisé pour mettre à jour les tarifs Colissimo de notre client et remettre sa gestion des frais de port au propre.

Sauf que suite à cette mise à jour,  notre client nous a remonté des frais de port incohérents pour certaines livraisons. Prestashop n’utilisait pas la bonne grille de frais de port.

En effet, ce script permet bien de supprimer tous les transporteurs et créer une toute nouvelle grille de frais de port mais il ne modifie pas les frais de port des pays à états.

Certains pays (Argentine, Australie, Canada, États-Unis d’Amérique, Indonésie, Italie, Japon, Mexique) sont sous-divisés en états qui peuvent avoir des frais de ports différents. Vous pouvez donc modifier en base de données, les frais de port mais il ne faut pas oublier de mettre à jour aussi les frais de port au niveau des états.

Comme nous sommes sympas, on vous met aussi le script pour modifier les frais de port au niveau des états.

 

Script de mise à jour des frais de port sous Prestashop
!! Attention de toujours faire une sauvegarde de vos fichiers avant de les modifier. !!

Si vous ne comprenez pas ce que vous faites, ne pas modifier votre fichier et demander à votre agence ou une agence de développement spécialisée dans Prestashop d’apporter ces modifications sur votre site Internet.

Ce fichier ne fonctionne qu’avec le module module Developper Tools. A vous de l’adapter en fonction de vos besoins.

modules/pliciwebupdate/data/001_update_delivery_price.php

[sourcecode language= »php »]
<?php $carrier_colissimo = new Carrier(80); // Change label of zone $sqls = []; $sqls[] = ‘UPDATE `’._DB_PREFIX_.’zone` SET `name` = "Zone 1" WHERE `id_zone` = 4′; $sqls[] = ‘UPDATE `’._DB_PREFIX_.’zone` SET `name` = "Zone 2" WHERE `id_zone` = 5′; $sqls[] = ‘UPDATE `’._DB_PREFIX_.’zone` SET `name` = "Zone 3" WHERE `id_zone` = 6′; $sqls[] = ‘UPDATE `’._DB_PREFIX_.’zone` SET `name` = "Zone 4" WHERE `id_zone` = 7′; foreach ($sqls as $sql) { if (!Db::getInstance()->execute($sql)) {
$controller->errors[] = vsprintf(‘Cannot play request "%s"’, [$sql]);
return false;
}
}
$controller->confirmations[] = ‘
‘.vsprintf(‘Zone update’, []);

// Add new zones
$zone5 = new Zone(8);
if ($zone5->name) {
$controller->informations[] = ‘
‘.vsprintf(‘Zone %d already exist’, [5]);
} else {
$zone5->name=’Zone 5′;
$zone5->active = 1;

if (!$zone5->save()) {
$controller->errors[] = vsprintf(‘Cannot create "Zone %d"’, [5]);
return false;
}

$controller->confirmations[] = ‘
‘.vsprintf(‘Zone "%s" created’, [$zone5->name]);
}

$zone6 = new Zone(9);
if ($zone6->name) {
$controller->informations[] = ‘
‘.vsprintf(‘Zone %d already exist’, [6]);
} else {
$zone6->name=’Zone 6′;
$zone6->active = 1;

if (!$zone6->save()) {
$controller->errors[] = vsprintf(‘Cannot create "Zone %d"’, [6]);
return false;
}

$controller->confirmations[] = ‘
‘.vsprintf(‘Zone "%s" created’, [$zone6->name]);
}

// Remove old carriers
$id_lang_fr = Language::getIdByIso(‘FR’);

$carriers = Carrier::getCarriers($id_lang_fr);

foreach($carriers as $carrier_detail) {
$carrier = new Carrier($carrier_detail[‘id_carrier’]);

if (!in_array($carrier_detail[‘name’], [‘Fedex’, ‘Colissimo France’])) {
if (!$carrier->delete()) {
$controller->errors[] = vsprintf(‘Cannot delete "%s"’, [$carrier_detail[‘name’]]);
return false;
}
}
}
$controller->confirmations[] = ‘
‘.vsprintf(‘Carriers deleted’, []);

$carrier_colissimo->name = ‘Colissimo’;

if (!$carrier_colissimo->save()) {
$controller->errors[] = vsprintf(‘Cannot save Carrier "%s"’, [$carrier_colissimo->name]);
return false;
}
$controller->confirmations[] = ‘
‘.vsprintf(‘Carrier "%s" updated’, [$carrier_colissimo->name]);

// Update zone for country
$country[‘AF’] = 9;
$country[‘ZA’] = 9;
$country[‘AX’] = 7;
$country[‘AL’] = 7;
$country[‘DZ’] = 7;
$country[‘DE’] = 4;
$country[‘AD’] = 7;
$country[‘AO’] = 9;
$country[‘AI’] = 9;
$country[‘AQ’] = 9;
$country[‘AG’] = 9;
$country[‘AN’] = 9;
$country[‘SA’] = 9;
$country[‘AR’] = 9;
$country[‘AM’] = 7;
$country[‘AW’] = 9;
$country[‘AU’] = 8;
$country[‘AT’] = 5;
$country[‘AZ’] = 7;
$country[‘BS’] = 9;
$country[‘BH’] = 9;
$country[‘BD’] = 9;
$country[‘BB’] = 9;
$country[‘BY’] = 7;
$country[‘BE’] = 4;
$country[‘BZ’] = 9;
$country[‘BJ’] = 9;
$country[‘BM’] = 9;
$country[‘BT’] = 9;
$country[‘BO’] = 9;
$country[‘BA’] = 7;
$country[‘BW’] = 9;
$country[‘BV’] = 9;
$country[‘BR’] = 9;
$country[‘BN’] = 9;
$country[‘BG’] = 7;
$country[‘BF’] = 9;
$country[‘MM’] = 9;
$country[‘BI’] = 9;
$country[‘KY’] = 9;
$country[‘KH’] = 9;
$country[‘CM’] = 9;
$country[‘CA’] = 8;
$country[‘CV’] = 9;
$country[‘CF’] = 9;
$country[‘CL’] = 9;
$country[‘CN’] = 8;
$country[‘CX’] = 9;
$country[‘CY’] = 7;
$country[‘CC’] = 9;
$country[‘CO’] = 9;
$country[‘KM’] = 9;
$country[‘CG’] = 9;
$country[‘CD’] = 9;
$country[‘CK’] = 9;
$country[‘KR’] = 8;
$country[‘KP’] = 9;
$country[‘CR’] = 9;
$country[‘CI’] = 9;
$country[‘HR’] = 7;
$country[‘CU’] = 9;
$country[‘DK’] = 6;
$country[‘DJ’] = 9;
$country[‘DM’] = 9;
$country[‘EG’] = 9;
$country[‘SV’] = 9;
$country[‘AE’] = 9;
$country[‘EC’] = 9;
$country[‘ER’] = 9;
$country[‘ES’] = 5;
$country[‘EE’] = 6;
$country[‘US’] = 8;
$country[‘ET’] = 9;
$country[‘FK’] = 9;
$country[‘FO’] = 6;
$country[‘FJ’] = 9;
$country[‘FI’] = 7;
$country[‘FR’] = 1;
$country[‘GA’] = 9;
$country[‘GM’] = 9;
$country[‘GE’] = 7;
$country[‘GS’] = 9;
$country[‘GH’] = 9;
$country[‘GI’] = 7;
$country[‘GR’] = 7;
$country[‘GD’] = 9;
$country[‘GL’] = 6;
$country[‘GP’] = 2;
$country[‘GU’] = 9;
$country[‘GT’] = 9;
$country[‘GG’] = 5;
$country[‘GN’] = 9;
$country[‘GQ’] = 9;
$country[‘GW’] = 9;
$country[‘GY’] = 9;
$country[‘GF’] = 2;
$country[‘HT’] = 9;
$country[‘HM’] = 9;
$country[‘HN’] = 9;
$country[‘HK’] = 8;
$country[‘HU’] = 6;
$country[‘MU’] = 9;
$country[‘VG’] = 9;
$country[‘VI’] = 9;
$country[‘IN’] = 8;
$country[‘ID’] = 9;
$country[‘IR’] = 9;
$country[‘IQ’] = 9;
$country[‘IE’] = 5;
$country[‘IS’] = 7;
$country[‘IL’] = 8;
$country[‘IT’] = 5;
$country[‘JM’] = 9;
$country[‘JP’] = 8;
$country[‘JE’] = 5;
$country[‘JO’] = 9;
$country[‘KZ’] = 9;
$country[‘KE’] = 9;
$country[‘KG’] = 9;
$country[‘KI’] = 9;
$country[‘KW’] = 9;
$country[‘LA’] = 9;
$country[‘LS’] = 9;
$country[‘LV’] = 6;
$country[‘LB’] = 9;
$country[‘LR’] = 9;
$country[‘LY’] = 9;
$country[‘LI’] = 7;
$country[‘LT’] = 6;
$country[‘LU’] = 4;
$country[‘MO’] = 9;
$country[‘MK’] = 7;
$country[‘MG’] = 9;
$country[‘MY’] = 9;
$country[‘MW’] = 9;
$country[‘MV’] = 9;
$country[‘ML’] = 9;
$country[‘MT’] = 7;
$country[‘IM’] = 5;
$country[‘MP’] = 9;
$country[‘MA’] = 7;
$country[‘MH’] = 9;
$country[‘MQ’] = 2;
$country[‘MR’] = 9;
$country[‘YT’] = 2;
$country[‘MX’] = 9;
$country[‘FM’] = 9;
$country[‘MD’] = 7;
$country[‘MC’] = 1;
$country[‘MN’] = 9;
$country[‘ME’] = 7;
$country[‘MS’] = 9;
$country[‘MZ’] = 9;
$country[‘NA’] = 9;
$country[‘NR’] = 9;
$country[‘NP’] = 9;
$country[‘NI’] = 9;
$country[‘NE’] = 9;
$country[‘NG’] = 9;
$country[‘NU’] = 9;
$country[‘NF’] = 9;
$country[‘NO’] = 7;
$country[‘NC’] = 3;
$country[‘NZ’] = 9;
$country[‘IO’] = 9;
$country[‘OM’] = 9;
$country[‘ONL’] = 3;
$country[‘UG’] = 9;
$country[‘UZ’] = 9;
$country[‘PK’] = 9;
$country[‘PW’] = 9;
$country[‘PS’] = 9;
$country[‘PA’] = 9;
$country[‘PG’] = 9;
$country[‘PY’] = 9;
$country[‘NL’] = 4;
$country[‘PE’] = 9;
$country[‘PH’] = 9;
$country[‘PN’] = 9;
$country[‘PL’] = 6;
$country[‘PF’] = 3;
$country[‘PR’] = 9;
$country[‘PT’] = 5;
$country[‘QA’] = 9;
$country[‘DO’] = 9;
$country[‘CZ’] = 6;
$country[‘RE’] = 2;
$country[‘RO’] = 7;
$country[‘GB’] = 5;
$country[‘RU’] = 8;
$country[‘RW’] = 9;
$country[‘EH’] = 9;
$country[‘BL’] = 2;
$country[‘LC’] = 2;
$country[‘KN’] = 9;
$country[‘SM’] = 5;
$country[‘MF’] = 9;
$country[‘PM’] = 2;
$country[‘VA’] = 5;
$country[‘VC’] = 9;
$country[‘SB’] = 9;
$country[‘WS’] = 9;
$country[‘AS’] = 9;
$country[‘ST’] = 9;
$country[‘SN’] = 9;
$country[‘RS’] = 7;
$country[‘SC’] = 9;
$country[‘SL’] = 9;
$country[‘SG’] = 8;
$country[‘SK’] = 6;
$country[‘SI’] = 6;
$country[‘SO’] = 9;
$country[‘SD’] = 9;
$country[‘LK’] = 9;
$country[‘SE’] = 6;
$country[‘CH’] = 6;
$country[‘SR’] = 9;
$country[‘SJ’] = 9;
$country[‘SZ’] = 9;
$country[‘SY’] = 9;
$country[‘TJ’] = 9;
$country[‘TW’] = 8;
$country[‘TZ’] = 9;
$country[‘TD’] = 9;
$country[‘TF’] = 3;
$country[‘TH’] = 8;
$country[‘TL’] = 9;
$country[‘TG’] = 9;
$country[‘TK’] = 9;
$country[‘TO’] = 9;
$country[‘TT’] = 9;
$country[‘TN’] = 7;
$country[‘TM’] = 9;
$country[‘TC’] = 9;
$country[‘TR’] = 7;
$country[‘TV’] = 9;
$country[‘UA’] = 7;
$country[‘UY’] = 9;
$country[‘VU’] = 9;
$country[‘VE’] = 9;
$country[‘VN’] = 8;
$country[‘WF’] = 3;
$country[‘YE’] = 9;
$country[‘ZM’] = 9;
$country[‘ZW’] = 9;

foreach ($country as $iso_country => $id_zone) {
if (!Db::getInstance()->execute(‘UPDATE `’._DB_PREFIX_.’country` SET `id_zone` = ‘.(int) $id_zone.’ WHERE `iso_code` = "’.pSql($iso_country).’"’)) {
$controller->errors[] = vsprintf(‘Cannot update country "%s"’, [$iso_country]);
return false;
}
}
$controller->confirmations[] = ‘
‘.vsprintf(‘Countries updated’, []);

if ( Db::getInstance()->getValue(‘SELECT COUNT(`id_range_weight`) FROM `’._DB_PREFIX_.’range_weight` WHERE `id_carrier` = ‘.$carrier_colissimo->id) < 12) { // Remove all range for colissimo if (!Db::getInstance()->execute(‘DELETE FROM `’._DB_PREFIX_.’range_weight` WHERE `id_carrier` = ‘.$carrier_colissimo->id)) {
$controller->errors[] = vsprintf(‘Cannot delete old range_weight’, [$sql]);
return false;
}
$controller->confirmations[] = ‘
‘.vsprintf(‘Old range_weight deleted’, []);

if (!Db::getInstance()->execute(‘DELETE FROM `’._DB_PREFIX_.’delivery` WHERE `id_carrier` = ‘.$carrier_colissimo->id)) {
$controller->errors[] = vsprintf(‘Cannot delete old delivery’, [$sql]);
return false;
}
$controller->confirmations[] = ‘
‘.vsprintf(‘Old delivery deleted’, []);

$ranges = [];
$ranges[] = [ ‘from’ => 0, ‘to’ => 0.25, ‘price’ => [1 => 6.31, 2 => 12.63, 3 => 18.54, 4 => 10.11, 5 => 11.31, 6 => 11.36, 7=> 13.93, 8=>21.29, 9=>24.41]];
$ranges[] = [ ‘from’ => 0.25, ‘to’ => 0.5, ‘price’ => [1 => 7.10, 2 => 12.63, 3 => 18.54, 4 => 10.11, 5 => 11.31, 6 => 11.36, 7=> 13.93, 8=>21.29, 9=>24.41]];
$ranges[] = [ ‘from’ => 0.5, ‘to’ => 0.75, ‘price’ => [1 => 7.83, 2 => 15.62, 3 => 22.93, 4 => 11.89, 5 => 13.84, 6 => 13.88, 7=> 16.58, 8=>23.54, 9=>28.71]];
$ranges[] = [ ‘from’ => 0.75, ‘to’ => 1, ‘price’ => [1 => 8.42, 2 => 15.62, 3 => 22.93, 4 => 11.89, 5 => 13.84, 6 => 13.88, 7=> 16.58, 8=>23.54, 9=>28.71]];
$ranges[] = [ ‘from’ => 1, ‘to’ => 2, ‘price’ => [1 => 9.23, 2 => 21.04, 3 => 35.68, 4 => 12.60, 5 => 15.25, 6 => 15.40, 7=> 18.03, 8=>32.28, 9=>39.43]];
$ranges[] = [ ‘from’ => 2, ‘to’ => 3, ‘price’ => [1 => 10.04, 2 => 26.49, 3 => 48.43, 4 => 13.37, 5 => 16.11, 6 => 16.70, 7=> 19.59, 8=>41, 9=>50.36]];
$ranges[] = [ ‘from’ => 3, ‘to’ => 4, ‘price’ => [1 => 10.86, 2 => 31.93, 3 => 60.69, 4 => 14.15, 5 => 16.86, 6 => 18.28, 7=> 21.67, 8=>46.98, 9=>61.07]];
$ranges[] = [ ‘from’ => 4, ‘to’ => 5, ‘price’ => [1 => 11.67, 2 => 37.06, 3 => 73.33, 4 => 14.83, 5 => 17.68, 6 => 19.89, 7=> 25.78, 8=>50.16, 9=>70.22]];
$ranges[] = [ ‘from’ => 5, ‘to’ => 6, ‘price’ => [1 => 12.50, 2 => 42.81, 3 => 86.67, 4 => 15.55, 5 => 18.44, 6 => 25.87, 7=> 28.92, 8=>64.12, 9=>80.67]];
$ranges[] = [ ‘from’ => 6, ‘to’ => 7, ‘price’ => [1 => 13.31, 2 => 48.25, 3 => 99.41, 4 => 16.26, 5 => 19.31, 6 => 27.28, 7=> 32.66, 8=>74.22, 9=>91.22]];
$ranges[] = [ ‘from’ => 7, ‘to’ => 8, ‘price’ => [1 => 14.11, 2 => 53.25, 3 => 111.27, 4 => 16.96, 5 => 20.07, 6 => 28.60, 7=> 37.21, 8=>82.24, 9=>101.67]];
$ranges[] = [ ‘from’ => 8, ‘to’ => 9, ‘price’ => [1 => 14.94, 2 => 58.65, 3 => 123.92, 4 => 17.68, 5 => 20.83, 6 => 29.93, 7=> 39.84, 8=>85.70, 9=>112.38]];
$ranges[] = [ ‘from’ => 9, ‘to’ => 10, ‘price’ => [1 => 15.75, 2 => 64.05, 3 => 136.56, 4 => 18.39, 5 => 21.59, 6 => 31.24, 7=> 43.07, 8=>89.98, 9=>122.83]];
$ranges[] = [ ‘from’ => 10, ‘to’ => 11, ‘price’ => [1 => 16.58, 2 => 89.60, 3 => 202.42, 4 => 22.46, 5 => 25.81, 6 => 38.71, 7=> 57.53, 8=>131.74, 9=>170.20]];
$ranges[] = [ ‘from’ => 11, ‘to’ => 12, ‘price’ => [1 => 17.38, 2 => 89.60, 3 => 202.42, 4 => 22.46, 5 => 25.81, 6 => 38.71, 7=> 57.53, 8=>131.74, 9=>170.20]];
$ranges[] = [ ‘from’ => 12, ‘to’ => 13, ‘price’ => [1 => 18.20, 2 => 89.60, 3 => 202.42, 4 => 22.46, 5 => 25.81, 6 => 38.71, 7=> 57.53, 8=>131.74, 9=>170.20]];
$ranges[] = [ ‘from’ => 13, ‘to’ => 14, ‘price’ => [1 => 19.02, 2 => 89.60, 3 => 202.42, 4 => 22.46, 5 => 25.81, 6 => 38.71, 7=> 57.53, 8=>131.74, 9=>170.20]];
$ranges[] = [ ‘from’ => 14, ‘to’ => 15, ‘price’ => [1 => 19.83, 2 => 89.60, 3 => 202.42, 4 => 22.46, 5 => 25.81, 6 => 38.71, 7=> 57.53, 8=>131.74, 9=>170.20]];
$ranges[] = [ ‘from’ => 15, ‘to’ => 16, ‘price’ => [1 => 20.66, 2 => 115.87, 3 => 265.05, 4 => 26.52, 5 => 29.93, 6 => 46.09, 7=> 67.13, 8=>144.28, 9=>218.59]];
$ranges[] = [ ‘from’ => 16, ‘to’ => 17, ‘price’ => [1 => 21.46, 2 => 115.87, 3 => 265.05, 4 => 26.52, 5 => 29.93, 6 => 46.09, 7=> 67.13, 8=>144.28, 9=>218.59]];
$ranges[] = [ ‘from’ => 17, ‘to’ => 18, ‘price’ => [1 => 22.28, 2 => 115.87, 3 => 265.05, 4 => 26.52, 5 => 29.93, 6 => 46.09, 7=> 67.13, 8=>144.28, 9=>218.59]];
$ranges[] = [ ‘from’ => 18, ‘to’ => 19, ‘price’ => [1 => 23.10, 2 => 115.87, 3 => 265.05, 4 => 26.52, 5 => 29.93, 6 => 46.09, 7=> 67.13, 8=>144.28, 9=>218.59]];
$ranges[] = [ ‘from’ => 19, ‘to’ => 20, ‘price’ => [1 => 23.91, 2 => 115.87, 3 => 265.05, 4 => 26.52, 5 => 29.93, 6 => 46.09, 7=> 67.13, 8=>144.28, 9=>218.59]];
$ranges[] = [ ‘from’ => 20, ‘to’ => 21, ‘price’ => [1 => 24.73, 2 => 142.86, 3 => 329.30, 4 => 30.58, 5 => 34.04, 6 => 53.49, 7=> 79.16, 8=>185.21, 9=>265.95]];
$ranges[] = [ ‘from’ => 21, ‘to’ => 22, ‘price’ => [1 => 25.54, 2 => 142.86, 3 => 329.30, 4 => 30.58, 5 => 34.04, 6 => 53.49, 7=> 79.16, 8=>185.21, 9=>265.95]];
$ranges[] = [ ‘from’ => 22, ‘to’ => 23, ‘price’ => [1 => 26.36, 2 => 142.86, 3 => 329.30, 4 => 30.58, 5 => 34.04, 6 => 53.49, 7=> 79.16, 8=>185.21, 9=>265.95]];
$ranges[] = [ ‘from’ => 23, ‘to’ => 24, ‘price’ => [1 => 27.18, 2 => 142.86, 3 => 329.30, 4 => 30.58, 5 => 34.04, 6 => 53.49, 7=> 79.16, 8=>185.21, 9=>265.95]];
$ranges[] = [ ‘from’ => 24, ‘to’ => 25, ‘price’ => [1 => 27.98, 2 => 142.86, 3 => 329.30, 4 => 30.58, 5 => 34.04, 6 => 53.49, 7=> 79.16, 8=>185.21, 9=>265.95]];
$ranges[] = [ ‘from’ => 25, ‘to’ => 26, ‘price’ => [1 => 28.81, 2 => 169.83, 3 => 393.53, 4 => 34.64, 5 => 38.15, 6 => 55.61, 7=> 91.50, 8=>213.44, 9=>313.31]];
$ranges[] = [ ‘from’ => 26, ‘to’ => 27, ‘price’ => [1 => 29.62, 2 => 169.83, 3 => 393.53, 4 => 34.64, 5 => 38.15, 6 => 55.61, 7=> 91.50, 8=>213.44, 9=>313.31]];
$ranges[] = [ ‘from’ => 27, ‘to’ => 28, ‘price’ => [1 => 30.44, 2 => 169.83, 3 => 393.53, 4 => 34.64, 5 => 38.15, 6 => 55.61, 7=> 91.50, 8=>213.44, 9=>313.31]];
$ranges[] = [ ‘from’ => 28, ‘to’ => 29, ‘price’ => [1 => 31.26, 2 => 169.83, 3 => 393.53, 4 => 34.64, 5 => 38.15, 6 => 55.61, 7=> 91.50, 8=>213.44, 9=>313.31]];
$ranges[] = [ ‘from’ => 29, ‘to’ => 30, ‘price’ => [1 => 32.06, 2 => 169.83, 3 => 393.53, 4 => 34.64, 5 => 38.15, 6 => 55.61, 7=> 91.50, 8=>213.44, 9=>313.31]];

foreach($ranges as &$range) {
$data = [
‘id_carrier’ => $carrier_colissimo->id
,’delimiter1′ => $range[‘from’]
,’delimiter2′ => $range[‘to’]
];

// Add range price
if (!Db::getInstance()->insert(‘range_price’, $data, true)) {
$controller->errors[] = vsprintf(‘Cannot add range price %f,%f’, [$range[‘from’], $range[‘to’]]);
return false;
}
$id_range_price = Db::getInstance()->Insert_ID();

// Add range weight
if (!Db::getInstance()->insert(‘range_weight’, $data, true)) {
$controller->errors[] = vsprintf(‘Cannot add range weight %f,%f’, [$range[‘from’], $range[‘to’]]);
return false;
}
$id_range_weight = Db::getInstance()->Insert_ID();

foreach($range[‘price’] as $id_zone => $price) {
$delivery = new Delivery();
$delivery->id_shop = null;
$delivery->id_shop_group = null;
$delivery->id_carrier = $carrier_colissimo->id;
$delivery->id_range_price = $id_range_price;
$delivery->id_range_weight = $id_range_weight;
$delivery->id_zone = $id_zone;
$delivery->price = $price;
if (!$delivery->add(true, true)) {
$controller->errors[] = vsprintf(‘Cannot add delivery (%d,%d,%d,%f)’, [$carrier_colissimo->id, $range_weight->id, $id_zone, $price]);
return false;
}
}

}

$controller->confirmations[] = ‘
‘.vsprintf(‘Ranges added’, []);

foreach($range[‘price’] as $id_zone => $price) {
$data_zone = [
‘id_carrier’ => $carrier_colissimo->id
, ‘id_zone’ => $id_zone
];
if (!Db::getInstance()->insert(‘carrier_zone’, $data_zone, true, true, Db::REPLACE)) {
$controller->errors[] = vsprintf(‘Cannot add carrier_zone %d,%d’, [$carrier_colissimo->id, $id_zone]);
return false;
}
}
$controller->confirmations[] = ‘
‘.vsprintf(‘Ranges added’, []);
}

// Update product weight
$product_weight[1] = 1.5;
$product_weight[2] = 1.5;
$product_weight[3] = 1.5;
$product_weight[4] = 1.5;
$product_weight[5] = 2.8;
$product_weight[10] = 1.5;
$product_weight[11] = 1.5;
$product_weight[12] = 1.5;
$product_weight[13] = 1.5;
$product_weight[14] = 1.5;
$product_weight[15] = 1.5;
$product_weight[17] = 1.5;
$product_weight[18] = 1.5;
$product_weight[19] = 1.5;
$product_weight[20] = 1.5;
$product_weight[21] = 1.5;
$product_weight[22] = 2.7;
$product_weight[23] = 1.9;
$product_weight[24] = 1.7;
$product_weight[25] = 1.7;
$product_weight[26] = 0.9;
$product_weight[27] = 0.5;
$product_weight[28] = 2.8;
$product_weight[29] = 1;
$product_weight[30] = 0.5;
$product_weight[31] = 0.5;
$product_weight[32] = 0.5;
$product_weight[33] = 1.5;
$product_weight[34] = 0.5;
$product_weight[35] = 1.5;
$product_weight[36] = 1.5;
$product_weight[37] = 1.5;
$product_weight[38] = 1.5;
$product_weight[39] = 1.5;
$product_weight[40] = 2.2;
$product_weight[41] = 2.2;
$product_weight[42] = 1.5;
$product_weight[45] = 1.5;
$product_weight[47] = 1.5;
$product_weight[48] = 1.5;
$product_weight[49] = 1.5;
$product_weight[50] = 2.3;
$product_weight[51] = 0.9;
$product_weight[52] = 1.5;
$product_weight[53] = 4;
$product_weight[54] = 4;
$product_weight[55] = 4;
$product_weight[56] = 1.5;
$product_weight[57] = 1.5;
$product_weight[58] = 2.3;
$product_weight[59] = 1.5;
$product_weight[60] = 1;
$product_weight[61] = 1.5;
$product_weight[62] = 7.3;
$product_weight[63] = 1;
$product_weight[64] = 1.5;
$product_weight[65] = 7.3;
$product_weight[66] = 0.5;
$product_weight[67] = 1.5;
$product_weight[68] = 1.5;
$product_weight[69] = 1.5;

foreach($product_weight as $id_product => $weight) {
if (!Db::getInstance()->update(‘product’, [‘weight’ => $weight], ‘id_product = ‘.$id_product)) {
$controller->errors[] = vsprintf(‘Cannot change weight for product %d’, [$id_product]);
return false;
}
}
$controller->confirmations[] = ‘
‘.vsprintf(‘Weight product change’, []);[/sourcecode]

Script de mise à jour des frais de port des états sous Prestashop
!! Attention de toujours faire une sauvegarde de vos fichiers avant de les modifier. !!

Si vous ne comprenez pas ce que vous faites, ne pas modifier votre fichier et demander à votre agence ou une agence de développement spécialisée dans Prestashop d’apporter ces modifications sur votre site Internet.

Ce fichier ne fonctionne qu’avec le module Developper Tools. A vous de l’adapter en fonction de vos besoins.

modules/pliciwebupdate/data/002_update_delivery_price_state.php

[sourcecode language= »php »]
<?php $carrier_colissimo = new Carrier(80); // Change label of zone $sqls = []; $sqls[] = ‘UPDATE `’._DB_PREFIX_.’state` SET `id_zone` = 9 WHERE `id_country` IN (44, 21, 111, 145)’; $sqls[] = ‘UPDATE `’._DB_PREFIX_.’state` SET `id_zone` = 8 WHERE `id_country` IN (4, 11)’; $sqls[] = ‘UPDATE `’._DB_PREFIX_.’state` SET `id_zone` = 5 WHERE `id_country` IN (10)’; foreach ($sqls as $sql) { if (!Db::getInstance()->execute($sql)) {
$controller->errors[] = vsprintf(‘Cannot play request "%s"’, [$sql]);
return false;
}
}
$controller->confirmations[] = ‘
‘.vsprintf(‘Zone update’, []);[/sourcecode]