/** * Delete all categories->products->articles if a category should be deleted. * This one does NOT delete any relations! * This is not wanted because you might want to * restore deleted categories, products or articles. * * @param int $categoryUid Category uid * * @return void */ protected function deleteChildCategoriesProductsArticlesPricesOfCategory($categoryUid) { // we dont use Tx_Commerce_Domain_Model_Category::getChildCategoriesUidlist // because of performance issues // @todo is there realy a performance issue? $childCategories = array(); $this->belib->getChildCategories($categoryUid, $childCategories, 0, 0, TRUE); if (count($childCategories)) { foreach ($childCategories as $childCategoryUid) { $products = $this->belib->getProductsOfCategory($childCategoryUid); if (count($products)) { $productList = array(); foreach ($products as $product) { $productList[] = $product['uid_local']; $articles = $this->belib->getArticlesOfProduct($product['uid_local']); if (count($articles)) { $articleList = array(); foreach ($articles as $article) { $articleList[] = $article['uid']; } $this->deletePricesByArticleList($articleList); $this->deleteArticlesByArticleList($articleList); } } $this->deleteProductsByProductList($productList); $this->deleteProductTranslationsByProductList($productList); } } $this->deleteCategoriesByCategoryList($childCategories); $this->deleteCategoryTranslationsByCategoryList($childCategories); } }
/** * Save category relations * * @param int $cUid Categor uid * @param array $fieldArray Field array * @param bool $saveAnyway Save anyway * @param bool $delete Delete * @param bool $updateXml Update xml * * @return void */ protected function saveCategoryRelations($cUid, array $fieldArray = array(), $saveAnyway = FALSE, $delete = TRUE, $updateXml = TRUE) { // now we have to save all attribute relations for this category and all their // child categories but only if the fieldArray has changed if (isset($fieldArray['attributes']) || $saveAnyway) { // get all parent categories ... $catList = array(); $this->belib->getParentCategories($cUid, $catList, $cUid, 0, FALSE); // get all correlation types $correlationTypeList = $this->belib->getAllCorrelationTypes(); // get their attributes $paList = $this->belib->getAttributesForCategoryList($catList); // Then extract all attributes from this category and merge it into the // attribute list if (!empty($fieldArray['attributes'])) { $ffData = (array) GeneralUtility::xml2array($fieldArray['attributes']); } else { $ffData = array(); } if (!is_array($ffData['data']) || !is_array($ffData['data']['sDEF'])) { $ffData = array(); } $this->belib->mergeAttributeListFromFFData($ffData['data']['sDEF']['lDEF'], 'ct_', $correlationTypeList, $cUid, $paList); // get the list of uid_foreign and save relations for this category $uidList = $this->belib->extractFieldArray($paList, 'uid_foreign', TRUE, array('uid_correlationtype')); $this->belib->saveRelations($cUid, $uidList, 'tx_commerce_categories_attributes_mm', $delete, FALSE); // update the XML structure if needed if ($updateXml) { $this->belib->updateXML('attributes', 'tx_commerce_categories', $cUid, 'category', $correlationTypeList); } // save all attributes of this category into all poroducts, // that are related to it $products = $this->belib->getProductsOfCategory($cUid); if (count($products) > 0) { foreach ($products as $product) { $this->belib->saveRelations($product['uid_local'], $uidList, 'tx_commerce_products_attributes_mm', FALSE, FALSE); $this->belib->updateXML('attributes', 'tx_commerce_products', $product['uid_local'], 'product', $correlationTypeList); } } // get children of this category after this operation the childList contains // all categories that are related to this category (recursively) $childList = array(); $this->belib->getChildCategories($cUid, $childList, $cUid, 0, FALSE); foreach ($childList as $childUid) { $this->saveCategoryRelations($childUid, NULL, TRUE, FALSE); } } }