Developer forum

Forum » Development » How to apply voucher code via API

How to apply voucher code via API

Zayar Minn Dynamicweb Employee
Zayar Minn
Reply

I am developing API to use from mobile application. I am facing a problem, when applying voucher code with API POST method, is not working. Could you please suggest me?
 
1.       Applying voucher code from url is not working.
http://[myDomain]/[pageName]?EcomOrderVoucherCode=[voucherCode]
 
2.       Applying voucher code by creating dll is not working.
Order dwOrder = Order.GetOrderByID([cartId/orderId]);
dwOrder.VoucherCode = [voucherCode];
dwOrder.Save();
 
Best Regards


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Zayar

You have to post to a page with the cart module on before it works - I think that might be it

In you API things you query the order from the database directly - if you need to change things on the cart, you have to get the cart from context: https://doc.dynamicweb.com/api/html/31a6a639-16e1-080e-9d9f-d5db9fcae344.htm

To work with voucher codes in the API: https://doc.dynamicweb.com/api/html/19274ddd-dfd4-ea82-964a-a1de6d0653af.htm

After adding a voucher code, you have to make sure the cart gets calculated:

Call .ClearCachedPrices(), .ForcePriceRecalculation() and .CalculateDiscounts(); on the order.

BR Nicolai

Votes for this answer: 1

 

You must be logged in to post in the forum