Merge branch 'add-module-ant_creationcategories' into develop
This commit is contained in:
commit
7f34c09cf7
204
modules/ant_creationcategories/AdminAntCreationcategories.php
Normal file
204
modules/ant_creationcategories/AdminAntCreationcategories.php
Normal file
@ -0,0 +1,204 @@
|
||||
<?php
|
||||
if(!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
include_once(_PS_ROOT_DIR_.'/modules/privatesales/Sale.php');
|
||||
require_once(PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php');
|
||||
require_once(PS_ADMIN_DIR . '/helpers/HelperForm.php');
|
||||
require_once(PS_ADMIN_DIR . '/helpers/HelperList.php');
|
||||
|
||||
class AdminAntCreationcategories extends AdminTab
|
||||
{
|
||||
public function postProcess() {
|
||||
global $cookie;
|
||||
if(Tools::isSubmit('submitAddCategories')) {
|
||||
if(Tools::getValue('category')) {
|
||||
$date = date('Y') . '-' . date('m');
|
||||
$name = Tools::getValue('category');
|
||||
$category = new Category();
|
||||
$category->id_parent = 1;
|
||||
$category->active = 1;
|
||||
$category->name[2] = $name;
|
||||
$category->name[3] = $name;
|
||||
$category->description[2] = $date;
|
||||
$category->description[3] = $date;
|
||||
|
||||
if($category->add()) {
|
||||
if(Tools::getValue('subcategories')) {
|
||||
$subcategories = Tools::getValue('subcategories');
|
||||
$subcategories = explode(',',$subcategories);
|
||||
foreach ($subcategories as $key => $name) {
|
||||
$subcategory = new Category();
|
||||
$subcategory->id_parent = $category->id;
|
||||
$subcategory->active = 1;
|
||||
$subcategory->name[2] = $name;
|
||||
$subcategory->name[3] = $name;
|
||||
$subcategory->description[2] = $date;
|
||||
$subcategory->description[3] = $date;
|
||||
$subcategory->add();
|
||||
}
|
||||
}
|
||||
}
|
||||
Category::regenerateEntireNtree();
|
||||
HelperFormBootstrap::echoConfirmation('Catégories créées');
|
||||
}
|
||||
} elseif(Tools::isSubmit('submitAddSubCategories')) {
|
||||
if(Tools::getValue('id_parent')) {
|
||||
$id_parent = (int) Tools::getValue('id_parent');
|
||||
if(Tools::getValue('subcategories2')) {
|
||||
$subcategories = Tools::getValue('subcategories2');
|
||||
$subcategories = explode(',',$subcategories);
|
||||
foreach ($subcategories as $key => $name) {
|
||||
$subcategory = new Category();
|
||||
$subcategory->id_parent = $id_parent;
|
||||
$subcategory->active = 1;
|
||||
$subcategory->name[2] = $name;
|
||||
$subcategory->name[3] = $name;
|
||||
$subcategory->description[2] = $date;
|
||||
$subcategory->description[3] = $date;
|
||||
$subcategory->add();
|
||||
}
|
||||
Category::regenerateEntireNtree();
|
||||
HelperFormBootstrap::echoConfirmation('Sous catégories créées');
|
||||
} else {
|
||||
HelperFormBootstrap::echoError('Vous devez renseigner au moins une sous catégorie');
|
||||
}
|
||||
} else {
|
||||
HelperFormBootstrap::echoError('Vous devez selectionner une catégorie parente');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function display() {
|
||||
global $cookie, $currentIndex;
|
||||
|
||||
$form = '';
|
||||
|
||||
$base_link = $currentIndex . '&token='.Tools::getAdminTokenLite('AdminAntCreationcategories');
|
||||
$helperForm = new HelperFormBootstrap();
|
||||
$helperForm->_inputTag = true;
|
||||
$helperForm->_select2 = true;
|
||||
|
||||
$id_categories = array();
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT c.`id_category`, cl.`name`
|
||||
FROM `'._DB_PREFIX_.'category` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (cl.`id_category` = c.`id_category`)
|
||||
WHERE cl.`id_lang` = '.$cookie->id_lang.'
|
||||
AND c.active = 1
|
||||
ORDER BY c.`id_category` DESC
|
||||
') as $row) {
|
||||
$id_categories[] = array(
|
||||
'label' => '#'.$row['id_category'].' - '.$row['name'],
|
||||
'value' => (int) $row['id_category']
|
||||
);
|
||||
}
|
||||
$helperForm->_forms = array(
|
||||
array(
|
||||
'action' => $base_link,
|
||||
'title' => $this->l('Creation Catégories'),
|
||||
'icon' => '<span class="glyphicon glyphicon-list"></span> ',
|
||||
'class' => 'form-horizontal',
|
||||
'class_div' => 'col-md-12',
|
||||
'information' => 'Création de catégories multiples',
|
||||
'sections' => array(
|
||||
array(
|
||||
'inputs' => array(
|
||||
array(
|
||||
'type' => 'simpleText',
|
||||
'label' => $this->l('Catégorie : '),
|
||||
'label-class' => 'col-md-2',
|
||||
'input-class' => 'col-md-6',
|
||||
'name' => 'category',
|
||||
),
|
||||
array(
|
||||
'type' => 'tag',
|
||||
'label' => $this->l('Sous Catégorie : '),
|
||||
'label-class' => 'col-md-2',
|
||||
'input-class' => 'col-md-6',
|
||||
'name' => 'subcategories',
|
||||
'id_tag' => 'tag_subcategories',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'actions' => array(
|
||||
array(
|
||||
'type' => 'submit',
|
||||
'class' => 'btn-primary',
|
||||
'name' => 'submitAddCategories',
|
||||
'value' => $this->l('Ajouter les catégories')
|
||||
)
|
||||
),
|
||||
'actions-class' => 'text-right',
|
||||
),
|
||||
array(
|
||||
'action' => $base_link,
|
||||
'title' => $this->l('Creation Sous Catégories'),
|
||||
'icon' => '<span class="glyphicon glyphicon-list"></span> ',
|
||||
'class' => 'form-horizontal',
|
||||
'class_div' => 'col-md-12',
|
||||
'information' => 'Création de sous-catégories ayant un parent existant',
|
||||
'sections' => array(
|
||||
array(
|
||||
'inputs' => array(
|
||||
array(
|
||||
'type' => 'select2',
|
||||
'label' => $this->l('Catégorie Parente'),
|
||||
'select-class' => 'col-md-6',
|
||||
'label-class' => 'col-md-2',
|
||||
'options' => $id_categories,
|
||||
'name' => 'id_parent',
|
||||
),
|
||||
array(
|
||||
'type' => 'tag',
|
||||
'label' => $this->l('Sous Catégorie : '),
|
||||
'label-class' => 'col-md-2',
|
||||
'input-class' => 'col-md-6',
|
||||
'name' => 'subcategories2',
|
||||
'id_tag' => 'tag_subcategories2',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'actions' => array(
|
||||
array(
|
||||
'type' => 'submit',
|
||||
'class' => 'btn-primary',
|
||||
'name' => 'submitAddSubCategories',
|
||||
'value' => $this->l('Ajouter les sous catégories')
|
||||
)
|
||||
),
|
||||
'actions-class' => 'text-right',
|
||||
)
|
||||
);
|
||||
$helperForm->_js .='
|
||||
<script>
|
||||
function onAddTag(tag) {
|
||||
alert("Added a tag: " + tag);
|
||||
}
|
||||
|
||||
function onRemoveTag(tag) {
|
||||
alert("Removed a tag: " + tag);
|
||||
}
|
||||
|
||||
function onChangeTag(input, tag) {
|
||||
alert("Changed a tag: " + tag);
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$(\'#subcategories\').tagsInput({
|
||||
width: \'auto\'
|
||||
});
|
||||
$(\'#subcategories2\').tagsInput({
|
||||
width: \'auto\'
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
$form .= $helperForm->renderStyle();
|
||||
$form .= '<div class="row">'.$helperForm->renderForm(false, NULL, NULL, true).'</div>';
|
||||
$form .= $helperForm->renderScript();
|
||||
|
||||
echo $form;
|
||||
}
|
||||
}
|
40
modules/ant_creationcategories/ant_creationcategories.php
Normal file
40
modules/ant_creationcategories/ant_creationcategories.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
class Ant_Creationcategories extends Module
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'ant_creationcategories';
|
||||
$this->tab = 'administration';
|
||||
$this->author = 'Antadis';
|
||||
$this->version = '1.0';
|
||||
$this->need_instance = 0;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->displayName = $this->l('Creation de catégories multiple');
|
||||
$this->description = $this->l('Permet de créer une catégorie et ses sous catégories en même temps');
|
||||
}
|
||||
|
||||
public function install()
|
||||
{
|
||||
|
||||
if(!(parent::install())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function uninstall() {
|
||||
|
||||
if(parent::uninstall() == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user