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