Php 在Magento前端过滤没有图像的产品

Php 在Magento前端过滤没有图像的产品,php,magento,filter,Php,Magento,Filter,我正在尝试过滤Magento前端没有图像的产品,但成功了一半 我添加了以下代码: //$_productCollection=$this->getLoadedProductCollection(); $_productCollection = clone $this->getLoadedProductCollection(); $_productCollection->clear() ->addAttributeToFilter('image', array('n

我正在尝试过滤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是一个新手,似乎对这个人有效,但也许我的情况不同


请帮忙。

我自己解决了!希望有人能从中受益

在app/code/core/Mage/Catalog/Block/Product/list.php中覆盖\u beforeToHtml()[备份文件]

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

资料来源:

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

在app/code/core/Mage/Catalog/Block/Product/list.php中覆盖\u beforeToHtml()[备份文件]

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();
}
资料来源: