diff --git a/adm/helpers/HelperFormBootstrap.php b/adm/helpers/HelperFormBootstrap.php index 77ffdd6b..2c69d4d7 100644 --- a/adm/helpers/HelperFormBootstrap.php +++ b/adm/helpers/HelperFormBootstrap.php @@ -107,7 +107,7 @@ class HelperFormBootstrap{
-
'; + '; if(isset($form['information'])) { $this->_html .= '

'.$form['information'].'

'; } @@ -389,7 +389,7 @@ class HelperFormBootstrap{ public function inputSwitch($p = array()) { $this->_html .=' -
+
'.(isset($p['label'])?'':'').'
@@ -398,16 +398,7 @@ class HelperFormBootstrap{
-
- '; +
'; } public function inputText($p = array()){ diff --git a/adm/helpers/includes/js/custom.js b/adm/helpers/includes/js/custom.js index 709093f2..38cf6ce9 100644 --- a/adm/helpers/includes/js/custom.js +++ b/adm/helpers/includes/js/custom.js @@ -54,4 +54,10 @@ $(function() { } reader.readAsDataURL(file); }); + + var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch')); + + elems.forEach(function(html) { + var switchery = new Switchery(html, { size: 'small', color: '#504d8b' }); + }); }); \ No newline at end of file diff --git a/modules/ant_creationcategories/AdminAntCreationcategories.php b/modules/ant_creationcategories/AdminAntCreationcategories.php index a71c94b7..7958bcf7 100644 --- a/modules/ant_creationcategories/AdminAntCreationcategories.php +++ b/modules/ant_creationcategories/AdminAntCreationcategories.php @@ -5,7 +5,7 @@ if(!defined('_PS_VERSION_')) { include_once(_PS_ROOT_DIR_.'/modules/privatesales/Sale.php'); require_once(PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php'); require_once(PS_ADMIN_DIR . '/helpers/HelperList.php'); -//require_once '..'._MODULE_DIR_.'categoryfamily/models/CategoryFamily.php'; +require_once(_PS_ROOT_DIR_.'/modules/categoryfamily/models/CategoryFamily.php'); class AdminAntCreationcategories extends AdminTab { @@ -47,6 +47,10 @@ class AdminAntCreationcategories extends AdminTab if(Tools::getValue('subcategories')) { $subcategories = Tools::getValue('subcategories'); $subcategories = explode(',',$subcategories); + if(Tools::getValue('subfamilies') && Tools::getValue('families')) { + $families = Tools::getValue('families'); + $subfamilies = Tools::getValue('subfamilies'); + } foreach ($subcategories as $key => $name) { $meta_name = 'Vente privée '.$name; $subcategory = new Category(); @@ -66,6 +70,12 @@ class AdminAntCreationcategories extends AdminTab $subcategory->link_rewrite[3] = $subcategory->link_rewrite[2]; $subcategory->groupBox = $groups; $subcategory->add(); + + if(isset($subfamilies) && isset($subfamilies[$key]))){ + CategoryFamilyCore::addAssociations2($subcategory->id, $subfamilies[$key]); + } elseif (isset($families) && isset($families[$key]))){ + CategoryFamilyCore::addAssociations2($subcategory->id, $families[$key]); + } } } } @@ -78,6 +88,10 @@ class AdminAntCreationcategories extends AdminTab if(Tools::getValue('subcategories2')) { $subcategories = Tools::getValue('subcategories2'); $subcategories = explode(',',$subcategories); + if(Tools::getValue('subfamilies') && Tools::getValue('families')) { + $families = Tools::getValue('families'); + $subfamilies = Tools::getValue('subfamilies'); + } foreach ($subcategories as $key => $name) { $meta_name = 'Vente privée '.$name; $subcategory = new Category(); @@ -97,6 +111,12 @@ class AdminAntCreationcategories extends AdminTab $subcategory->link_rewrite[3] = $subcategory->link_rewrite[2]; $subcategory->groupBox = $groups; $subcategory->add(); + + if(isset($subfamilies) && isset($subfamilies[$key])){ + CategoryFamilyCore::addAssociations2($subcategory->id, $subfamilies[$key]); + } elseif (isset($families) && isset($families[$key]))){ + CategoryFamilyCore::addAssociations2($subcategory->id, $families[$key]); + } } Category::regenerateEntireNtree(); HelperFormBootstrap::echoConfirmation('Sous catégories créées'); @@ -140,6 +160,7 @@ class AdminAntCreationcategories extends AdminTab 'title' => $this->l('Creation Catégories'), 'icon' => ' ', 'class' => 'form-horizontal', + 'id' => 'form1', 'class_div' => 'col-md-12', 'information' => 'Création de catégories multiples', 'sections' => array( @@ -173,8 +194,9 @@ class AdminAntCreationcategories extends AdminTab 'label' => $this->l('Ajouter les familles'), 'label-class' => 'col-md-2', 'input-class' => 'col-md-6', + 'class-group' => 'switch', 'name' => 'family', - 'title' => 'Activer', + 'title' => ' ', ), ), ), @@ -194,6 +216,7 @@ class AdminAntCreationcategories extends AdminTab 'title' => $this->l('Creation Sous Catégories'), 'icon' => ' ', 'class' => 'form-horizontal', + 'id' => 'form2', 'class_div' => 'col-md-12', 'information' => 'Création de sous-catégories ayant un parent existant', 'sections' => array( @@ -216,6 +239,15 @@ class AdminAntCreationcategories extends AdminTab 'id_tag' => 'tag_subcategories2', 'info' => 'Renseigner un nom et ajouter en appuyant sur Entrer
Ajouter autant de nom que de catégories souhaitées' ), + array( + 'type' => 'switch', + 'label' => $this->l('Ajouter les familles'), + 'label-class' => 'col-md-2', + 'input-class' => 'col-md-6', + 'class-group' => 'switch', + 'name' => 'family', + 'title' => ' ', + ), ), ), ), @@ -231,25 +263,103 @@ class AdminAntCreationcategories extends AdminTab ) ); - // $families = array(); - // foreach(CategoryFamilyCore::getParentFamily($cookie->id_lang) as $row) { - // $families[] = array( - // 'label' => $row['name'], - // 'value' => (int) $row['id_category_family'] - // ); - // } + $families = array(); + foreach(CategoryFamilyCore::getParentFamily($cookie->id_lang) as $row) { + $families[] = array( + 'label' => $row['name'], + 'value' => (int) $row['id_category_family'] + ); + } $helperForm->_js .=' '; $form .= $helperForm->renderStyle(); @@ -272,4 +382,13 @@ class AdminAntCreationcategories extends AdminTab return $string; } + + public function generateSelectFamilies($families){ + $selectFamily = '
'; + return $selectFamily; + } } \ No newline at end of file diff --git a/modules/categoryfamily/ajax_2.php b/modules/categoryfamily/ajax_2.php new file mode 100644 index 00000000..1b088741 --- /dev/null +++ b/modules/categoryfamily/ajax_2.php @@ -0,0 +1,32 @@ + + +
'; +} else { + $select = ''; +} + +$data['data'] = $select; +$data['id_before'] = (int)$id_select; +$data['id_select'] = (int)$select_upd; +die(json_encode($data)); diff --git a/modules/categoryfamily/models/CategoryFamily.php b/modules/categoryfamily/models/CategoryFamily.php index 3b05bce9..18b179d9 100755 --- a/modules/categoryfamily/models/CategoryFamily.php +++ b/modules/categoryfamily/models/CategoryFamily.php @@ -133,6 +133,24 @@ class CategoryFamilyCore extends ObjectModel { return TRUE; } + public static function addAssociations2($id_category, $family) { + self::deleteAssociations($id_category); + + if (isset($family)) { + Db::getInstance()->execute(' + INSERT INTO + `'._DB_PREFIX_.'category_family_association` + (`id_category_family`, `id_category`) + VALUES ( + '.(int)$family.', + '.(int)$id_category.' + ) + '); + } + + return true; + } + public static function loadAssociations($id_category, $id_lang) { global $cookie, $smarty; $category_family = array();