[英]Filter products without images on Magento frontend
I am trying to filter products without images on Magento frontend but with half success. 我正在尝试在Magento前端过滤没有图像的产品,但收效不佳。
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 应用程序/设计/前端/默认/ [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 Magento-list.phtml筛选产品集合未提供正确的分页
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. 我不确定如何实施他的解决方案,因为我是Magento的新手,似乎对这个人有用,但也许我的情况有所不同。
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] 在应用程序/代码/核心/法师/目录/块/产品 /list.php中覆盖_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();
}
Sources: http://www.magentocommerce.com/boards/viewthread/73507/ 资料来源: http : //www.magentocommerce.com/boards/viewthread/73507/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.