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(); if ($product) { $product->delete($con); } } } }
/** * Calculate next position relative to our default category */ protected function addCriteriaToPositionQuery($query) { // Find products in the same category $produits = ProductCategoryQuery::create()->filterByCategoryId($this->getDefaultCategoryId())->filterByDefaultCategory(true)->select('product_id')->find(); // Filtrer la requete sur ces produits if ($produits != null) { $query->filterById($produits, Criteria::IN); } }
/** * @inheritdoc */ protected function addCriteriaToPositionQuery(ProductCategoryQuery $query) { $query->filterByCategoryId($this->getCategoryId()); }
/** * Overload for the position management * @param Base\ProductCategory $productCategory * @inheritdoc */ protected function doAddProductCategory($productCategory) { parent::doAddProductCategory($productCategory); $productCategoryPosition = ProductCategoryQuery::create()->filterByCategoryId($productCategory->getCategoryId())->orderByPosition(Criteria::DESC)->findOne(); $productCategory->setPosition($productCategoryPosition !== null ? $productCategoryPosition->getPosition() + 1 : 1); }