Skip to content

Instantly share code, notes, and snippets.

@maxout
Last active November 6, 2015 12:25
Show Gist options
  • Save maxout/355a89afafda5d956680 to your computer and use it in GitHub Desktop.
Save maxout/355a89afafda5d956680 to your computer and use it in GitHub Desktop.
Shopware delete all empty Categories
<?php
/**
* Delete all empty Categories
* @return int
*/
public function deleteEmptyCategories()
{
$acSql = "select * from s_categories
left join s_articles_categories_ro ro
on ro.categoryID = s_categories.id
left join s_categories_attributes attr on attr.categoryID = s_categories.id
where ro.id IS NULL
and s_categories.parent is not null
and s_categories.blog=false";
$categoryIds = Shopware()->Db()->fetchAll($acSql);
foreach ($categoryIds as $catId) {
try {
$this->getShopwareCategoryResource()->delete($catId['categoryID']);
} catch (\Exception $e) {
//do nothing
}
}
return count($categoryIds);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment