问题描述
我知道 Magento1.9 真的很老了,但有些人仍然坚持使用它......所以,这是我的问题......
我有一个模块,它根据一些 POST 参数创建一个新的产品集合,并将它们呈现在自定义页面上。我现在想要的是向该页面添加分层导航。但是,到目前为止,我的尝试都没有成功...
这是我目前的代码:
<?xml version="1.0"?>
<config>
<modules>
<ID_SearchResults>
<version>0.1.0</version>
</ID_SearchResults>
</modules>
<frontend>
<routers>
<searchresults>
<use>standard</use>
<args>
<module>ID_SearchResults</module>
<frontName>searchresults</frontName>
</args>
</searchresults>
</routers>
<layout>
<updates>
<searchresults>
<file>searchresults.xml</file>
</searchresults>
</updates>
</layout>
</frontend>
<global>
<helpers>
<id_searchresults>
<class>ID_SearchResults_Helper</class>
</id_searchresults>
</helpers>
<models>
<searchresults>
<class>ID_SearchResults_Model</class>
</searchresults>
</models>
<blocks>
<searchresults>
<class>ID_SearchResults_Block</class>
</searchresults>
</blocks>
</global>
</config>
IndexController.PHP
<?PHP
class ID_SearchResults_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$post_params = Mage::app()->getRequest()->getPost();
$this->loadLayout();
$this->getLayout()->getBlock("head")->setTitle( $this->__("Search results for: '%s'",$post_params['search']) );
$breadcrumbs = $this->getLayout()->getBlock("breadcrumbs");
$breadcrumbs->addCrumb("home",array(
"label" => $this->__("Home"),"title" => $this->__("Home"),"link" => Mage::getBaseUrl()
));
$breadcrumbs->addCrumb("titlename",array(
"label" => $this->__("Search results for: '%s'",$post_params['search']),"title" => $this->__("Search results for: '%s'",$post_params['search'])
));
$this->_initLayoutMessages('catalog/session');
$this->_initLayoutMessages('checkout/session');
$this->renderLayout();
}
}
数据.PHP
<?PHP
class ID_SearchResults_Helper_Data extends Mage_Core_Helper_Abstract
{
public function getAvailableOrders()
{
return array(
// attribute name => label to be used
'price' => $this->__('Price')
);
}
public function getProductCollection()
{
$post_params = Mage::app()->getRequest()->getPost();
$product_ids = array_map(
function($item) {
return (int)filter_var($item,FILTER_SANITIZE_NUMBER_INT);
},explode(',',$post_params['sbl_search_data'])
);
$layer = Mage::getSingleton('catalog/layer');
if( $product_ids[0] === 0 ) {
if( !is_null(Mage::registry('product-ids')) ) {
$product_ids = Mage::registry('product-ids');
}
}
$product_ids = array(36896,36892,36886);
if ( count($product_ids) > 0 ) {
if( is_null(Mage::registry('product-ids')) ) {
Mage::register('product-ids',$product_ids);
}
$collection = Mage::getResourceModel('catalog/product_collection');
$attributes = Mage::getSingleton('catalog/config')->getProductAttributes();
$collection->addAttributetoSelect($attributes);
$collection->addAttributetoFilter('status',1);
$collection->addIdFilter($product_ids);
$this->_productCollection = $collection;
$layer->setCollection($this->_productCollection);
} else {
$productCollection = $layer->getProductCollection();
$this->_productCollection = $productCollection;
$layer->setCollection($this->_productCollection);
}
return $this->_productCollection;
}
}
List.PHP
<?PHP
class ID_SearchResults_Block_Product_List extends Mage_Catalog_Block_Product_List
{
protected function _beforetoHtml()
{
$toolbar = $this->getToolbarBlock();
// called prepare sortable parameters
$collection = $this->getProductCollection();
// use sortable parameters
if ($orders = $this->getAvailableOrders()) {
$toolbar->setAvailableOrders($orders);
}
if ($sort = $this->getSortBy()) {
$toolbar->setDefaultOrder($sort);
}
if ($dir = $this->getDefaultDirection()) {
$toolbar->setDefaultDirection($dir);
}
if ($modes = $this->getModes()) {
$toolbar->setModes($modes);
}
// set collection to toolbar and apply sort
$toolbar->setCollection($collection);
$this->setChild('toolbar',$toolbar);
Mage::dispatchEvent('catalog_block_product_list_collection',array(
'collection' => $this->getProductCollection()
));
$this->getProductCollection()->load();
return parent::_beforetoHtml();
}
}
我确信我在这里遗漏了一些明显的东西,但是自从我使用 magento 1.9 以来我已经很久没有看到它了......
任何人都可以引导我走向正确的方向???
谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)