我有一个网站,出售汽车零部件。我已经将我的类别设置为Make - > Model - > Year,从这里过滤由属性完成。刹车,车轮,发动机等...Magento合并2分类成1集合
这将按照我的预期过滤集合,但是一旦我到了年份,我还想包含来自Universal Category的项目。 I.E.该集合应包括特定车辆的物品,以及所有车辆的“通用”物品。
我发现这个Magento: how to merge two product collections into one?这似乎是我想要的,但我似乎无法弄清楚究竟应该在哪里实施。
List.php,Layer.php和Category.php中有getCollection()方法,我试图在上面的链接中实现代码,但没有成功。如果我将它包含在List.php中,集合似乎被合并,但属性过滤不适用于Universal产品。
我已经试过编辑像这样在Category.php的getProductCollection功能:
public function getProductCollection()
{
$collection = Mage::getResourceModel('catalog/product_collection')
->setStoreId($this->getStoreId())
->addCategoryFilter($this);
//return $collection;
$universalCollection = Mage::getModel('catalog/category')->load(18)->getProductCollection();
$merged_ids = array_merge($collection->getAllIds(), $universalCollection->getAllIds());
// can sometimes use "getLoadedIds()" as well
$merged_collection = Mage::getResourceModel('catalog/product_collection')
->addFieldToFilter('entity_id', $merged_ids)
->addAttributeToSelect('*');
return $merged_collection;
}
但是这给了我:“致命错误:达到‘200’最大功能嵌套层次,中止”
如果有人可以给任何建议,将不胜感激。
感谢德鲁,我知道我不应该修改的核心文件。计划是让它以某种形式工作,然后再做好。是否会发生是另一回事......大声笑... 感谢您的帮助,我确信我可以从中找出答案。 –
嗨德鲁,当我使用这段代码时,我的属性过滤器似乎不工作。我得到了一大堆没有名字的项目,成本为0.00,缺货,然后是与过滤器相关的项目。有任何想法吗? –
@JohnCondron - 尝试在合并后的集合上使用addAttributeToSelect和所需的属性,或*对所有即addAttributeToSelect(array('price','name'))或addAttributeToSelect('*')等 –