From b992cc8488ca22ab5aa0571d3c437d418ab3cf0a Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 2 Jan 2014 10:30:24 +0100 Subject: [PATCH] delete all sub categories on category removal, fix issue #150 --- core/lib/Thelia/Model/Category.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/lib/Thelia/Model/Category.php b/core/lib/Thelia/Model/Category.php index 8f1dd8eb4..9108c159e 100755 --- a/core/lib/Thelia/Model/Category.php +++ b/core/lib/Thelia/Model/Category.php @@ -121,6 +121,15 @@ class Category extends BaseCategory { $this->markRewritenUrlObsolete(); + //delete all subcategories + $subCategories = CategoryQuery::findAllChild($this->getId()); + + foreach($subCategories as $category) { + $category->setDispatcher($this->getDispatcher()); + + $category->delete(); + } + $this->dispatchEvent(TheliaEvents::AFTER_DELETECATEGORY, new CategoryEvent($this)); } } \ No newline at end of file