在Magento前端过滤没有图像的产品 [英] Filter products without images on Magento frontend

查看:136
本文介绍了在Magento前端过滤没有图像的产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我添加了以下代码:

  // $ _ productCollection = $ this-> getLoadedProductCollection(); 
$ _productCollection = clone $ this-> getLoadedProductCollection();
$ _productCollection-> clear()
- > addAttributeToFilter('image',array('neq'=>'no_selection'))
- > load();



app / design / frontend / default / [my_theme] /template/catalog/product/list.phtml



产品过滤得很好,但是页码和项目数量没有得到更新。

我跟着这个链接:



这似乎是有道理的,该产品没有被过滤在全球范围内,所以网站的一些部分没有正确更新。



我是不知道如何实施他的解决方案,因为我是Magento的新手,似乎它为人工作,但也许我的情况是不同的。



请帮助。 >

解决方案

自己想出来!希望有人能从中受益!


$ b

app / code / core / Mage / Catalog / Block / Product中覆盖 _beforeToHtml() /list.php [BACKUP FILE]

  protected function _beforeToHtml()
{
$ toolbar = $ this-> getToolbarBlock();

//调用准备可排序参数
$ collection = $ this-> _getProductCollection();

//使用可排序参数
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);


//开始
$ collection-> addAttributeToFilter('image',array('neq'=>'no_selection'));
//插入结束

//将集合设置为工具栏并应用排序
$ toolbar-> setCollection($ collection);

$ this-> setChild('toolbar',$ toolbar);
Mage :: dispatchEvent('catalog_block_product_list_collection',array(
'collection'=> $ this-> _getProductCollection()
));

$ this-> _getProductCollection() - > load();

返回parent :: _ beforeToHtml();

来源: http://www.magentocommerce.com/boards/viewthread/73507/

I am trying to filter products without images on Magento frontend but with half success.

I added the following code:

//$_productCollection=$this->getLoadedProductCollection();
$_productCollection = clone $this->getLoadedProductCollection();
$_productCollection->clear()
    ->addAttributeToFilter('image', array('neq' => 'no_selection'))
    ->load();

to:

app/design/frontend/default/[my_theme]/template/catalog/product/list.phtml

The products get filtered nicely but the page number and item count doesn't get updated.

I followed this link:

Magento - list.phtml filtering product collection not giving correct pagination

It seems to make sense, the product isn't getting filtered at a global scale so some parts of the website isn't properly updating.

I am not sure how to implement his solution as I am a newbie in Magento, seems like it worked for the person but maybe my case is different.

Please help.

解决方案

Figured it out myself! Hopefully someone could benefit from this!

Overwrite _beforeToHtml() in app/code/core/Mage/Catalog/Block/Product/list.php [BACKUP FILE]

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);
    }

    // insert start       
    $collection->addAttributeToFilter('image', array('neq' => 'no_selection'));
    // insert end   

    // 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();
}

Sources: http://www.magentocommerce.com/boards/viewthread/73507/

这篇关于在Magento前端过滤没有图像的产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆