当我执行以下操作时,我对优惠券API有问题:
$couponCode = "test";
$resultCartCoupon = $proxy->call($sessionId, "cart_coupon.add", array($shoppingCartId, $couponCode));我总是得到:未捕获SoapFault异常: 1083优惠券无效,如果我在前端尝试优惠券代码,没有问题。有没有人曾经成功地使用过这个API部件?
谢谢。
发布于 2015-01-30 08:04:44
此错误来自Mage_Checkout_Model_Cart_Coupon_Api::_applyCoupon()
if ($couponCode) {
if (!$couponCode == $quote->getCouponCode()) {
$this->_fault('coupon_code_is_not_valid');
}
}这看起来可能是个bug,实际上应该是if ($couponCode != $quote->getCouponCode()) {,但我不确定。
可能是您尝试应用优惠券的购物车(报价)无效,即没有获得优惠券所需的合格物品。您确定$shoppingCartId与Magento的sales_flat_quote表中的预期报价正确匹配吗?
发布于 2015-02-02 05:35:30
我注意到错误在下面的摘录中:
try {
$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->setCouponCode(strlen($couponCode) ? $couponCode : '')
->collectTotals()
->save();
} catch (Exception $e) {
$this->_fault("cannot_apply_coupon_code", $e->getMessage());
} 在此特定行:->collectTotals()通过删除此拉伸,没有的错误,但不适用的优惠券。
发布于 2016-03-08 16:53:09
在API上调试了2-3个小时后,我已经在我的终端解决了这个错误。检查下面的代码,我已经在优惠券API使用。
<?php
$mage_url = 'http://yoursiteurl/api/soap?wsdl';
$mage_user= "API_User"; //webservice user login
$mage_api_key = "API_PASSWORD"; //webservice user pass
$client = new SoapClient($mage_url);
$couponCode = 'couponCode'; // a coupon to be apply
$shoppingCartId = '35'; // a cart Id which i have put test id
$sessionId = $client->login($mage_user, $mage_api_key);
$result = $client->call($sessionId,'cart_coupon.add',array($shoppingCartId,$couponCode));
print_r($result);
?>
The above code gives error that "Uncaught SoapFault exception: [1083] Coupon is not valid". When i debugg the core code i came to know that magento cart.create API insert wrong store id in sales_flat_quote table. I have changed the store id value in sales_flat_quote table manually and again run the Coupon API and after that it works perfectly. So here is the my solution. When you create cart id just run the below update query to change the store id.
<?php
$shoppingCartId = $soap->call( $sessionId, 'cart.create');
$mageFilename = '../app/Mage.php';
require_once $mageFilename;
umask(0);
Mage::app();
$db_write1 = Mage::getSingleton('core/resource')->getConnection('core_write');
$updateQue = "update sales_flat_quote set store_id='1' where entity_id ='".$shoppingCartId."'";
$db_write1->query($updateQue);
// Now run the Coupon API here
?>代码摘自此处:http://chandreshrana.blogspot.in/2015/11/uncaught-soapfault-exception-1083.html
https://stackoverflow.com/questions/28225474
复制相似问题