/** * カテゴリツリーの取得. * * @param array $arrParentCategoryId 親カテゴリの配列 * @param boolean $count_check 登録商品数をチェックする場合はtrue * @return array $arrRet カテゴリーツリーの配列を返す */ function lfGetCatTree($arrParentCategoryId, $count_check = false) { $objQuery = new SC_Query_Ex(); $objDb = new SC_Helper_DB_Ex(); $col = '*'; $from = 'dtb_category left join dtb_category_total_count on dtb_category.category_id = dtb_category_total_count.category_id'; // 登録商品数のチェック if ($count_check) { $where = 'del_flg = 0 AND product_count > 0'; } else { $where = 'del_flg = 0'; } $objQuery->setOption('ORDER BY rank DESC'); $arrRet = $objQuery->select($col, $from, $where); foreach ($arrParentCategoryId as $category_id) { $arrParentID = $objDb->sfGetParents('dtb_category', 'parent_category_id', 'category_id', $category_id); $arrBrothersID = SC_Utils_Ex::sfGetBrothersArray($arrRet, 'parent_category_id', 'category_id', $arrParentID); $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrRet, 'parent_category_id', 'category_id', $category_id); $this->root_parent_id[] = $arrParentID[0]; $arrDispID = array_merge($arrBrothersID, $arrChildrenID); foreach ($arrRet as $key => $array) { foreach ($arrDispID as $val) { if ($array['category_id'] == $val) { $arrRet[$key]['display'] = 1; break; } } } } return $arrRet; }
/** * カテゴリツリーの取得を複数カテゴリで行う. * * @param integer $product_id 商品ID * @param bool $count_check 登録商品数のチェックを行う場合 true * @return array カテゴリツリーの配列 */ public static function sfGetMultiCatTree($product_id, $count_check = false) { $objQuery =& SC_Query_Ex::getSingletonInstance(); $col = ''; $col .= ' cat.category_id,'; $col .= ' cat.category_name,'; $col .= ' cat.parent_category_id,'; $col .= ' cat.level,'; $col .= ' cat.rank,'; $col .= ' cat.creator_id,'; $col .= ' cat.create_date,'; $col .= ' cat.update_date,'; $col .= ' cat.del_flg, '; $col .= ' ttl.product_count'; $from = 'dtb_category as cat left join dtb_category_total_count as ttl on ttl.category_id = cat.category_id'; // 登録商品数のチェック if ($count_check) { $where = 'del_flg = 0 AND product_count > 0'; } else { $where = 'del_flg = 0'; } $objQuery->setOption('ORDER BY rank DESC'); $arrRet = $objQuery->select($col, $from, $where); $arrCategory_id = SC_Helper_DB_Ex::sfGetCategoryId($product_id); $arrCatTree = array(); foreach ($arrCategory_id as $pkey => $parent_category_id) { $arrParentID = SC_Helper_DB_Ex::sfGetParents('dtb_category', 'parent_category_id', 'category_id', $parent_category_id); foreach ($arrParentID as $pid) { foreach ($arrRet as $key => $array) { if ($array['category_id'] == $pid) { $arrCatTree[$pkey][] = $arrRet[$key]; break; } } } } return $arrCatTree; }
function getBreadcrumbByCategoryId($category_id) { $arrBreadcrumb = array(); // 正当性チェック if (!SC_Utils_Ex::sfIsInt($category_id) || SC_Utils_Ex::sfIsZeroFilling($category_id) || !SC_Helper_DB_Ex::sfIsRecord('dtb_category', 'category_id', (array) $category_id, 'del_flg = 0')) { $this->current_name = '全商品'; return array(); } // 指定されたカテゴリIDを元に正しいカテゴリIDを取得する。 $arrCategory_id = SC_Helper_DB_Ex::sfGetCategoryId('', $category_id); if (empty($arrCategory_id)) { $this->current_name = '全商品'; return array(); } // 商品が属するカテゴリIDを縦に取得 $objDb = new SC_Helper_DB_Ex(); $arrCatID = $objDb->sfGetParents("dtb_category", "parent_category_id", "category_id", $arrCategory_id[0]); $objQuery = new SC_Query(); $index_no = 0; foreach ($arrCatID as $val) { // カテゴリー名称を取得 $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?"; $arrVal = array($val); $CatName = $objQuery->getOne($sql, $arrVal); if ($val != $category_id) { $arrBreadcrumb[$index_no]['category_name'] = $CatName; $arrBreadcrumb[$index_no]['category_id'] = $val; } else { $this->current_name = $CatName; } $index_no++; } return $arrBreadcrumb; }