Скрипт для удаления товаров и групп в зависимости от выбранных параметров
<?php
/**
* Скрипт который удаляет товары и группы в зависимости от выбранных параметров
*
* @author Kozub Boris, KAD Systems (©) 2014
* @date 10-12-2014
*/
// Удаление групп
$delGroups = false;
// Количество товаров за шаг
$stepCount = 1000;
// Id родительской группы, если не задан то не используется
$parentGroupId = 0;
// Id интернет магазина, если не задан то выборка делается из всех товаров
$shopId = 0;
$oItems = Core_Entity::factory('shop_item');
// Выборка из родительской группы и ее подгрупп
if($parentGroupId)
{
$aGroupsId = array();
// Массив групп
$aGroupsId[] = $parentGroupId;
$aoCurGroups = array(Core_Entity::factory('Shop_group', $parentGroupId));
do
{
$aoParGroups = $aoCurGroups;
$aCurGroupsId = array();
$aoCurGroups = array();
foreach($aoParGroups as $oParGroup)
{
$aCurGroupsId[] = $oParGroup->id;
$aGroupsId[] = $oParGroup->id;
}
$oGroups = Core_Entity::factory('Shop_group');
$oGroups->queryBuilder()
->where('parent_id', 'IN', $aCurGroupsId);
$aoCurGroups = $oGroups->findAll();
} while (count($aoCurGroups) != 0);
$oItems->queryBuilder()
->where('shop_group_id', 'IN', $aGroupsId);
}
// Выборка из интернет магазина
if($shopId)
{
$oItems->queryBuilder()
->where('shop_id', '=', $shopId);
}
$oItems->queryBuilder()
->limit($stepCount);
$aoItems = $oItems->findAll();
$delCount = 0;
foreach ($aoItems as $oItem)
{
if($oItem->delete())
{
$delCount++;
}
}
print '<br/>' . $delCount . ' items deleted!';
if(count($aoItems) == $stepCount)
{
$RedirectTime = 500;
Core::factory('Core_Html_Entity_Script')
->type('text/javascript')
->value('setTimeout(location.reload(), ' . $RedirectTime . ')')
->execute();
}
else
{
if($delGroups)
{
$groupDelCount = 0;
if($shopId)
{
$aoDelGroups = Core_Entity::factory('Shop_group')->getAllByShop_id($shopId);
}
elseif(isset($aGroupsId) && count($aGroupsId))
{
$oDelGroups = Core_Entity::factory('Shop_group');
$oDelGroups->queryBuilder()
->where('id', 'IN', $aGroupsId);
$aoDelGroups = $oDelGroups->findAll();
}
else
{
$aoDelGroups = Core_Entity::factory('Shop_group')->findAll();
}
if(count($aoDelGroups))
{
foreach($aoDelGroups as $oDelGroup)
{
$oDelGroup->delete();
$groupDelCount++;
}
}
print '<br/>' . $groupDelCount . ' groups deleted!';
}
}