Magento:setCouponCode似乎没有在报价模型上应用优惠券 [英] Magento: setCouponCode does not seem to apply coupon on quote model

查看:48
本文介绍了Magento:setCouponCode似乎没有在报价模型上应用优惠券的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们主要将Magento用于交易,并且已经完全通过自定义应用程序重写了前端.我在报价对象上应用优惠券代码(购物车价格规则)时遇到麻烦.优惠券代码似乎被拒绝-setCouponCode不返回任何错误,但是getCouponCode返回空字符串.

we are using Magento mainly for transactions and have rewritten the frontend entirely through a custom application. I am having trouble applying a coupon code (shopping cart price rule) on a quote object. The coupon code seems to be rejected - setCouponCode does not return any error, but getCouponCode returns empty string.

我已经通过管理员后端进行交易,从而验证了优惠券代码是否有效.这是下面的代码片段.

I have verified that the coupon code is valid by making a transacting through the admin backend. Here is the code snippet below.

有人可以帮助我让报价模型对象接受并应用优惠券代码吗?

Can someone help me with getting the quote model object to accept and apply a coupon code?

function add_coupon($ shoppingCartId,$ couponcode){

function add_coupon($shoppingCartId, $couponcode) {

    try {
            $quoteObj = Mage::getModel('sales/quote')->load($shoppingCartId);
            $quoteObj->getShippingAddress()->setCollectShippingRates(true);
            $quoteObj->getShippingAddress()->setCouponCode($coupon)
                    ->setTotalsCollectedFlag(true)
                    ->collectTotals()
                    ->save();
    } catch (Exception $e) {
            return array("status"=>"failed", "message"=>"Error applying coupon.");
    }
    if ($coupon) {
            if (!$coupon == $quoteObj->getCouponCode()) {
                    return array("status"=>"failed", "message"=>"Coupon code is not valid.");
            }
    }
    return array("status"=>"success");

}

推荐答案

我遇到了同样的问题,发现在将任何项目添加到报价中之前,我需要调用setCouponCode().

I ran into the same issue, and discovered that I needed to call setCouponCode() before adding any items to my quote.

在您的情况下,看起来像这样:

In your case, that would look like:

$quoteObj = Mage::getModel('sales/quote')->setCouponCode($coupon)->load($shoppingCartId);

这篇关于Magento:setCouponCode似乎没有在报价模型上应用优惠券的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆