简体   繁体   English

Magento按分级价格为当前客户群筛选产品集合

[英]Magento filter product collection by tier price for current customer group

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. 我认为我需要查看catalog_product_entity_tier_price表,以查看集合中每个产品的current customer_group_id是否存在条目(如果没有,则应从集合中排除/过滤该产品),但我可以弄清楚如何做到这一点。

Background: Some products are not available to certain customer groups, and we are using tier price to make that determination (ie if a tier price exits, include in collection and display, if not, exclude and don't display). 背景:某些客户群无法使用某些产品,我们正在使用等级价格进行确定(即,是否存在等级价格,是否包含在集合和显示中,如果没有,则排除并不显示)。

Any help is much appreciated 任何帮助深表感谢

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). Product对象具有getTierPrice方法,该方法使用Factory模式来根据产品类型(简单,捆绑销售等)返回层级定价。 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. 因此,层价格不是经典的Magento的属性,这意味着您不能按属性进​​行过滤,而是可以使用集合上的walk函数计算层价格,然后按更新后的值过滤集合。

An example of a walk function might be: 步行功能的示例可能是:

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->walk('Namespace_Module_Helper_Data::removeStockData',array());

then within your Namespace_Module_Helper_Data , you have something like: 然后在您的Namespace_Module_Helper_Data ,您将得到以下内容:

public static function removeStockData($product = null)
{
    $product->setData('stock_item',null);
    return;
}

Alternatively, you could run the collection through a foreach loop: 或者,您可以通过foreach循环运行集合:

foreach($collection->getItems() as $key => $item){
   if($item->getTierPrice($qty) == $item->getPrice()){  //insert your own criteria
        $collection->removeItemByKey($key);
   }
}

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

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