0
幫助我有下面的代碼禮貌Edmond's Ecommerce是Magento的標準mini-搜索表單轉換爲像亞馬遜和eBay看到的那些更詳細的迷你搜索。在這個時候,我能夠到達根目錄的子類別,但是我想從子子類別中取出數組。根目錄>子類別>子子類別。需要與Magento的迷你搜索
試圖執行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>