Magento - 在购物车中获取折扣类型

时间:2015-01-29 18:19:36

标签: magento cart discount

我需要能够在购物车中获得折扣类型。

我可以这样得到折扣金额:

$cart = Mage::getModel('checkout/cart')->getQuote();
$totals =  $cart->getTotals(); 
$discount = $totals["discount"]->getValue();

我如何检查它的折扣类型 - 是百分比还是固定金额?

1 个答案:

答案 0 :(得分:0)

查看applied_rule_idssales_flat_quote

中的sales_flat_quote_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 - get price rules from order