Developer forum

Forum » Development » Product quantity prices in 9.5.5

Product quantity prices in 9.5.5

Rui Silva
Reply

In our custom live integration, we have the ability of loading quantity prices for the products by using a piece of code like:

            product.Prices.Clear();

            foreach (var price in prices)

            {

                product.Prices.Add(new Price

                {

                    Id = price.Id,

                    Amount = price.Amount.GetValueOrDefault(),

                    Quantity = price.Quantity.GetValueOrDefault(),

                    ProductId = price.ProductId,

                    VariantId = price.ProductVariantId,

                    LanguageId = Context.LanguageID,

                    UserCustomerNumber = price.UserCustomerNumber,

                    IsInformative = false,

                    CurrencyCode = Context.Currency.Code

                });

            }

 

After upgrading one of our solutions to 9.5.5 it breaks because the Prices property is now read only and can’t be changed with this piece of code.

Is there any other way to do this without having to write the prices in DW database by using the Price.SavePrices method?


Replies

 
Nicolai Pedersen
Reply

Use a priceprovider - that is why it is there... And this kind of code is the reason we made it readonly since it is the source of several bugs...

 
Rui Silva
Reply

Hi Nicolai,

We use a price provider, but to show something like this:

in the green square the results of the code I've showed before...

Is there anyway to have a live feed for those prices (EcomPrices table)?
 

 
Morten Snedker Dynamicweb Employee
Morten Snedker
Reply

Hi Rui,

Unless I am misunderstanding your postings, I would say that your approach is not quite right.

I see to distinct sections:

  1. Show prices per quantity interval (show/render only)
  2. Calculate the correct price based on quantity (PriceProvider)

So, I don't see the need for saving any prices with Product.Prices. Build a class that return the prices from your live feed, and simply implement into the template for render purpose. You may want to cache it per session. Then, when adding to the cart, the PriceProvider will get the proper price from the live feed based on the quantity passed along to it from its parameter property Quantity.

If your live feed is via the Dynamicweb Live Integration framework, you can even have ERP return it in the live response.

Let me have a comment.

Best regards
Morten Snedker

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Or use a template extender... Made for purposes like this

Votes for this answer: 1
 
Rui Silva
Reply

Thanks guys, for your comments.

I’ll try to use the Product template extender to overrule the DW tags for the prices.

 

You must be logged in to post in the forum