id_lang)) AS $row){
$groups[] = $row['id_group'];
}
$date = date('Y') . '-' . date('m');
$name = Tools::getValue('category');
$meta_name = 'Vente privée '.$name;
$meta_name_es = 'Venta privada '.$name;
$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;
$category->meta_title[2] = $meta_name;
$category->meta_title[3] = $meta_name_es;
$category->meta_keywords[2] = $meta_name;
$category->meta_keywords[3] = $meta_name_es;
$category->meta_description[2] = $meta_name;
$category->meta_description[3] = $meta_name_es;
$category->link_rewrite[2] = $this->str2url($name);
$category->link_rewrite[3] = $category->link_rewrite[2];
$category->groupBox = $groups;
if($category->add()) {
if (isset($_FILES['image_thumb']) && $_FILES['image_thumb']['name'] != NULL) {
copy($_FILES['image_thumb']['tmp_name'], _PS_CAT_IMG_DIR_.$category->id.'_thumb_vp_2.jpg');
copy($_FILES['image_thumb']['tmp_name'], _PS_CAT_IMG_DIR_.$category->id.'_thumb_vp_3.jpg');
}
if (isset($_FILES['image_mobile']) && $_FILES['image_mobile']['name'] != NULL) {
copy($_FILES['image_mobile']['tmp_name'], _PS_CAT_IMG_DIR_.$category->id.'_mobile_vp_2.jpg');
copy($_FILES['image_mobile']['tmp_name'], _PS_CAT_IMG_DIR_.$category->id.'_mobile_vp_3.jpg');
}
if (isset($_FILES['image_category']) && $_FILES['image_category']['name'] != NULL) {
copy($_FILES['image_category']['tmp_name'], _PS_CAT_IMG_DIR_.$category->id.'.jpg');
if (file_exists(_PS_CAT_IMG_DIR_.$category->id.'.jpg')) {
$imagesTypes = ImageType::getImagesTypes('categories');
foreach ($imagesTypes AS $k => $imageType) {
imageResize(_PS_CAT_IMG_DIR_.$category->id.'.jpg', _PS_CAT_IMG_DIR_.$category->id.'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height']));
}
}
}
if(Tools::getValue('subcategories')) {
$subcategories = Tools::getValue('subcategories');
$subcategories = explode(';',$subcategories);
if(Tools::getValue('families')) {
$families = Tools::getValue('families');
if(Tools::getValue('subfamilies')) {
$subfamilies = Tools::getValue('subfamilies');
}
}
foreach ($subcategories as $key => $name) {
$meta_name = 'Vente privée '.$name;
$meta_name_es = 'Venta privada '.$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->meta_title[2] = $meta_name;
$subcategory->meta_title[3] = $meta_name_es;
$subcategory->meta_keywords[2] = $meta_name;
$subcategory->meta_keywords[3] = $meta_name_es;
$subcategory->meta_description[2] = $meta_name;
$subcategory->meta_description[3] = $meta_name_es;
$subcategory->link_rewrite[2] = $this->str2url($name);
$subcategory->link_rewrite[3] = $subcategory->link_rewrite[2];
$subcategory->groupBox = $groups;
$subcategory->add();
if(isset($families) && isset($families[$key]) && (int)$families[$key] != 0) {
if(isset($subfamilies) && isset($subfamilies[$key]) && (int)$subfamilies[$key] != 0) {
CategoryFamilyCore::addAssociations2($subcategory->id, $subfamilies[$key]);
} else {
CategoryFamilyCore::addAssociations2($subcategory->id, $families[$key]);
}
}
}
}
}
Category::regenerateEntireNtree();
HelperFormBootstrap::echoConfirmation('Catégories créées');
}
} elseif(Tools::isSubmit('submitAddSubCategories')) {
if(Tools::getValue('id_parent')) {
$groups = array();
foreach (Group::getGroups((int)($cookie->id_lang)) AS $row){
$groups[] = $row['id_group'];
}
$id_parent = (int) Tools::getValue('id_parent');
if(Tools::getValue('category_child')) {
$id_parent = (int) Tools::getValue('category_child');
}
$date = date('Y') . '-' . date('m');
if(Tools::getValue('subcategories2')) {
$subcategories = Tools::getValue('subcategories2');
$subcategories = explode(';',$subcategories);
if(Tools::getValue('families')) {
$families = Tools::getValue('families');
if(Tools::getValue('subfamilies')) {
$subfamilies = Tools::getValue('subfamilies');
}
}
foreach ($subcategories as $key => $name) {
$meta_name = 'Vente privée '.$name;
$meta_name_es = 'Venta privada '.$name;
$subcategory = new Category();
$subcategory->id_parent = (int)$id_parent;
$subcategory->active = 1;
$subcategory->name[2] = $name;
$subcategory->name[3] = $name;
$subcategory->description[2] = $date;
$subcategory->description[3] = $date;
$subcategory->meta_title[2] = $meta_name;
$subcategory->meta_title[3] = $meta_name_es;
$subcategory->meta_keywords[2] = $meta_name;
$subcategory->meta_keywords[3] = $meta_name_es;
$subcategory->meta_description[2] = $meta_name;
$subcategory->meta_description[3] = $meta_name_es;
$subcategory->link_rewrite[2] = $this->str2url($name);
$subcategory->link_rewrite[3] = $subcategory->link_rewrite[2];
$subcategory->groupBox = $groups;
$subcategory->add();
if(isset($families) && isset($families[$key]) && (int)$families[$key] != 0) {
if(isset($subfamilies) && isset($subfamilies[$key]) && (int)$subfamilies[$key] != 0) {
CategoryFamilyCore::addAssociations2($subcategory->id, $subfamilies[$key]);
} else {
CategoryFamilyCore::addAssociations2($subcategory->id, $families[$key]);
}
}
}
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;
$helperForm->_inputSwitch = 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
AND c.id_parent = 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' => ' ',
'class' => 'form-horizontal',
'id' => 'form1',
'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' => 'uploadImage',
'label' => $this->l('Logo : '),
'label-class' => 'col-md-2',
'input-class' => 'col-md-6',
'name' => 'image_thumb',
'id' => 'preview_thumb',
),
array(
'type' => 'uploadImage',
'label' => $this->l('Image Latérale : '),
'label-class' => 'col-md-2',
'input-class' => 'col-md-6',
'name' => 'image_category',
'id' => 'preview_category',
),
// array(
// 'type' => 'uploadImage',
// 'label' => $this->l('Image Application : '),
// 'label-class' => 'col-md-2',
// 'input-class' => 'col-md-6',
// 'name' => 'image_mobile',
// 'id' => 'preview_mobile',
// ),
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',
'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' => ' ',
),
),
),
),
'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' => ' ',
'class' => 'form-horizontal',
'id' => 'form2',
'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',
'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' => ' ',
),
),
),
),
'actions' => array(
array(
'type' => 'submit',
'class' => 'btn-primary',
'name' => 'submitAddSubCategories',
'value' => $this->l('Ajouter les sous catégories')
)
),
'actions-class' => 'text-right',
)
);
$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();
$form .= '