产品集合工具栏,带有magento自定义模块中的请求参数

时间:2016-08-12 04:39:34

标签: php codeblocks magento-1.9

enter image description here

enter image description here

我有一个名为CARTRIDGE FINDER的过滤器。当我点击按钮,通过选择打印机系列下拉列表查找我的CARTRIDGE时,它会正确,精确地显示带有产品列表工具栏的产品集合。但是,当我按名称或价格或视图排序时,它显示没有与选择匹配的产品。这里我的自定义(制造商)模块的布局文件代码如下:

<manufacturer_index_filter>
  <reference name="root">
        <action method="setTemplate"><template>page/2columns-left.phtml</template></action>
  </reference>
<reference name="content">
       <block type="manufacturer/custom" name="printer_filter" template="manufacturer/brand_filter_result.phtml"/> 
</reference>

模块(制造商)块文件的代码Custom.php如下:`class Bubmania_Manufacturer_Block_Custom extends Mage_Core_Block_Template {public function __construct()     {         parent :: __ construct(); $ printer = $ this-&gt; getRequest() - &gt; getParams(); $ make_a_printer_op_val = $ printer [&#39; make_a_printer&#39;]; $ printer_series = $ printer [&#39 ; printer_series&#39;];         $ printer_model_no = $ printer [&#39; printer_model_no&#39;];

    $collection = Mage::getModel('catalog/product')->getCollection();
    $collection->addAttributeToSelect('*'); 
    $collection->addAttributeToSort('created_at', 'desc');
    $collection->addAttributeToFilter(array(
        array('attribute'=>'manufacturer','eq'=>$make_a_printer_op_val),
        array('attribute'=>'printerseries','eq'=>$printer_series), 
        array('attribute'=>'printermodelnumber','eq'=>$printer_model_no),
    ));
    $collection->addAttributeToFilter('status', 1);$this->setCollection($collection); /* parent::__construct();

    $collection = Mage::getModel('catalog/product')->getCollection();
    $collection->addAttributeToSelect('*')
               ->addFieldToFilter('visibility', array(
                           Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
                           Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
               )); //showing just products visible in catalog or both search and catalog
        $this->setCollection($collection); */}

protected function _prepareLayout(){         父:: _ prepareLayout();

    //$toolbar = $this->getToolbarBlock();
    $toolbar = Mage::getBlockSingleton('catalog/product_list')->getToolbarBlock();

    // called prepare sortable parameters
    $collection = $this->getCollection();

    // use sortable parameters
    if ($orders = $this->getAvailableOrders()) {
        $toolbar->setAvailableOrders($orders);
    }
    if ($sort = $this->getSortBy()) {
        $toolbar->setDefaultOrder($sort);
    }
    if ($dir = $this->getDefaultDirection()) {
        $toolbar->setDefaultDirection($dir);
    }
    $toolbar->setCollection($collection);

    $this->setChild('toolbar', $toolbar);
    $this->getCollection()->load();
    return $this;
}public function getDefaultDirection(){
    return 'asc';
}

public function getAvailableOrders(){         //返回数组(&#39; created_time&#39; =&gt;&#39;创建时间&#39;,&#39; update_time&#39; =&gt;&#39;更新时间&#39;,&#39; ; collection_id&#39; =&gt;&#39; ID&#39;,&#39; name&#39; =&gt;&#39; Name&#39;);         返回数组(&#39;名称&#39; =&gt;&#39;姓名&#39;,&#39;职位&#39; =&gt;&#39;职位&#39;&#39;价格&#39 ; =&GT;&#39;价格&#39);     }     public function getSortBy(){         返回&#39; name&#39 ;;     }     公共函数getToolbarBlock()     {         $ block = $ this-&gt; getLayout() - &gt; createBlock(&#39; manufacturer / toolbar&#39;,microtime());         return $ block;     }     公共函数getMode()     {         return $ this-&gt; getChild(&#39; toolbar&#39;) - &gt; getCurrentMode();     }

public function getToolbarHtml()
{
    return $this->getChildHtml('toolbar');
}}`

但是当它只运行Mage :: getModel(&#39; catalog / product&#39;) - &gt; getCollection()而不是params时,它会成功运行产品集合工具栏。我需要在这个工具栏中设置params。这该怎么做。如果有人知道这一点,请尽快回复我。我google了很多。但是没有具体的结果。 谢谢

1 个答案:

答案 0 :(得分:0)

尝试扩展:

class CollectionFilter extends \Magento\Catalog\Model\Layer\Category\CollectionFilter
{

public function filter(
    $collection,
    \Magento\Catalog\Model\Category $category
) {
if(isset($_GET['your filter']))

/* your magic here*/