简体   繁体   English

Magento产品列表,带有自定义productCollection

[英]Magento product list with custom productCollection

For my module I need to create a custom productCollection built with various addAttributeToFilter modifiers. 对于我的模块,我需要创建一个使用各种addAttributeToFilter修饰符构建的自定义productCollection。 However, I have no idea how to get such a collection into a product list like the default magento one. 但是,我不知道如何将这样的集合放入像默认的magento那样的产品列表中。 So basicly I'd like to create a pre-filtered product list, could anyone give me some advice on how to start such a thing? 所以基本上我想创建一个预过滤的产品列表,任何人都可以给我一些关于如何开始这样的事情的建议吗?

EDIT: Just to clarify, I can make the collection, just not show it like the default product list. 编辑:只是为了澄清,我可以制作集合,只是不显示它像默认产品列表。

After hours of struggling I found a solution: I overrided Mage_Catalog_Block_Product_List and made my own _getProductCollection with: 经过几个小时的挣扎,我找到了一个解决方案:我重写了Mage_Catalog_Block_Product_List并创建了我自己的_getProductCollection:

$collection = parent::_getProductCollection();
$collection->addAttributeToFilter('attribute', array('operator' => 'value'));
/* more filters go here */
$this->_productCollection = $collection;
return $this->_productCollection;

This seemed to be the only way to get the original product list working without any errors or category problems. 这似乎是使原始产品列表正常运行而没有任何错误或类别问题的唯一方法。

With thanks to Guerra!! 感谢Guerra !!

use this in list.phtml: 在list.phtml中使用它:

$_productCollection->clear()
        ->addAttributeToFilter('attribute_set_id', array('eq' => 63))
        ->load();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM