/**
  * 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
     // \CommerceTeam\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 (!empty($childCategories)) {
         foreach ($childCategories as $childCategoryUid) {
             $products = $this->belib->getProductsOfCategory($childCategoryUid);
             if (!empty($products)) {
                 $productList = array();
                 foreach ($products as $product) {
                     $productList[] = $product['uid_local'];
                     $articles = $this->belib->getArticlesOfProduct($product['uid_local']);
                     if (!empty($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);
     }
 }
Example #2
0
 /**
  * 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((array) $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 (!empty($products)) {
             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);
         }
     }
 }