Developer forum

Forum » Development » Distinguish between a real product and a discount in an OrderLineTemplateExtender

Distinguish between a real product and a discount in an OrderLineTemplateExtender


Reply
Hi there,

How do I determine the difference between a product and a discount in an OrderLineTemplateExtender? I need to extend real products by querying some of their custom fields, which obviously won't work for discounts. I see a few options:

1. OrderLine.Type
OrderLine.Type = 0 (Product)
OrderLine.Type = 1 (Discount)

Are these all available options? Are there products with a Type other than 2 or discounts with a type other than 1? (And why is Type not an enum?)

2. OrderLine.DiscountID
Is DiscountID always filled for all discounts and empty for all products? Does an empty string always mean I have a product?

3. OrderLine.Product.ID
This one seems to be filled for products, and seems to be empty for discounts. Is this always the case?

What's the recommended strategy here?

Thanks,

Imar

Replies

 
Nicolai Høeg Pedersen
Reply
Asking hard questions.

Orderline.Type is a string representation of Orderline.Orderlinetype enum - at the moment 4 different values. Have no clue why there is no enum property... Bad API design. And there might very well be new orderline types in the future.

DiscountID is either "0", string.empty or null for products without a discount.

Orderline.Product.ID can be a valid product ID for discount lines. It depends on the discount. A discount can be another product and then the productID will be set.That is where the OrderLineType comes in handy. Orderline.Type = 3 is a discount in the form of a product.

BR and nice weekend, Nicolai
 
Reply
>> Asking hard questions.

Ha, yes. Doing difficult stuff, and stretching the API to its limits. So far, having lots of fun and I still seem to be able to do whatever needs to be done.

So am I right when I think that checking DiscountID for 0, "" or null is my safest option to find a real product?

Thanks, and you too have a great weekend.

Imar
 
Nicolai Høeg Pedersen
Reply
I would say orderline.type = 0 - that is a product. Discounts would have type > 0
 
Reply
Ah, yes, that makes sense as soon as I fully realized what you mean with:

>> DiscountID is either "0", string.empty or null for products without a discount.

This could be a product (which I am looking for) but without a discount. As soon as I have a discount for that product, it gets an ID and my logic breaks.

Thanks!

Imar

 

You must be logged in to post in the forum