diff --git a/CHANGELOG.md b/CHANGELOG.md index 53b20dd27..b299c0bb4 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ #2.0.0-beta3 - Coupon effect inputs are now more customisable (input text, select, ajax, etc.. are usable) and unlimited amount of input for coupon effect are now possible too +- when a category is deleted, all subcategories are deleted +- delete products when categories are removed. Works only when the category is the default one for this product #2.0.0-beta2 diff --git a/core/lib/Thelia/Form/TaxCreationForm.php b/core/lib/Thelia/Form/TaxCreationForm.php index 65617e615..001bb3cf8 100644 --- a/core/lib/Thelia/Form/TaxCreationForm.php +++ b/core/lib/Thelia/Form/TaxCreationForm.php @@ -40,7 +40,7 @@ class TaxCreationForm extends BaseForm protected function buildForm($change_mode = false) { - $types = TaxEngine::getInstance()->getTaxTypeList(); + $types = TaxEngine::getInstance($this->getRequest()->getSession())->getTaxTypeList(); $typeList = array(); $requirementList = array(); foreach ($types as $type) { diff --git a/core/lib/Thelia/Model/Category.php b/core/lib/Thelia/Model/Category.php index 8f1dd8eb4..3924f4a99 100755 --- a/core/lib/Thelia/Model/Category.php +++ b/core/lib/Thelia/Model/Category.php @@ -5,6 +5,7 @@ namespace Thelia\Model; use Thelia\Core\Event\Category\CategoryEvent; use Thelia\Model\Base\Category as BaseCategory; use Propel\Runtime\ActiveQuery\Criteria; +use Thelia\Model\ProductCategoryQuery; use Thelia\Tools\URL; use Thelia\Core\Event\TheliaEvents; use Propel\Runtime\Connection\ConnectionInterface; @@ -62,6 +63,22 @@ class Category extends BaseCategory $query->filterByParent($this->getParent()); } + public function deleteProducts(ConnectionInterface $con = null) + { + $productsCategories = ProductCategoryQuery::create() + ->filterByCategoryId($this->getId()) + ->filterByDefaultCategory(1) + ->find($con); + + if($productsCategories) { + foreach ($productsCategories as $productCategory) { + $product = $productCategory->getProduct(); + + $product->delete($con); + } + } + } + /** * {@inheritDoc} */ @@ -111,6 +128,7 @@ class Category extends BaseCategory "parent" => $this->getParent(), ) ); + $this->deleteProducts($con); return true; } @@ -121,6 +139,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