Sunday 8 November 2015

Uncaught SoapFault exception: [1083] Coupon is not valid Magento


Uncaught SoapFault exception: [1083] Coupon is not valid Magento

Every people faced this error that "Coupon is not valid" in magento. After debugging 2-3 hour on API, I have solved this error at my-end. Check below code which i have used in Coupon 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
?>

That's it.. Enjoy Chandresh Rana Coding..

No comments: