关于我们
公司博客
- 2011湖北互联网精英联谊会图片播报
- 我公司出席2011武汉市服务外包行业协会、武汉市软件行业协会联合年会
- 我公司成功为国外客户交付Drupal项目
- 伊锐数码参加“HTML5技术分享沙龙”活动
- 伊锐数码CMMI3认证工作正式启动
- 伊锐数码成为信步东方IT服务提供商
- 公司参加“云计算时代的过程改进及武汉市服务外包政策宣讲会”
- 伊锐数码助力客户走向移动互联网!
- 伊锐数码交付 Facebook 应用程序
- 伊锐数码作为软件外包提供商出席上海世博会活动
- 如何将大型 Magento 站点到 1.4以上版本 (公司英文博客)
- 关于 Zend Server 的一些思考 (公司英文博客)
- 如何整合 Zend Studio 及 SVN (公司英文博客)
- Magento 能支持 Amazon S3 吗?
- 最近解决的一个奇怪的 Joomla! 下图片显示问题
Magento: 如何对产品进行分目录的产品搜索 (摘自公司英文博客)
In "advanced search" feature, searching product by category is not the default setting. But we can do this by modifying the foloowing files:
app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php
app/code/core/Mage/CatalogSearch/Model/Advanced.php
app/design/yourdesign/yourdesign/template/catalogsearch/advanced/form.phtml
At the bottom of app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php we can add following codes:
public function getStoreCategories() { $helper = Mage::helper('catalog/category'); return $helper->getStoreCategories(); }
In app/code/core/Mage/CatalogSearch/Model/Advanced.php, replace the getSearchCriterias() by following functions:
public function getSearchCriterias() { $search = $this->_searchCriterias; /* display category filtering criteria */ if(isset($_GET['category']) && is_numeric($_GET['category'])) { $category = Mage::getModel('catalog/category')->load($_GET['category']); $search[] = array('name'=>'Category','value'=>$category->getName()); } return $search; }
Replace the getProductCollection() by following function:
public function getProductCollection(){
if (is_null($this->_productCollection)) {
$this->_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addMinimalPrice()
->addStoreFilter();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection);
/* include category filtering */
if(isset($_GET['category']) && is_numeric($_GET['category'])) $this->_productCollection->addCategoryFilter(Mage::getModel('catalog/category')->load($_GET['category']),true);
}
return $this->_productCollection;
}
In page app/design/yourdesign/yourdesign/template/catalogsearch/advanced/form.phtml, find the codes as following:
<input name="<?php echo $_code ?>" id="<?php echo $_code ?>" value="<?php echo $this->htmlEscape($this->getAttributeValue($_attribute)) ?>" title="<?php echo $this->htmlEscape($this->getAttributeLabel($_attribute)) ?>" class="input-text <?php echo $this->getAttributeValidationClass($_attribute) ?>" type="text" /> <?php endswitch; ?> </li> <?php endforeach; ?>
at the bottom of this piece of codes, add following codes:
<li>
<label for="category_search_field">Search by Category:</label>
<select name="category" id="category_search_field">
<option value="">-- Any Category --</option>
<?php foreach ($this->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>
</li>






