From 85c6e799c36fa5a45ccddb70b2fa55aec79bc0b0 Mon Sep 17 00:00:00 2001 From: indesign47 Date: Sat, 12 Oct 2013 11:33:36 +0200 Subject: [PATCH 1/5] [+] BO : AdminImport add entity Alias --- controllers/admin/AdminImportController.php | 75 ++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/controllers/admin/AdminImportController.php b/controllers/admin/AdminImportController.php index 58fa8f527..ffbf617b1 100644 --- a/controllers/admin/AdminImportController.php +++ b/controllers/admin/AdminImportController.php @@ -88,6 +88,7 @@ class AdminImportControllerCore extends AdminController $this->l('Addresses'), $this->l('Manufacturers'), $this->l('Suppliers'), + $this->l('Alias'), ); // @since 1.5.0 @@ -360,7 +361,6 @@ class AdminImportControllerCore extends AdminController 'postcode' => 'X' ); break; - case $this->entities[$this->l('Manufacturers')]: case $this->entities[$this->l('Suppliers')]: //Overwrite validators AS name is not MultiLangField @@ -392,6 +392,23 @@ class AdminImportControllerCore extends AdminController 'shop' => Shop::getGroupFromShop(Configuration::get('PS_SHOP_DEFAULT')), ); break; + case $this->entities[$this->l('Alias')]: + //Overwrite required_fields + $this->required_fields = array( + 'alias', + 'search', + ); + $this->available_fields = array( + 'no' => array('label' => $this->l('Ignore this column')), + 'id' => array('label' => $this->l('ID')), + 'alias' => array('label' => $this->l('Alias *')), + 'search' => array('label' => $this->l('Search *')), + 'active' => array('label' => $this->l('Active')), + ); + self::$default_values = array( + 'active' => '1', + ); + break; } // @since 1.5.0 @@ -2435,6 +2452,56 @@ class AdminImportControllerCore extends AdminController $this->closeCsvFile($handle); } + public function aliasImport() + { + $this->receiveTab(); + $handle = $this->openCsvFile(); + AdminImportController::setLocale(); + for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) + { + if (Tools::getValue('convert')) + $line = $this->utf8EncodeArray($line); + $info = AdminImportController::getMaskedRow($line); + + AdminImportController::setDefaultValues($info); + + if (Tools::getValue('forceIDs') && isset($info['id']) && (int)$info['id']) + $alias = new Alias((int)$info['id']); + else + { + if (array_key_exists('id', $info) && (int)$info['id'] && Alias::existsInDatabase((int)$info['id'], 'alias')) + $alias = new Alias((int)$info['id']); + else + $alias = new Alias(); + } + + AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $alias); + + $res = false; + if (($field_error = $alias->validateFields(UNFRIENDLY_ERROR, true)) === true && + ($lang_field_error = $alias->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) + { + if ($alias->id && $alias->aliasExists($alias->id)) + $res = $alias->update(); + if (!$res) + $res = $alias->add(); + + if (!$res) + $this->errors[] = Db::getInstance()->getMsgError().' '.sprintf( + Tools::displayError('%1$s (ID: %2$s) cannot be saved'), + $info['name'], + (isset($info['id']) ? $info['id'] : 'null') + ); + } + else + { + $this->errors[] = $this->l('Alias is invalid').' ('.$alias->name.')'; + $this->errors[] = ($field_error !== true ? $field_error : '').(isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : ''); + } + } + $this->closeCsvFile($handle); + } + /** * @since 1.5.0 */ @@ -2782,6 +2849,9 @@ class AdminImportControllerCore extends AdminController if (preg_match('/^[0-9]+(\-(.*))?\.jpg$/', $d)) unlink(_PS_SUPP_IMG_DIR_.$d); break; + case $this->entities[$this->l('Alias')]: + Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'alias`'); + break; } Image::clearTmpDir(); return true; @@ -2880,6 +2950,9 @@ class AdminImportControllerCore extends AdminController $this->supplierImport(); $this->clearSmartyCache(); break; + case $this->entities[$import_type = $this->l('Alias')]: + $this->aliasImport(); + break; } // @since 1.5.0 From 2afbe8fd04b3c3b43d75cea97db1f51cc31d7775 Mon Sep 17 00:00:00 2001 From: indesign47 Date: Sat, 12 Oct 2013 11:39:29 +0200 Subject: [PATCH 2/5] Create alias_import.csv --- docs/csv_import/alias_import.csv | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 docs/csv_import/alias_import.csv diff --git a/docs/csv_import/alias_import.csv b/docs/csv_import/alias_import.csv new file mode 100644 index 000000000..b64a435be --- /dev/null +++ b/docs/csv_import/alias_import.csv @@ -0,0 +1,3 @@ +id;Alias *;Search *;Active (0/1) +3;microsft,micro;microsoft;1 +4;adbe,adaub;adobe;1 From 4f9191fe0c037efa1066325d90e512590f38ed85 Mon Sep 17 00:00:00 2001 From: indesign47 Date: Sat, 12 Oct 2013 11:45:07 +0200 Subject: [PATCH 3/5] Update form.tpl --- .../template/controllers/import/helpers/form/form.tpl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/import/helpers/form/form.tpl b/admin-dev/themes/default/template/controllers/import/helpers/form/form.tpl index 09a50329f..181508404 100644 --- a/admin-dev/themes/default/template/controllers/import/helpers/form/form.tpl +++ b/admin-dev/themes/default/template/controllers/import/helpers/form/form.tpl @@ -77,6 +77,7 @@
  • {l s='Sample Addresses file'}
  • {l s='Sample Manufacturers file'}
  • {l s='Sample Suppliers file'}
  • +
  • {l s='Sample Alias file'}
  • {if $PS_ADVANCED_STOCK_MANAGEMENT}
  • {l s='Supply Orders sample file'}
  • {l s='Supply Orders Details sample file'}
  • @@ -203,12 +204,12 @@ }); $("select#entity").change(function(){ - if ($("#entity > option:selected").val() == 7 || $("#entity > option:selected").val() == 8) + if ($("#entity > option:selected").val() == 8 || $("#entity > option:selected").val() == 9) $("label[for=truncate],#truncate").hide(); else $("label[for=truncate],#truncate").show(); - if ($("#entity > option:selected").val() == 8) + if ($("#entity > option:selected").val() == 9) { $(".import_supply_orders_details").show(); $('input[name=multiple_value_separator]').val('|'); @@ -226,7 +227,7 @@ $(".import_products_categories, label[for=regenerate], #regenerate").show(); else $(".import_products_categories, label[for=regenerate], #regenerate").hide(); - if ($("#entity > option:selected").val() == 0 || $("#entity > option:selected").val() == 1 || $("#entity > option:selected").val() == 3 || $("#entity > option:selected").val() == 5 || $("#entity > option:selected").val() == 6) + if ($("#entity > option:selected").val() == 0 || $("#entity > option:selected").val() == 1 || $("#entity > option:selected").val() == 3 || $("#entity > option:selected").val() == 5 || $("#entity > option:selected").val() == 6 || $("#entity > option:selected").val() == 7) $("label[for=forceIDs], #forceIDs").show(); else $("label[for=forceIDs], #forceIDs").hide(); @@ -260,4 +261,4 @@ }); }; }); - \ No newline at end of file + From 0a441b9a4b79cc191f52e36bbd168e6552764cac Mon Sep 17 00:00:00 2001 From: indesign47 Date: Sat, 12 Oct 2013 11:49:27 +0200 Subject: [PATCH 4/5] Update Alias.php --- classes/Alias.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/classes/Alias.php b/classes/Alias.php index b6fda0903..932495206 100644 --- a/classes/Alias.php +++ b/classes/Alias.php @@ -124,5 +124,21 @@ class AliasCore extends ObjectModel { return Configuration::get('PS_ALIAS_FEATURE_ACTIVE'); } + + /** + * This method is allow to know if a alias exist for AdminImportController + * @since 1.5.7 + * @return bool + */ + public static function aliasExists($id_alias) + { + $row = Db::getInstance()->getRow(' + SELECT `id_alias` + FROM '._DB_PREFIX_.'alias a + WHERE a.`id_alias` = '.(int)$id_alias + ); + + return isset($row['id_alias']); + } } From f25a41878503bd00ae50cb230da1d500b755e82f Mon Sep 17 00:00:00 2001 From: indesign47 Date: Mon, 14 Oct 2013 19:20:38 +0200 Subject: [PATCH 5/5] Update Alias.php --- classes/Alias.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Alias.php b/classes/Alias.php index 932495206..386aa741d 100644 --- a/classes/Alias.php +++ b/classes/Alias.php @@ -127,7 +127,7 @@ class AliasCore extends ObjectModel /** * This method is allow to know if a alias exist for AdminImportController - * @since 1.5.7 + * @since 1.5.6.0 * @return bool */ public static function aliasExists($id_alias)