Developer forum

Forum » Development » Voucher Code applied but not effect on price

Voucher Code applied but not effect on price

Zayar Minn Dynamicweb Employee
Zayar Minn
Reply

Hi All,

I am implementing Dynamicweb API for mobile. I set the voucher code in order and save the order.
myOrder.VoucherCode = voucherCode;
orderService.Save(myOrder);
The voucher code is applied in order but the price doesn't effect.

One time set the voucher code from website, then I try to set/remove voucher code from API call on that order. It is reflecting on price.

In my retrieving order obj codes, I add below function
orderService.RemoveOrderCache(orderId);
orderService.ClearCachedPrices(myOrder);
orderService.CalculateDiscounts(myOrder);
orderService.ForcePriceRecalculation(myOrder);

My question is; is there any flag or service to calculate the price with voucher code?

Regards,
Zayar Minn


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Zayar

Check these properties out - they will affect the discount calculation

order.Calculate 
order.RecalculateDiscountsNeeded 
order.DisableDiscountCalculation

see if that works - otherwise we need more of your code.

Votes for this answer: 1
 
Zayar Minn Dynamicweb Employee
Zayar Minn
Reply

Dear Nicolai,

Thank for your response. Here is codes for Applying Voucher.

"Apply Voucher API.txt" is the integration codes.
"ApplyVoucher(Apac.Api.Models.ApplyVoucherRequest applyVoucherRequest)" function call to "ApplyVoucher_PageControl(Apac.Api.Models.ApplyVoucherRequest applyVoucherRequest)".
"ApplyVoucher_PageControl(Apac.Api.Models.ApplyVoucherRequest applyVoucherRequest)" function call to "/api/set-voucher-to-order" page.

"TWG_Set_Voucher_to_Order_API.cshtml" is the page template for "/api/set-voucher-to-order" page.

"TWG_Get_OrderObj_API.cshtml" is the page template to retrieve order information.

This is deployed in "twgapi.dynamicwebapac.com".

I am looking forward your reply with many thanks.

Regards,
Zayar Minn

 
Nicolai Pedersen
Reply

Hi Zayar

It seems like you already have a page with the cart app attached that return the cart content as json. Instead of creating a webapi controller or the thing you do in voucher_to_order templater, simply make a post to the cart page with EcomOrderVoucherCode=XYZ in the post body on the page where you have TWG_Get_OrderObj_API.cshtml - then the cart app will apply the voucher and your code will already return the new cart price with your existing template code in TWG_Get_OrderObj_API.cshtml. 

BR Nicolai

 
Zayar Minn Dynamicweb Employee
Zayar Minn
Reply

Dear Nicolai,
I directly try to post the Shopping Cart module attached page from rest client;
URL: https://twgapi.dynamicwebapac.com//Default.aspx?ID=15?orderid=CART4394
Body:{
  "EcomOrderVoucherCode":"NEXT10"
}
But does not reflected. And also direct url parameter.
 

Regards,
Zayar Minn

 
Nicolai Pedersen
Reply

You cannot post to a URL with 2 ?'s

You do not send a post like this:

Body:{
  "EcomOrderVoucherCode":"NEXT10"
}

That is your own json format, and the server does not understand that.

Checkout here how to do that:

https://plainjs.com/javascript/ajax/send-ajax-get-and-post-requests-47/

 

You must be logged in to post in the forum