有谁知道如何从订单中获得目录和购物车价格规则?
我知道我可以通过该方法从订单商品中获得折扣百分比getDiscountPercent(),但是如何获得应用于整个订单的所有规则?
例如,我有一条规则"客户组X可以获得商店中所有商品20%的折扣".
现在我想确定用户提交订单时实际应用了哪些规则.我需要这个订单导出界面,我必须提供用户获得的所有折扣.
提前致谢!
看看sales_flat_order_item桌子.有一个字段applied_rule_ids,它将为您提供应用于该项目的规则的ID.您还可以在此表中找到应用了多少折扣和百分比.
例
//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>";
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13981 次 |
| 最近记录: |