以下のコードは、Magento の標準的なミニ検索フォームを、Amazon や eBay で見られるようなより詳細なミニ検索に変換するEdmond's Ecommerce の好意によるものです。この時点で、ルート ディレクトリのサブカテゴリに到達できますが、代わりに、サブサブカテゴリからアレイを取り出したいと考えています。ルート ディレクトリ > サブカテゴリ > サブサブカテゴリ。
以下を含む getSubCategories の多くの順列を実装しようとしましたが、エラーが発生し続けました。
$category->load(Mage::app()->getStore()->getRootCategoryId()->getSubCategories());
共有されたヒントは何の助けにもなりませんでした。たぶん私はそれを熟読することができません。
if($this->getSubCategories($c)){
foreach($this->getSubCategories($c) as $sc){
foreach($this->getSubCategories($sc) as $ssc){
...
}
}
}
$exclude_array オプションに気付くかもしれません。ミニ検索に関係のないカテゴリを除外するには、サブサブカテゴリの配列が正確でなければなりません。任意の提案をいただければ幸いです。
<?php
$category = Mage::getModel('catalog/category');
if(is_object(Mage::registry('current_category'))){
$current_category_path=Mage::registry('current_category')->getPathIds();
}else{
$current_category_path = array();
}
$category->load(Mage::app()->getStore()->getRootCategoryId());
$children_string = $category->getChildren();
$children = explode(',',$children_string);
$extra_options='';
$exclude_array=array(1,2,3);
foreach($children as $c){
if(in_array($c, $exclude_array)){continue;}
$selected = (in_array($c, $current_category_path))?'SELECTED':'';
$extra_options.= '<option value="' . $c . '" ' . $selected . '>' . $category->load($c)->getName() . '</option>' . "\n";
}
?>
<form id="search_mini_form" action="<?php echo $this->helper('catalogSearch')->getResultUrl() ?>" method="get">
<fieldset>
<legend><?php echo $this->__('Search Site') ?></legend>
<div class="mini-search">
<?php echo $this->__('I am celebrating my') ?>
<select name="cat" id="cat" class="input-text">
<option value="">Any Occassion</option>
<?= $extra_options ?>
</select>
<input id="search" type="text" class="input-text" name="<?php echo $this->helper('catalogSearch')->getQueryParamName() ?>" value="<?php echo $this->helper('catalogSearch')->getEscapedQueryText() ?>" />
<input class="search-box" type="submit" value="Go" alt="<?php echo $this->__('Search') ?>" />
<div id="search_autocomplete" class="search-autocomplete"></div>
<script type="text/javascript">
//<![CDATA[
var searchForm = new Varien.searchForm('search_mini_form', 'search', '<?php echo $this->__('and looking for...') ?>');
searchForm.initAutocomplete('<?php echo $this->helper('catalogSearch')->getSuggestUrl() ?>', 'search_autocomplete');
//]]>
</script>
</div>
</fieldset>
</form>