Developer forum

Forum » Development » product.Discount class crashing solution

product.Discount class crashing solution

Martin Gammelholm
Reply

Hello,

We've got a problem with the following code.
The problem is, that it will cause both VS and the solution to crash, when we run it and ask directly to the product.Discounts class. Also tested on the latest DW 8.4 version 

Our test price provider has the following code, the line if (product.Discounts! = Null && product.Discounts.Count> 0) which makes it crache.

I can easily take hold of the individual items in the list, for example. product.Discounts [0]. Price.Price without fail ...?

public class ProductPrice : PriceProvider

    {

        public override PriceRaw FindPrice(Product product, double quantity, string variantID, Currency currency, string unitID, Extranet user)

        {

            // Get the price from the DefaultPriceProvider

            //DefaultPriceProvider defaultProvider = new DefaultPriceProvider();

            //PriceRaw rawPrice = defaultProvider.FindPrice(product, quantity, variantID, currency, unitID, user);

            

            try

            {

                if (product.Discounts != null && product.Discounts.Count > 0)

                {

                    Dynamicweb.LogToFile.Log(

                        "ProductPriceProvider, ProductId=" + product.ID + " Discountprice=" +

                        product.Discounts[0].Price.Price,

                        "1stweb_test", LogToFile.LogType.ManyEntriesPerFile);

                }

                else

                {

                    Dynamicweb.LogToFile.Log(

                        "ProductPriceProvider, ProductId=" + product.ID + " Discountprice=null", "1stweb_test",

                        LogToFile.LogType.ManyEntriesPerFile);

                }

            }

            catch (Exception ex)

            {

 

 

            }

            

            return null;

        }

    }


Replies

 
Christian Rud Skovgaard
Reply

Hi Martin,

This has been identified as a recursion bug in our code and a bug has been created.

 

Kind regards

Christian

 
Christian Rud Skovgaard
Reply

Hi Martin,

After further investigation it seems that your code example actually provokes this. We have had similar examples before like these:

http://developer.dynamicweb-cms.com/forum/ecommerce-standard-features/list-of-products-on-product-page.aspx

http://developer.dynamicweb-cms.com/forum/development/custom-fee-provider.aspx

The trick is to make sure to just Return if your code is called again from itself. Hope this helps!

Kind regards

Christian

 

 

You must be logged in to post in the forum