php - Magento - 从订单中获取价格规则

标签 php magento

有谁知道如何从订单中获取目录和购物车价格规则?

我知道我可以通过 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>";
        }

    }

关于php - Magento - 从订单中获取价格规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7649695/

相关文章:

php - 使用 PHP/Ajax 在 Jquery Lightbox 中获取结果

php - 'field declared dynamically' 在这种情况下意味着什么?

从 http 切换到 https 时 Magento session 丢失

php - Magento 中的 Paypal 错误 #10602

Magento:将产品添加到购物车后重定向到特定类别

php - 如何在 Apache 中使用 PHP 脚本进行访问控制

php - 类中的多个准备好的语句,出现错误 : Call to undefined function prepare()

php - 在 PHP 5.3 中创建单例基类

magento - 如何从 Magento 订单模型中获得没有运费的总计?

Magento 安装卡在 Magento_Catalog 上