【问题标题】:Apply coupon code not working in magento应用优惠券代码在 magento 中不起作用
【发布时间】:2015-04-16 14:59:14
【问题描述】:

我正在 Magento 外部编写一个单独的 php 文件来支持我们的本地应用程序。

应用优惠券代码部分不适合我。但同样的优惠券也适用于 Magento(userend) 和 Magento API 调用。

我正在尝试使用 Magento 在 API 中的相同代码。

$quoteId = 10001;
$coupon = 'TESTCOUPON';
$storeId = 2;

$quote = Mage::getModel("sales/quote");
$quote->setStoreId($storeId);
$quote->load($quoteId);

if (!$quote->getItemsCount()) {
        echo ('quote_is_empty');
        exit;
}

$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->setCouponCode($coupon)
        ->collectTotals()
        ->save();

if (!$coupon == $quote->getCouponCode()) {
        echo ('coupon_code_is_not_valid');
        exit;
}
else{
        echo 'coupon applied';
        exit;
}

以上代码通过coupon_code_is_not_valid。 如果有人对此有任何想法,请告诉我。

【问题讨论】:

  • 您想在订购产品时获取优惠券代码吗?
  • 是的,在产品添加到购物车/报价后。
  • 你的代码是正确的,你遇到了什么问题?
  • 当我通过 coupon_code_is_not_valid 运行代码时
  • 在不区分大小写模式下比较字符串

标签: api magento coupon


【解决方案1】:

尝试关注

if (strcasecmp($coupon,$quote->getCouponCode()) == 0 ){
    echo 'coupon applied';
     exit;
}

【讨论】:

  • 我也签入了db,优惠券没有使用。
猜你喜欢
  • 2014-01-20
  • 2016-04-02
  • 2018-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-26
  • 1970-01-01
  • 2012-09-11
相关资源
最近更新 更多