logo

INTERNETNE STORITVE

- IZDELAVA SPLETNIH STRANI - OBLIKOVANJE - PROGRAMIRANJE DODATKOV

PHP - Zen Cart - Easy Populate - UTF8 podpora - UTF8 support

Vsi tisti, ki uporabljate Zen Cart spletno trgovino veste, da Zen Cart (zaenkrat) ne podpira UTF-8. Zadeva se, da hitro spremeniti. Celotni postopek spreminjanja Zen Cart baze ter nastavitev (php header) je opisan tukaj. Naredili smo tudi celotno pretvorbo slovenskega jezika (zen cart slovenian language pack) za Zen Cart 1.3.8a z UTF-8 podporo. Vendar, ko imamo celotno strukturo in jezikovne datoteke v UTF8 formatu nastane problem pri uvozu novih podatkov, saj Easy Populate, ki omogoča hitro vnašanje podatkov in je eden izmed bolj priljubljenih dodatkov za Zen Cart, ne podpira UTF-8 branje podatkov / pisanje podatkov. Na srečo je potrebno le malo modifikacije za ustrezen rezultat.

If you are using zen cart internet shop you know that Zen Cart (for now) doesn't support UTF8. Likely this can be easily changed (whole procedure in Slovene). After we change the Zen Cart database structure, data and language files to UTF-8 charset we get a new problem with importing / exporting data using Easy Populate module which is one of the most popular modules out there. Unlickely the Easy Populate doesn't support UTF8 and I didn't find any solution on the web so I've decided to modify the files myself. Luckily there aren't many changes necessary to get UTF8 support. Here is the list of files which needs to be changed (backup first!!!). Just copy the whole function code and replace it with the old one at files which are written above the php code block. If you have any problems let me know (comments or email).

Easy Populate Advanced 3.0.3 - 65.00 USD:
#1 FileWriter.php -> /admin/includes/easypopulate/classes/eclipse/FileWriter.php

PHP:
  1. function FileWriter ( $file, $append=false ) {
  2.     $this->append = $append;
  3.     $type = gettype($file);
  4.     switch ( $type ) {
  5.         case 'string':
  6.             $this->_fileString($file);
  7.             break;
  8.  
  9.         case 'object':
  10.             $this->_fileObject($file);
  11.             break;
  12.     }
  13.  
  14.     $this->write("\xEF\xBB\xBF"); // Added for UTF-8 support
  15. }

#2 FileIterator -> /admin/includes/easypopulate/classes/eclipse/FileIterator.php

PHP:
  1. function readLine() {
  2.     // Get the text
  3.     $test = fgets($this->pointer, $this->bufferSize);
  4.  
  5.     // Check which encoding is this - if this is UTF-8 dont try to convert it again to UTF-8 as corupted chars will apear
  6.     $encoding = mb_detect_encoding($test, "UTF-8, ISO-8859-1");
  7.  
  8.     // Only convert if ISO-8859-1 / CP1250
  9.     if ($encoding == "CP1250") {
  10.         $test = iconv("CP1250", "UTF-8", $test);
  11.     }
  12.  
  13.     // If there is BOM char at the begining, clear it
  14.     if (strpos($test, "\xEF\xBB\xBF") !== false) {
  15.         $test = str_replace("\xEF\xBB\xBF", "", $test);
  16.     }
  17.  
  18.     return $test;
  19. }

#3 MyDatabase.php -> /admin/includes/easypopulate/classes/eclipse/MyDatabase.php

PHP:
  1. function connect($username, $password, $type = ECLIPSE_DB_NON_PERSISTENT) {
  2.     $this->setLink(
  3.     ($type == ECLIPSE_DB_PERSISTENT)
  4.     ? mysql_pconnect($this->getHost(), $username, $password)
  5.     : mysql_connect($this->getHost(), $username, $password)
  6.     );
  7.     mysql_select_db($this->getName(), $this->getLink());
  8.  
  9.     $charset    = 'utf8';
  10.     $collation  = 'utf8_slovenian_ci';
  11.  
  12.     if (!mysql_query("SET NAMES '$charset' COLLATE '$collation'", $this->getLink()))
  13.         die('Error executing query SET NAMES - MyDatabase.php - easyupload - classes-eclipse');
  14.  
  15.  
  16.     return $this->isConnected();
  17. }

Obstaja tudi zastonjska verzija Easy Populate, vendar je koda še bolj "zbegana" kot pri advanced easy populate, kjer mi ni jasno, zakaj je potrebno toliko kodo. Če bo čas, med poletjem spišemo nov modul za import / export Zen Cart baze s pomočjo Excela s boljšo podporo atributom ter podporo Attribute to Stock modulom. Je kdo zainteresiran za kaj takšnega?

There is also a free version of easy populate module, but the code is even more messier then in advanced easy populate. In both cases I don't understand why so much code has to be written for that little functionality. If there will be free time in summer I'll write a new module which will support direct Excel import / export with better attributes support and also support for Attribute to Stock module. If anybody is interested in this new module please drop me a line at rok.meglic@gmail.com.

Dodaj komentar