/**
  * 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);
         }
     }
 }