Developer forum

Forum » Development » Discount Matrix issue

Discount Matrix issue

Keld Gøtterup
Reply

I have a problem getting a discount throught the API.

I created an Orderline Discount (Exclusive) in the Discount Matrix which works fine when going through razor and loopitems. 

But when i use Dynamicweb.eCommerce.Products.Product object i have no access to see the discount. How can i get the discount on the Product Object?

 


Replies

 
Nicolai Pedersen
Reply

Hi Keld

Discounts are not related to products - they are related to an order because it is in the context of an ordet that we can calculate the discount. i.e. if you have a discount that is valid if you buy 2, have a specific delivery country, or have a voucher etc.

What kind of information do you need and in what context? Maybe I can lead you on the right track.

 
Rune Skovbo
Reply

Hi Nicolai,

Keld is not available right now, so maybe I can shed some more light on this issue. In a product list template, we have this piece of code to access product information:

// First loop we have in a product list template, works fine
foreach (LoopItem product in GetLoop("Products"))
{

    var price = product.GetDouble("Ecom:Product.Price.PriceWithVAT");

    // works fine
    var discount = product.GetDouble("Ecom:Product.Discount.TotalAmount.PriceWithVAT");

}


// Second loop is executed in a helper class, outside of a template

List<Dynamicweb.eCommerce.Products.Product> products = new List<Dynamicweb.eCommerce.Products.Product>();
// populated with multiple returns from Dynamicweb.eCommerce.Products.Product.GetProductByID(id)

foreach (var product in products)
{
    var price = product.Price.PriceWithoutVAT;

    // product.Discounts.Count is always 0, even though we know this product has a discount in discount matrix
    var discount = product.Discounts.TotalDiscount.PriceWithVAT;
}

First loop is executed in Product List template, and works fine. Second loop we execute in a helper method, so we do not have the context of a template, thus use product fields instead. In such case, product.Price is fine, however, product.Discounts is always an empty list, even though we know for sure that it has discounts in discount matrix (discount is attached to a group this product belongs to).

Does that make sense?

 
Viktor Letavin
Reply

Hi,

there is difference in api to get all product discounts, generaly due discount martix has come after 'Sales discount' so I guess next code will help you:

// discount info collection
DiscountInfoCollection discountMatrixDiscounts = product.DiscountMatrix

// discounts total price
var discountMatrixPrice = discountMatrixDiscounts.TotalPrice

 

BR, Viktor.

 
Keld Gøtterup
Reply

Hi Viktor
I get the following errors when trying to do the code you are suggesting, im running version 8.8.1.12

Error    17    'Dynamicweb.eCommerce.Products.Product' does not contain a definition for 'DiscountMatrix' and no extension method 'DiscountMatrix' accepting a first argument of type 'Dynamicweb.eCommerce.Products.Product' could be found (are you missing a using directive or an assembly reference?)   

Error    16    'Dynamicweb.eCommerce.Orders.Discounts.DiscountInfoCollection' is inaccessible due to its protection level   

Error    18    'Dynamicweb.eCommerce.Orders.Discounts.DiscountInfoCollection' does not contain a definition for 'TotalPrice' and no extension method 'TotalPrice' accepting a first argument of type 'Dynamicweb.eCommerce.Orders.Discounts.DiscountInfoCollection' could be found (are you missing a using directive or an assembly reference?)   

 

 
Viktor Letavin
Reply

Hi,

I am sorry that wasn't attentive in providing example to you.

For now the functionality you've trying to use is internal only, but TFS #26571 was created and will be provided with a hotfix. Then my example will work.

BR, Viktor.

 
Kristian Kirkholt Dynamicweb Employee
Kristian Kirkholt
Reply
This post has been marked as an answer

Hi Keld
The problem TFS#26571 Make Order.Discounts api publicly visible.  has now been fixed in version 8.8.1.19

You are able to find this build in the download section:

http://doc.dynamicweb.com/releases-and-downloads/latest-releases

Please contact Dynamicweb Support if you need any additional help regarding this.

Kind Regards
Dynamicweb Support
Kristian Kirkholt

Votes for this answer: 1

 

You must be logged in to post in the forum