Magento 按当前客户群的等级价格过滤产品集合
如何通过查看是否已设置当前客户群的等级价格来过滤产品系列?
我想我需要查看catalog_product_entity_tier_price
表,看看是否有集合中每个产品的当前customer_group_id
条目(如果没有,则该产品应该从集合中排除/过滤),但我不知道如何实现这一点。
背景:有些产品不适用于某些客户群,我们使用分级价格来做出决定(即,如果存在分级价格,则包括在收集和显示中,如果没有,则排除并且不显示)。
非常感谢任何帮助
How do I filter a product collection by looking at whether a tier price for the current customer group has been set?
I think I need to look at the catalog_product_entity_tier_price
table to see if there is an entry for the current customer_group_id
for each product in the collection (if there isn't, the product should be excluded / filtered from the collection), but I can't figure out how to make that happen.
Background: Some products are not available to certain customer groups, and we are using tier price to make that determination (i.e. if a tier price exits, include in collection and display, if not, exclude and don't display).
Any help is much appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这应该是可以实现的,但尽量不要从表的角度来考虑它,而是从对象和集合的角度来考虑。
Product 对象有一个方法
getTierPrice
,它使用工厂模式根据产品类型(Simple、Bundle 等)返回层级定价。该方法在计算等级价格时检查当前访问者的组。因此,Tier Price 不是经典 Magento 意义上的属性,这意味着您无法按属性进行过滤,而是可以在集合上使用
walk
函数来计算 Tier Price,然后进行过滤更新值的集合。walk 函数的一个示例可能是:
然后在您的
Namespace_Module_Helper_Data
中,您有类似的内容:或者,您可以通过
foreach
循环运行集合:Yup, this should be achievable, but try not to think about it in terms of tables, but rather as objects and collections.
The Product object has a method
getTierPrice
which uses a Factory pattern to return tier pricing depending on the product type (Simple, Bundle, etc). That method checks the current visitor's group when calculating the tier prices.So, tier price is not an attribute in the classic Magento sense which means that you can't filter by attribute, instead you could use the
walk
function on the collection to calculate the Tier Price, and then filter the collection by the updated values.An example of a walk function might be:
then within your
Namespace_Module_Helper_Data
, you have something like:Alternatively, you could run the collection through a
foreach
loop: