// adding categories with shop association
This commit is contained in:
@@ -606,6 +606,7 @@ class AdminControllerCore extends Controller
|
||||
$parent_id = (int)Tools::getValue('id_parent', 1);
|
||||
$this->afterAdd($object);
|
||||
$this->updateAssoShop($object->id);
|
||||
// d($object);
|
||||
// Save and stay on same form
|
||||
if (Tools::isSubmit('submitAdd'.$this->table.'AndStay'))
|
||||
$this->redirect_after = self::$currentIndex.'&'.$this->identifier.'='.$object->id.'&conf=3&update'.$this->table.'&token='.$token;
|
||||
|
||||
@@ -1205,9 +1205,13 @@ class CategoryCore extends ObjectModel
|
||||
return $categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id_shop
|
||||
* @return bool
|
||||
*/
|
||||
public function isParentCategoryAvailable($id_shop)
|
||||
{
|
||||
return Db::getInstance()->getValue('
|
||||
return (bool)Db::getInstance()->getValue('
|
||||
SELECT c.`id_category`
|
||||
FROM `'._DB_PREFIX_.'category` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs
|
||||
@@ -1215,5 +1219,27 @@ class CategoryCore extends ObjectModel
|
||||
WHERE cs.`id_shop` = '.(int)$id_shop.'
|
||||
AND c.`id_parent` = '.(int)$this->id_parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add association between shop and cateogries
|
||||
* @param int $id_shop
|
||||
* @return bool
|
||||
*/
|
||||
public function addShop($id_shop)
|
||||
{
|
||||
$sql = '';
|
||||
if (!$id_shop)
|
||||
{
|
||||
foreach (Shop::getShops(true) as $shop)
|
||||
$sql .= '('.(int)$this->id.', '.(int)$shop['id_shop'].'),';
|
||||
// removing last comma to avoid SQL error
|
||||
$sql = substr($sql, 0, strlen($sql) - 1);
|
||||
} else
|
||||
$sql .= '('.(int)$this->id.', '.(int)$id_shop.')';
|
||||
|
||||
return Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'category_shop` (`id_category`, `id_shop`) VALUES
|
||||
'.$sql);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -433,6 +433,12 @@ class AdminCategoriesControllerCore extends AdminController
|
||||
{
|
||||
return strip_tags(stripslashes($description));
|
||||
}
|
||||
|
||||
public function afterAdd($object)
|
||||
{
|
||||
// associate the category to the context shop
|
||||
$object->addShop($this->context->shop->getID());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user