Question

I'm trying to make a php files, to apply coupon code to shipping cart. I explain. We have a mobile-commerce application, and wanna add coupon code. Creating them on magento, adding rules, date, products, there is no problem here, but when customer have choose products, they enter the coupon code in a text field. My php files take the code they enter, and the shopping card Id (if there is one ? ) with a GET method, check if the coupon can be apply (rules, date, products, obviously ask magento "Can he does it ?"), and if magento says "yes", return the final price, or reduction (return like '5%' or '543$'), or return "error" if the coupon is not validate.

I try to look some code here : http://inchoo.net/ecommerce/magento/programming-magento/programmatically-create-apply-and-delete-shopping-cart-price-rule-in-magento/ also look at the magento's documentation, but not abble to finally find what I wanna do.

I don't really know where to start, every helps are welcome =)

EDIT: I'm actually here :

$couponCode = $_GET['couponCode'];
$shoppingCartId = $_GET['shoppingCartId'];

$result = $proxy->call($session, "cart_coupon.add", array($shoppingCartId, $couponCode));

but I don't know what to do with my result, (what can I return).

Was it helpful?

Solution

What this will do is simply add the coupon to the cart. You will then need to make a further call to the api to get the cart totals.

It is all documented at http://www.magentocommerce.com/api/soap/checkout/cart/cart.totals.html and a call like the following:

$client = new SoapClient('http://magentohost/api/soap/?wsdl');

// If somestuff requires api authentification,
// then get a session token
$session = $client->login('apiUser', 'apiKey');

$result = $client->call($session, 'cart.totals', '15');
var_dump ($result);

Should give you an array of all the totals which will include the discounts.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top