Developer forum

Forum » CMS - Standard features » How to get the product discount from the Product object?

How to get the product discount from the Product object?

Peter Leleulya
Peter Leleulya
Reply

Hi guys,

 

I’m struggeling with a very basic ecom function, the product discount.
The documentation and forum don’t help me much unfortunately …

 

I’m in a bit of a hurry, so I call out to you guys directly …

 

I’ve set a product discount in the DW9.7.5 CMS for a number of products.

When I use the ecom module to show the products the template tags contain the product discount and I can show the before price and the discount price.

 

SO FAR SO GOOD!

 

When the user adds a discount product to the cart I go to a custom page where the user can do all sorts of extra stuff.
There I need to show the before price and discount price too.

I, of cause,  have the product as Dynamicweb.Ecommerce.Products.Product object in code.

 

But I can NOT find the discount via the API !!

 

The product.Discounts = 0

All methods on the product regarding Getting discount return 0.

Almost everything seems to be deprecated or obsolete …

 

When using GetDiscounts via the DiscountService it does find my discount, but I don’t want to work from that, because then I need to implement all the logic behind all the discount params.

 

In the screendump below you can see the methods I call and their input values and their outcome.
Can you please tell me how to get the discount when having a Product object ?

 

screendump.jpg

Replies

 
Nicolai Pedersen
Reply

If you only work with products in your custom code that has been added to the cart, use Common.Context.Cart and find the right orderline for the product. The orderline has the information and there will be one or more related discount lines with the information you want.

 
Soe Moe Tun
Reply

Hi,

i would like to create custom api for add to cart, delete from cart, checkout etc. i would like to know how i can achieve this. DW is new for me. 

thanks.

 
Nicolai Pedersen
Reply

Great question.

You can do that by using the API.

 
Soe Moe Tun
Reply

I use OrderLineService.Save(OrderLine) in webapi controller to add orderline, and it won't trigger orderline added notification on notification subscriber. Could you please advice on that?

 
Nicolai Pedersen
Reply

If you have a webapi controller, you probably made it in your team, and then the implementation is made in such a way that the notification is not fired.

 
Soe Moe Tun
Reply

we used the solution mentioned here 'https://doc.dynamicweb.com/forum/dynamicweb-9-0-upgrade-issues/dynamicweb-9-0-upgrade-issues/using-webapi-with-attribute-routing-in-dw-9' to handle route to webapi controller.
but OrderLineService.Save(OrderLine) in webapi controller does not trigger orderline add notification. 

 

You must be logged in to post in the forum