我在Magento中让寻呼机按我想要的方式工作时遇到了一些麻烦。
问题是:
我正在获得一个产品集合,其中我仅使用图像过滤产品。
但是分页仍然显示未应用过滤的产品总数,我该如何解决这个问题?
例: 我有 38 个产品,其中只有 23 个有关联的图像,如果我定义按页面显示 9 个产品,它应该显示 1|2|3。但它仍然显示 1|2|3|4|5。
提前感谢,波纹管是我用来过滤产品的一段代码。
$_productCollection = clone $this->getLoadedProductCollection()
->clear()
->addAttributeToFilter('small_image', array('neq' => 'no_selection'))
->load();
也许你需要包括addAttributeToSelect:
$_productCollection = clone $this->getLoadedProductCollection()
->clear()
->addAttributeToSelect('*')
->addAttributeToFilter('image', array('neq' => 'no_selection'));
编辑 1
好的,您需要进入文件app/code/core/Mage/Catalog/Model/Category.php
并尝试从以下位置编辑方法getProductCollection()
:
public function getProductCollection()
{
$collection = Mage::getResourceModel('catalog/product_collection')
->setStoreId($this->getStoreId())
->addCategoryFilter($this);
return $collection;
}
到:
public function getProductCollection()
{
$collection = Mage::getResourceModel('catalog/product_collection')
->setStoreId($this->getStoreId())
->addAttributeToFilter('small_image', array('neq' => 'no_selection'))
->addCategoryFilter($this);
return $collection;
}
当然,您不应该直接编辑它,然后在您的本地池中覆盖它。比你的代码与克隆可以删除。