简体   繁体   English

产品收集和过滤器Magento

[英]Product collection and filter Magento

I have a custom attribute called groupId and I have about 1000 products and they all have groups of 4 products sharing the same groupId . 我有一个名为groupId的自定义属性,我有大约1000种产品,它们都有4个产品组,它们共享相同的groupId。

Now I have a category I want to display these products in but I only want to show one of the 4 products from each group. 现在,我有一个类别要显示这些产品,但我只想显示每个组的4个产品之一。

So I thought that I can filter this and match a collection against the products in the category and insert them if there is no match and so on . 因此,我认为我可以对此进行过滤,并针对该类别中的产品匹配一个集合,如果不存在匹配项,则将其插入,依此类推。 But the collection loads all products once so if I loop through the collection it won't notis the product that was inputed during that run . 但是集合一次加载所有产品,所以如果我遍历集合,它不会是那次运行中输入的产品。

Is there some one that has a suggestion to approach this 是否有人建议解决这个问题

您可以使用MySQL的DISTINCT来确保每个组中都有一个产品。

$collection->getSelect()->distinct($groupId);

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

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