Developer forum

Forum » Development » Get Discount information programatically

Get Discount information programatically

Marco Santos
Reply

Hello.

 

Is there a discount object that contains the information about it, and that I can get to it from a DiscountId (from an order line)? Can´t find any way to do it throught the Discount object in Dynamicweb.eCommerce.Discounts.

 

How about getting the discounts applied to an order? Can I get those programatically? Can´t find the info on the order object, even though I am creating the discount order line (and it is being created, since it shows up on the client pages).

 

Marco


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Marco,

 

I believe the object you're looking for is the SalesDiscount (Dynamicweb.eCommerce.Orders.SalesDiscounts.SalesDiscount). To get the object with the information of the discount with the given ID, new up an instance of this class and pass the ID and the Language to the constructor.

 

Something like this

 

var discountID = orderline.DiscountID;
var language = Dynamicweb.eCommerce.International.Language.GetLanguage(orderline.Order.LanguageID);

var discount = new Dynamicweb.eCommerce.Orders.SalesDiscounts.SalesDiscount(discountID, language);

 

Hope this helps :)

 

- Jeppe

 
Marco Santos
Reply

Hello.

 

You are right, this would help, but I seem to be missing something.

 

I'm creating a subscriber (for Dynamicweb.Notifications.eCommerce.Order.State.Changed), but even though the discount line is created and remains in existence throughout the cart process, once I get into the subscriber (its now an order) I am unable to get the discount Id. The order lines (and product order lines) only show the "regular" order lines, the line I created with the discount information is gone.

 

Are there any peculiarities I should be aware regarding the creation of the discount lines? Like setting the product Id to be discount Id or something like that.

 

Marco.

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

I think I need to know a little bit about, what you're trying to achieve.

 

Are you interested in doing something when a cart turns into an order, or do you need to do something whenever the state of the order changes?

 

Are you creating the discount orderlines yourself in the code, or do you use the Discounts feature of eCommerce?

 
Marco Santos
Reply

Hello.

 

I am creating the order line myself (in a custom discount), and then checking for a state change to "activate" the discount (creating a voucher when the order is paid).

 

However, this is not a problem anymore, in the sense that as it turns out we are reverting the solution to DW 7, so things have to be adressed diferently (and are in fact virtually done). Also, this problem is apparently related to this issue, since I could not get the line to find out whether the discount was applied or not, so once that is resolved this will be resolved as well.

 

Thanks for the help.

 

You must be logged in to post in the forum