Magento 按当前客户群的等级价格过滤产品集合

发布于 2024-10-15 02:38:36 字数 277 浏览 1 评论 0原文

如何通过查看是否已设置当前客户群的等级价格来过滤产品系列?

我想我需要查看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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

—━☆沉默づ 2024-10-22 02:38:36

是的,这应该是可以实现的,但尽量不要从表的角度来考虑它,而是从对象和集合的角度来考虑。

Product 对象有一个方法 getTierPrice,它使用工厂模式根据产品类型(Simple、Bundle 等)返回层级定价。该方法在计算等级价格时检查当前访问者的组。

因此,Tier Price 不是经典 Magento 意义上的属性,这意味着您无法按属性进行过滤,而是可以在集合上使用 walk 函数来计算 Tier Price,然后进行过滤更新值的集合。

walk 函数的一个示例可能是:

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

然后在您的 Namespace_Module_Helper_Data 中,您有类似的内容:

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

或者,您可以通过 foreach 循环运行集合:

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

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:

$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:

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

Alternatively, you could run the collection through a foreach loop:

foreach($collection->getItems() as $key => $item){
   if($item->getTierPrice($qty) == $item->getPrice()){  //insert your own criteria
        $collection->removeItemByKey($key);
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文