Last active
September 10, 2021 15:09
-
-
Save PululuK/c1cb4a6228d095b01c3055e14541a97d to your computer and use it in GitHub Desktop.
Assign all groups in all categories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require (dirname(__FILE__) . '/config/config.inc.php'); | |
$scriptKey = 'xjkhjiauuhgiu855wbgfb'; | |
if(Tools::getValue('scriptKey') != $scriptKey){ | |
die('403'); | |
} | |
$categories = (new PrestaShopCollection('Category'))->getResults(); | |
$excludedCategories = [1,2]; // roots categories | |
$newGroups = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' | |
SELECT g.`id_group` | |
FROM `' . _DB_PREFIX_ . 'group` g' | |
); | |
if(!empty($categories)){ | |
foreach ($categories as $categorieObject){ | |
if(!Validate::isLoadedObject($categorieObject) || in_array($categorieObject->id,$excludedCategories)){ | |
continue; | |
} | |
$categorieCurrentGroupsId = $categorieObject->getGroups(); | |
// Assing news groups if not exist. | |
foreach($newGroups as $group){ | |
$groupId = (int) $group['id_group']; | |
if(!in_array($groupId, $categorieCurrentGroupsId)){ | |
$categorieObject->addGroups([$groupId]); | |
echo 'Group '.$groupId.' add in categorie '.$categorieObject->id.'<br>'; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment