If new group is added, It will be automatically added in the Group Access of all categories. So that all categories(locations/hotels) can be accessed by the customers connected to that added group

This commit is contained in:
sumit panwar
2021-01-29 21:37:16 +05:30
parent 6b7ef21e3a
commit d2b49200d5
2 changed files with 40 additions and 1 deletions

View File

@@ -1367,6 +1367,45 @@ class CategoryCore extends ObjectModel
VALUES ('.(int)Context::getContext()->shop->getCategory().', '.(int)$id_group.')');
}
/**
* Assign one (ore more) group to all categories
* @param int|array $id_group_list group id or list of group ids
* @param array $exception list of id Categories to ignore
*/
public static function assignGroupToAllCategories($idGroupList, $exception = null)
{
if (!is_array($idGroupList)) {
$idGroupList = array($idGroupList);
}
Db::getInstance()->execute(
'DELETE FROM `'._DB_PREFIX_.'category_group`
WHERE `id_group` IN ('.join(',', $idGroupList).')'
);
$categoryList = Db::getInstance()->executeS(
'SELECT id_category FROM `'._DB_PREFIX_.'category` '.
(is_array($exception) ? ' WHERE id_category NOT IN ('.join(',', $exception).')' : '')
);
if ($categoryList) {
$data = array();
foreach ($categoryList as $category) {
foreach ($idGroupList as $idGroup) {
$data[] = array(
'id_category' => $category['id_category'],
'id_group' => $idGroup,
);
}
}
return Db::getInstance()->insert('category_group', $data, false, false);
}
return true;
}
public function updatePosition($way, $position)
{
if (!$res = Db::getInstance()->executeS('

View File

@@ -163,7 +163,7 @@ class GroupCore extends ObjectModel
{
Configuration::updateGlobalValue('PS_GROUP_FEATURE_ACTIVE', '1');
if (parent::add($autodate, $null_values)) {
Category::setNewGroupForHome((int)$this->id);
Category::assignGroupToAllCategories((int)$this->id);
Carrier::assignGroupToAllCarriers((int)$this->id);
return true;
}