function compareDatabaseRebuildProductsToCategoryTree($pid, $deepest_cat_id, $dataArray = array()) { if (!is_numeric($pid)) { return false; } if (!is_numeric($deepest_cat_id)) { return false; } $level = 1; $cats = mslib_fe::globalCrumbarTree($deepest_cat_id); $cats = array_reverse($cats); // $crumbar_ident_string = ''; $crumbar_ident_array = array(); foreach ($cats as $item) { $crumbar_ident_array[] = $item['id']; } $crumbar_ident_string = implode(',', $crumbar_ident_array); $count_cats = count($cats); /*if ($count_cats>1) { // remove the deepest cat id record // disabled by bas //unset($cats[$count_cats-1]); //recount //$count_cats=count($cats); }*/ if ($count_cats > 0) { foreach ($cats as $item) { if ($item['id']) { $rec = tx_mslib_catalog::isProductToCategoryLinkingExist($pid, $item['id'], $crumbar_ident_string); if (!$rec) { $insertArray = array(); if (!is_array($dataArray) || is_array($dataArray) && !count($dataArray)) { $insertArray['categories_id'] = $deepest_cat_id; $insertArray['products_id'] = $pid; $insertArray['page_uid'] = $item['page_uid']; $insertArray['sort_order'] = time(); $insertArray['related_to'] = 0; } else { foreach ($dataArray as $idx => $val) { $insertArray[$idx] = $val; } } $insertArray['node_id'] = $item['id']; if ($item['id'] == $deepest_cat_id) { $insertArray['is_deepest'] = 1; } else { $insertArray['is_deepest'] = 0; } $insertArray['crumbar_identifier'] = $crumbar_ident_string; $query = $GLOBALS['TYPO3_DB']->INSERTquery('tx_multishop_products_to_categories', $insertArray); $res = $GLOBALS['TYPO3_DB']->sql_query($query); } else { $updateArray = array(); if (!empty($rec['crumbar_identifier'])) { $tmp_cid = explode(',', $rec['crumbar_identifier']); $last_index = count($tmp_cid) - 1; if ($tmp_cid[$last_index] == $deepest_cat_id) { if ($item['id'] == $deepest_cat_id) { $updateArray['is_deepest'] = 1; } else { $updateArray['is_deepest'] = 0; } $updateArray['crumbar_identifier'] = $crumbar_ident_string; $query = $GLOBALS['TYPO3_DB']->UPDATEquery('tx_multishop_products_to_categories', 'products_to_categories_id=\'' . $rec['products_to_categories_id'] . '\'', $updateArray); $res = $GLOBALS['TYPO3_DB']->sql_query($query); } } else { if ($item['id'] == $deepest_cat_id) { $updateArray['is_deepest'] = 1; } else { $updateArray['is_deepest'] = 0; } $updateArray['crumbar_identifier'] = $crumbar_ident_string; $query = $GLOBALS['TYPO3_DB']->UPDATEquery('tx_multishop_products_to_categories', 'products_to_categories_id=\'' . $rec['products_to_categories_id'] . '\'', $updateArray); $res = $GLOBALS['TYPO3_DB']->sql_query($query); } } $level++; /*if ($pid==508) { echo "<pre>"; var_dump($query); echo "<br/>"; }*/ } } //return true; } }
//die(); // finally get the category ids that we must remove if (is_array($catOldIds) && count($catOldIds)) { foreach ($catOldIds as $page_uid => $catOldArray) { $catIdsToRemove = $catOldArray; if (is_array($catIds[$page_uid]) && count($catIds[$page_uid])) { $catIdsToRemove = array_diff($catOldIds[$page_uid], $catIds[$page_uid]); } //print_r($catIdsToRemove); if (is_array($catIdsToRemove) && count($catIdsToRemove)) { foreach ($catIdsToRemove as $catId) { if (strpos($catId, '::rel_') !== false) { list($tmpcatId, ) = explode('::rel_', $catId); $catId = $tmpcatId; } $cats = mslib_fe::globalCrumbarTree($catId); $cats = array_reverse($cats); // $crumbar_ident_string = ''; $crumbar_ident_array = array(); foreach ($cats as $item) { $crumbar_ident_array[] = $item['id']; } $crumbar_ident_string = implode(',', $crumbar_ident_array); // if (!empty($crumbar_ident_string)) { $query = $GLOBALS['TYPO3_DB']->DELETEquery('tx_multishop_products_to_categories', 'products_id=\'' . $prodid . '\' and crumbar_identifier=\'' . $crumbar_ident_string . '\' and page_uid=' . $page_uid); //var_dump($query); $res = $GLOBALS['TYPO3_DB']->sql_query($query); // remove the custom page desc if the cat id is not related anymore in p2c $query = $GLOBALS['TYPO3_DB']->DELETEquery('tx_multishop_products_description', 'products_id=\'' . $prodid . '\' and layered_categories_id=\'' . $catId . '\' and page_uid=' . $page_uid);
public function globalCrumbarTree($c, $languages_id = '', $output = array()) { if (is_numeric($c)) { if ($this->ms['MODULES']['CACHE_FRONT_END']) { if (!isset($this->ms['MODULES']['CACHE_TIME_OUT_CRUM'])) { $this->ms['MODULES']['CACHE_TIME_OUT_CRUM'] = $this->ms['MODULES']['CACHE_TIME_OUT_SEARCH_PAGES']; } if (!count($output) && $this->ms['MODULES']['CACHE_TIME_OUT_CRUM']) { $CACHE_FRONT_END = 1; } else { $CACHE_FRONT_END = 0; } } else { $CACHE_FRONT_END = 0; } if ($CACHE_FRONT_END) { $this->cacheLifeTime = $this->ms['MODULES']['CACHE_TIME_OUT_CRUM']; $options = array('caching' => true, 'cacheDir' => $this->DOCUMENT_ROOT . 'uploads/tx_multishop/tmp/cache/', 'lifeTime' => $this->cacheLifeTime); $Cache_Lite = new Cache_Lite($options); $string = $this->cObj->data['uid'] . '_crum_' . $c . '_' . $languages_id . '_' . md5(serialize($output)); } if ($this->ROOTADMIN_USER || !$CACHE_FRONT_END || $CACHE_FRONT_END && !($content = $Cache_Lite->get($string))) { $sql = $GLOBALS['TYPO3_DB']->SELECTquery('c.status, c.custom_settings, c.categories_id, c.parent_id, c.page_uid, cd.categories_name, cd.meta_title, cd.meta_description', 'tx_multishop_categories c, tx_multishop_categories_description cd', 'c.categories_id = \'' . $c . '\' and cd.language_id=\'' . $this->sys_language_uid . '\' and c.categories_id = cd.categories_id', '', '', ''); $qry = $GLOBALS['TYPO3_DB']->sql_query($sql); if ($GLOBALS['TYPO3_DB']->sql_num_rows($qry)) { $data = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry); if ($data['categories_name']) { $output[] = array('name' => $data['categories_name'], 'url' => mslib_fe::rewritenamein($data['categories_name'], 'cat', $data['categories_id']), 'id' => $data['categories_id'], 'custom_settings' => $data['custom_settings'], 'meta_title' => $data['meta_title'], 'meta_description' => $data['meta_description'], 'status' => $data['status'], 'page_uid' => $data['page_uid']); } if ($data['parent_id'] > 0 && $data['parent_id'] != $this->categoriesStartingPoint) { if ($data['categories_id'] == $data['parent_id']) { echo 'globalCrumbar is looping.'; die; } else { $output = mslib_fe::globalCrumbarTree($data['parent_id'], '', $output); } } $GLOBALS['TYPO3_DB']->sql_free_result($qry); } if ($CACHE_FRONT_END) { $Cache_Lite->save(serialize($output)); } } else { $output = unserialize($content); } } return $output; }