服务报价 | 域名主机 | 网络营销 | 软件工具| [加入收藏]
 热线电话: #
当前位置: 主页 > php教程 > magento教程 >

如何添加在magento迷你搜索类别搜索

时间:2016-04-08 07:17来源: 作者: 点击:
本教程演示了如何通过在 magento 迷你搜索类别添加搜索。您可能会在 Magento Connect 上搜索的结果,你会发现在 magento 商务,将帮助您搜索您与特定类别的存储区中是没有自由的扩展。但是
本教程演示了如何通过在 magento 迷你搜索类别添加搜索。您可能会在 Magento Connect 上搜索的结果,你会发现在 magento 商务,将帮助您搜索您与特定类别的存储区中是没有自由的扩展。但是你可以做如下所示:
第一次在form.mini.phtml中创建下拉列表中的所有类别
 
 
<select name="category" id="category_search_field">
<option value="">-- Any Category --</option>
<?php foreach ($catalog->getStoreCategories() as $_category): ?>
<?php if($_category->hasChildren()): ?>
<option class="parent-cat" value="<?php echo $_category->getId(); ?>"><?php echo $_category->getName();?></option>
<?php foreach ($_category->getChildren() as $subcategory):
if($subcategory->getIsActive()) : ?>
<option value="<?php echo $subcategory->getId(); ?>"<?php echo ($this->getRequest()->getQuery('category') == $subcategory->getId() ? ' selected="selected"': "") ?>><?php echo $subcategory->getName(); ?></option>
<?php endif; endforeach; ?>
<?php elseif($_category->getIsActive()): ?>
<option value="<?php echo $_category->getId(); ?>"><?php echo $_category->getName();?></option>
<?php endif; ?>
<?php endforeach ?>
</select>
现在转到应用程序/代码/核心/法师/CatalogSearch/助手和打开Data.php并添加以下代码:
 
 
public function getStoreCategories()
{
$helper = Mage::helper('catalog/category');
return $helper->getStoreCategories();
}
public function getSelectedCategory()
{
$catid = (int)addslashes($_REQUEST['category']); 
$cat="";
if($catid>1)
$cat = Mage::getModel('catalog/category')->load($catid); 
return $cat; 
}
现在转到应用程序/代码/核心/法师/CatalogSearch/模型和打开 Layer.php
替换
 
 
public function prepareProductCollection($collection)
{
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addSearchFilter(Mage::helper('catalogsearch')->getQuery()->getQueryText())
->setStore(Mage::app()->getStore())
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addStoreFilter()
->addUrlRewrite();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
return $this;
}
 
 
public function prepareProductCollection($collection)
{
if(Mage::helper('catalogsearch')->getSelectedCategory()!="")
{
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addSearchFilter(Mage::helper('catalogsearch')->getQuery()->getQueryText())
->setStore(Mage::app()->getStore())
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addStoreFilter()
->addCategoryFilter(Mage::helper('catalogsearch')->getSelectedCategory())
->addUrlRewrite();
}
else
{
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addSearchFilter(Mage::helper('catalogsearch')->getQuery()->getQueryText())
->setStore(Mage::app()->getStore())
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addStoreFilter() 
->addUrlRewrite();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
 
return $this;
}
保存并享受。
(责任编辑:最模板)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
栏目列表
热点内容