Magento - get price rules from order(Magento - 从订单中获取价格规则)
问题描述
有谁知道如何从订单中获取目录和购物车价格规则?
does anyone know how one can get the catalog- and cart price rules from an order?
我知道我可以通过 getDiscountPercent()
方法获取订单商品的折扣百分比,但是我如何获取应用于整个订单的所有规则?
I know that I can get the discount percentage from an order item via the method getDiscountPercent()
, but how can I get all the rules that were applied to the whole order?
例如,我有一个规则客户组 X 可享受商店中所有商品 20% 的折扣".
For example, I have a rule "Customer Group X gets 20% off all items in the store".
现在我想确定在用户提交订单时实际应用了哪些规则.我需要这个用于订单导出界面,我必须在其中提供用户获得的所有折扣.
Now I want to determine which rules were actually applied when the order has been submitted by the user. I need this for an order export interface where I have to supply all discounts that the user got.
提前致谢!
推荐答案
查看 sales_flat_order_item
表.有一个名为 applied_rule_ids
的字段,它将为您提供应用于该项目的规则的 ID.您还可以在此表中找到应用了多少折扣和百分比.
Have a look in the sales_flat_order_item
table. there is a field called applied_rule_ids
which will give you the id of the rule applied to that item. Also you can find out in this table how much discount was applied and the percentage.
例子
//The order I want to check
$order_id = 859;
//Get the list of items for your order
$items = Mage::getModel('sales/order_item')
->getCollection()
->addFilter('order_id',array('eq'=>$order_id));
//loop through each item
foreach($items as $item){
//if the item has not had a rule applied to it skip it
if($item->getAppliedRuleIds() == '')continue;
/*
* I cant remember in the database they might be comma separated or space if multiple rules were applied
* the getAppliedRuleIds() function is the one you want
*/
foreach(explode(",",$item->getAppliedRuleIds()) as $ruleID){
//Load the rule object
$rule = Mage::getModel('catalogrule/rule')->load($ruleID);
// Throw out some information like the rule name what product it was applied to
echo "<p>".$item->getSku()." had rule ".$rule->getName()."(".$item->getAppliedRuleIds().") applied </p>";
}
}
这篇关于Magento - 从订单中获取价格规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Magento - 从订单中获取价格规则
基础教程推荐
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01