Jump to content

Amélioration Expeditor INET


Recommended Posts

Bonjour,

J'ai remarqué que Expeditor n'acceptais pas UTF-8 mais uniquement ASCII.

J'ai donc procédé à une amélioration du fichier getCSV.php

<?php
include(dirname(__FILE__).'/../../config/config.inc.php');
$cookie = new Cookie('psAdmin', substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__), -10));
Tools::setCookieLanguage();

function formatItem($string)
{
   return '"' . $string . '";';
}

function getStandardSize($value)
{
   $ret = 'N';
   if ($value == true OR $value == '1' OR $value == 1)
       $ret = 'O';
   return formatItem($ret);
}

$expeditors = ExpeditorModule::getList();

$downloadFile = 'expeditor_'.date('Y-m-d').'_prestashop.csv';
ob_end_clean();              
header("Content-Transfer-Encoding: binary");
header('Content-Type: application/vnd.ms-excel; charset=US-ASCII'); // Should work for IE & Opera
header("Content-Type: application/x-msexcel; charset=US-ASCII"); // Should work for the rest
header('Content-Disposition: attachment; filename="' . $downloadFile . '"');

foreach ($expeditors as $expeditor)
{
   $order = new Order($expeditor['id_order']);
   $address = new Address($order->id_address_delivery);
   $country = new Country($address->id_country);
   echo formatItem('EXP'.$order->id);
   echo formatItem(trim((!empty($address->company) ? unaccent($address->company).' - ' : '').unaccent($address->firstname) .' '. unaccent($address->lastname)));

   // Address line is limited to 35 chars
   $wholeAddress = unaccent(trim($address->address1.' '.$address->address2));

   echo formatItem(substr($wholeAddress, 0, 35));
   echo formatItem(substr($wholeAddress, 35, 70));
   echo formatItem(substr($wholeAddress, 70, 105));
   echo formatItem(substr($wholeAddress, 105));

   echo formatItem(str_replace(' ', '', unaccent($address->postcode)));
   echo formatItem(unaccent($address->city));
   echo formatItem(unaccent($country->iso_code));
   echo formatItem(unaccent($expeditor['weight']));
   echo getStandardSize(unaccent($expeditor['standard_size']));
   echo chr(13); // CR --> carriage return
   echo chr(10); // LF --> new line
}

exit();

function unaccent($string){
      $string = htmlentities($string,ENT_QUOTES,'UTF-8');
      return preg_replace("/&([a-z])[a-z]+;/i","$1",$string);
}
?>

Link to comment
Share on other sites

  • 1 month later...
Bonjour,

Nous avons apportés des modifications au niveau de l’encodage sur le module Expeditor Inet de la poste.

Cordialement Mikaël


Bonjour Mickael,
Je viens de retélécharger le module et je ne vois pas les modifs.
Comment les intégrer ?
Link to comment
Share on other sites

J'ai bien désinstallé le module Expeditor, retéléchargé le module (depuis mon compte Prestashop), mais rien n'y fait.
Par ailleurs, les fichiers sont datés du 4 juin, avant la modif. Le seul ajout récent dans le pack est la doc en pdf.
En modifiant le fichier getCsv.php comme indiqué ci-dessus, le problème est presque réglé, mais ça ne traite pas les apostrophes.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...