public function doAction($arrParam) { $arrRequest = $this->doInitParam($arrParam); if (!$this->isParamError()) { $category_id = $arrRequest['BrowseNodeId']; if ($category_id && !Application::alias('eccube.helper.db')->isRecord('dtb_category', 'category_id', (array) $category_id, 'del_flg = 0')) { $category_id = '0'; } elseif (Utils::isBlank($category_id)) { $category_id = '0'; } // LC_Page_Products_CategoryList::lfGetCategories() と相当類似しているので共通化したい $arrCategory = null; // 選択されたカテゴリ $arrChildren = array(); // 子カテゴリ $arrAll = Application::alias('eccube.helper.db')->getCatTree($category_id, true); foreach ($arrAll as $category) { if ($category_id != 0 && $category['category_id'] == $category_id) { $arrCategory = $category; continue; } if ($category['parent_category_id'] != $category_id) { continue; } $arrGrandchildrenID = Utils::sfGetUnderChildrenArray($arrAll, 'parent_category_id', 'category_id', $category['category_id']); $category['has_children'] = count($arrGrandchildrenID) > 0; $arrChildren[] = $category; } if (!Utils::isBlank($arrCategory)) { $arrData = array('BrowseNodeId' => $category_id, 'Name' => $arrCategory['category_name'], 'PageURL' => HTTP_URL . 'products/list.php?category_id=' . $arr['category_id'], 'has_children' => count($arrChildren) > 0); } else { $arrData = array('BrowseNodeId' => $category_id, 'Name' => 'ホーム', 'PageURL' => HTTP_URL, 'has_children' => count($arrChildren) > 0); } if (!Utils::isBlank($arrChildren)) { $arrData['Children'] = array(); foreach ($arrChildren as $category) { $arrData['Children']['BrowseNode'][] = array('BrowseNodeId' => $category['category_id'], 'Name' => $category['category_name'], 'PageURL' => HTTP_URL . 'products/list.php?category_id=' . $category['category_id'], 'has_children' => $category['has_children']); } } $this->setResponse('BrowseNode', $arrData); // TODO: Ancestors 親ノード return true; } return false; }
/** * 選択されたカテゴリとその子カテゴリの情報を取得し、 * ページオブジェクトに格納する。 * * @param string $category_id カテゴリID * @param boolean $count_check 有効な商品がないカテゴリを除くかどうか * @return void */ public function lfGetCategories($category_id, $count_check = false) { $arrCategory = null; // 選択されたカテゴリ $arrChildren = array(); // 子カテゴリ $arrAll = Application::alias('eccube.helper.db')->getCatTree($category_id, $count_check); foreach ($arrAll as $category) { // 選択されたカテゴリの場合 if ($category['category_id'] == $category_id) { $arrCategory = $category; continue; } // 関係のないカテゴリはスキップする。 if ($category['parent_category_id'] != $category_id) { continue; } // 子カテゴリの場合は、孫カテゴリが存在するかどうかを調べる。 $arrGrandchildrenID = Utils::sfGetUnderChildrenArray($arrAll, 'parent_category_id', 'category_id', $category['category_id']); $category['has_children'] = count($arrGrandchildrenID) > 0; $arrChildren[] = $category; } if (!isset($arrCategory)) { Utils::sfDispSiteError(CATEGORY_NOT_FOUND); } // 子カテゴリの商品数を合計する。 $children_product_count = 0; foreach ($arrChildren as $category) { $children_product_count += $category['product_count']; } // 選択されたカテゴリに直属の商品がある場合は、子カテゴリの先頭に追加する。 if ($arrCategory['product_count'] > $children_product_count) { $arrCategory['product_count'] -= $children_product_count; // 子カテゴリの商品数を除く。 $arrCategory['has_children'] = false; // 商品一覧ページに遷移させるため。 array_unshift($arrChildren, $arrCategory); } return array('arrChildren' => $arrChildren, 'arrCategory' => $arrCategory); }
/** * メインカテゴリの取得. * * @param boolean $count_check 登録商品数をチェックする場合はtrue * @return array $arrMainCat メインカテゴリの配列を返す */ public function lfGetMainCat($count_check = false) { $objQuery = Application::alias('eccube.query'); $col = '*'; $from = 'dtb_category left join dtb_category_total_count ON dtb_category.category_id = dtb_category_total_count.category_id'; // メインカテゴリとその直下のカテゴリを取得する。 $where = 'level <= 2 AND del_flg = 0'; // 登録商品数のチェック if ($count_check) { $where .= ' AND product_count > 0'; } $objQuery->setOption('ORDER BY rank DESC'); $arrRet = $objQuery->select($col, $from, $where); // メインカテゴリを抽出する。 $arrMainCat = array(); foreach ($arrRet as $cat) { if ($cat['level'] != 1) { continue; } // 子カテゴリを持つかどうかを調べる。 $arrChildrenID = Utils::sfGetUnderChildrenArray($arrRet, 'parent_category_id', 'category_id', $cat['category_id']); $cat['has_children'] = count($arrChildrenID) > 0; $arrMainCat[] = $cat; } return $arrMainCat; }