Last active
November 6, 2015 12:25
-
-
Save maxout/355a89afafda5d956680 to your computer and use it in GitHub Desktop.
Shopware delete all empty 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 | |
/** | |
* 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