* @copyright PrestaShop * @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0 * @version 1.2 * */ include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php'); include_once(PS_ADMIN_DIR.'/../images.inc.php'); @ini_set('max_execution_time', 0); define('MAX_LINE_SIZE', 4096); define('UNFRIENDLY_ERROR', false); // Used for validatefields diying without user friendly error or not // this value set the number of columns visible on each page define('MAX_COLUMNS', 6); // correct Mac error on eof @ini_set('auto_detect_line_endings', '1'); class AdminImport extends AdminTab { public static $column_mask; public $entities = array(); public $available_fields = array(); public static $required_fields = array('name'); public static $default_values = array(); public static $validators = array( 'active' => array('AdminImport', 'getBoolean'), 'tax_rate' => array('AdminImport', 'getPrice'), 'price_tex' => array('AdminImport', 'getPrice'), // Tax excluded 'price_tin' => array('AdminImport', 'getPrice'), // Tax included 'reduction_price' => array('AdminImport', 'getPrice'), 'reduction_percent' => array('AdminImport', 'getPrice'), 'wholesale_price' => array('AdminImport', 'getPrice'), 'ecotax' => array('AdminImport', 'getPrice'), 'name' => array('AdminImport', 'createMultiLangField'), 'description' => array('AdminImport', 'createMultiLangField'), 'description_short' => array('AdminImport', 'createMultiLangField'), 'meta_title' => array('AdminImport', 'createMultiLangField'), 'meta_keywords' => array('AdminImport', 'createMultiLangField'), 'meta_description' => array('AdminImport', 'createMultiLangField'), 'available_now' => array('AdminImport', 'createMultiLangField'), 'available_later' => array('AdminImport', 'createMultiLangField'), 'category' => array('AdminImport', 'split'), ); public function __construct() { $this->entities = array_flip(array($this->l('Categories'), $this->l('Products'), $this->l('Attributes'), $this->l('Customers'), $this->l('Addresses'), $this->l('Manufacturers'), $this->l('Suppliers'))); switch (intval(Tools::getValue('entity'))) { case $this->entities[$this->l('Attributes')]: self::$required_fields = array('id_product', 'options'); $this->available_fields = array( 'no' => $this->l('Ignore this column'), 'id_product' => $this->l('Product ID'), 'options' => $this->l('Options'), 'reference' => $this->l('Reference'), 'supplier_reference' => $this->l('Supplier reference'), 'ean13' => $this->l('EAN13'), 'wholesale_price' => $this->l('Wholesale price'), 'price' => $this->l('Price'), 'ecotax' => $this->l('Ecotax'), 'quantity' => $this->l('Quantity'), 'weight' => $this->l('Weight'), 'default_on' => $this->l('Default') ); self::$default_values = array( 'reference' => '', 'supplier_reference' => '', 'ean13' => '', 'wholesale_price' => 0, 'price' => 0, 'ecotax' => 0, 'quantity' => 0, 'weight' => 0, 'default_on' => 0 ); break; case $this->entities[$this->l('Categories')]: $this->available_fields = array( 'no' => $this->l('Ignore this column'), 'id' => $this->l('ID'), 'active' => $this->l('Active (0/1)'), 'name' => $this->l('Name *'), 'parent' => $this->l('Parent category'), 'description' => $this->l('Description'), 'meta_title' => $this->l('Meta-title'), 'meta_keywords' => $this->l('Meta-keywords'), 'meta_description' => $this->l('Meta-description'), 'link_rewrite' => $this->l('URL rewrited'), 'image' => $this->l('Image URL'), ); self::$default_values = array( 'active' => '1', 'parent' => '1', 'link_rewrite' => '', ); break; case $this->entities[$this->l('Products')]: self::$validators['image'] = array('AdminImport', 'split'); $this->available_fields = array( 'no' => $this->l('Ignore this column'), 'id' => $this->l('ID'), 'active' => $this->l('Active (0/1)'), 'name' => $this->l('Name *'), 'category' => $this->l('Categories (x,y,z...)'), 'price_tex' => $this->l('Price tax excl.'), 'price_tin' => $this->l('Price tax incl.'), 'tax_rate' => $this->l('Tax rate'), 'wholesale_price' => $this->l('Wholesale price'), 'on_sale' => $this->l('On sale (0/1)'), 'reduction_price' => $this->l('Reduction amount'), 'reduction_percent' => $this->l('Reduction per cent'), 'reduction_from' => $this->l('Reduction from (yyyy-mm-dd)'), 'reduction_to' => $this->l('Reduction to (yyyy-mm-dd)'), 'reference' => $this->l('Reference #'), 'supplier_reference' => $this->l('Supplier reference #'), 'supplier' => $this->l('Supplier'), 'manufacturer' => $this->l('Manufacturer'), 'ean13' => $this->l('EAN13'), 'ecotax' => $this->l('Ecotax'), 'weight' => $this->l('Weight'), 'quantity' => $this->l('Quantity'), 'description_short' => $this->l('Short description'), 'description' => $this->l('Description'), 'tags' => $this->l('Tags (x,y,z...)'), 'meta_title' => $this->l('Meta-title'), 'meta_keywords' => $this->l('Meta-keywords'), 'meta_description' => $this->l('Meta-description'), 'available_now' => $this->l('Text when in-stock'), 'available_later' => $this->l('Text if back-order allowed'), 'image' => $this->l('Image URLs (x,y,z...)'), 'feature' => $this->l('Feature'), ); self::$default_values = array( 'id_category' => array(1), 'id_category_default' => 1, 'active' => '1', 'quantity' => 0, 'price' => 0, 'id_tax' => 0, 'description_short' => array(intval(Configuration::get('PS_LANG_DEFAULT')) => ''), 'link_rewrite' => array(intval(Configuration::get('PS_LANG_DEFAULT')) => '') ); break; case $this->entities[$this->l('Customers')]: //Overwrite required_fields AS only email is required whereas other entities self::$required_fields = array('email', 'passwd', 'lastname', 'firstname'); $this->available_fields = array( 'no' => $this->l('Ignore this column'), 'id' => $this->l('ID'), 'active' => $this->l('Active (0/1)'), 'id_gender' => $this->l('Gender ID (Mr = 1, Ms = 2, else 9)'), 'email' => $this->l('E-mail *'), 'passwd' => $this->l('Password *'), 'birthday' => $this->l('Birthday (yyyy-mm-dd)'), 'lastname' => $this->l('Lastname *'), 'firstname' => $this->l('Firstname *'), 'newsletter' => $this->l('Newsletter (0/1)'), 'optin' => $this->l('Optin (0/1)'), ); self::$default_values = array( 'active' => '1', ); break; case $this->entities[$this->l('Addresses')]: //Overwrite required_fields self::$required_fields = array('lastname', 'firstname', 'address1', 'postcode', 'country', 'city'); $this->available_fields = array( 'no' => $this->l('Ignore this column'), 'id' => $this->l('ID'), 'alias' => $this->l('Alias *'), 'active' => $this->l('Active (0/1)'), 'customer_email' => $this->l('Customer e-mail'), 'manufacturer' => $this->l('Manufacturer'), 'supplier' => $this->l('Supplier'), 'company' => $this->l('Company'), 'lastname' => $this->l('Lastname *'), 'firstname' => $this->l('Firstname *'), 'address1' => $this->l('Address 1 *'), 'address2' => $this->l('Address 2'), 'postcode' => $this->l('Postcode *'), 'city' => $this->l('City *'), 'country' => $this->l('Country *'), 'state' => $this->l('State'), 'other' => $this->l('Other'), 'phone' => $this->l('Phone'), 'phone_mobile' => $this->l('Mobile Phone'), ); self::$default_values = array( 'alias' => 'Alias', 'postcode' => 'X', ); break; case $this->entities[$this->l('Manufacturers')]: case $this->entities[$this->l('Suppliers')]: //Overwrite validators AS name is not MultiLangField but only description is needed AS MultiLangField self::$validators = array('description' => array('AdminImport', 'createMultiLangField')); $this->available_fields = array( 'no' => $this->l('Ignore this column'), 'id' => $this->l('ID'), 'name' => $this->l('Name *'), 'description' => $this->l('Description'), ); break; } parent::__construct(); } private static function getBoolean($field) { return (boolean)$field; } private static function getPrice($field) { $field = (floatval(str_replace(',', '.', $field))); $field = (floatval(str_replace('%', '', $field))); return $field; } private static function split($field) { $separator = is_null(Tools::getValue('multiple_value_separator')) ? ',' : Tools::getValue('multiple_value_separator'); $tab = explode($separator, $field); $res = array_map('strval', $tab); $res = array_map('trim', $tab); return $tab; } private static function createMultiLangField($field) { $languages = Language::getLanguages(); $res = array(); foreach ($languages AS $lang) $res[$lang['id_lang']] = $field; return $res; } private function getTypeValuesOptions($nb_c) { $i = 0; $noPreSelect = array('price_tin', 'feature'); $options = ''; foreach ($this->available_fields AS $k => $field) { $options .= '