Developer forum

Forum » Ecommerce - Standard features » How to run a PriceProvider on the prices rendere inside the Product.Prices loop

How to run a PriceProvider on the prices rendere inside the Product.Prices loop

Martin Nielsen
Reply

Hey,

I have create a price provider that gives a discount of 50% on all products to all loged in users.

public class UserDiscountPriceProvider : PriceProvider
    {
        public override PriceRaw FindPrice(Product product, double quantity, string variantId, Currency currency, string unitId, User user)
        {
            PriceRaw priceRaw = null;

            if (user != null)
            {
                    var defaultPriceProvider = new DefaultPriceProvider();
                    var defaultPrice = defaultPriceProvider.FindPrice(product, quantity, variantId, currency, unitId, user);                
                    priceRaw = new PriceRaw(defaultPrice.Price * 0.5, currency);
            }

            return priceRaw;
        }
    }

When rendering my Product page the price shows up correct with 50% off.

But prices inside the Product.Prices loop still show with the original price. Shouldn't a Price provider also run for prices in the price matrix? Or is there a different provider for that? Or am i doing it wrong entirely :)


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Martin

The price matrix is some data that the default priceprovider can use to find the correct calculated price for the current product, order and user context. When you override the priceprovider, Dynamicweb will use that to calculate the price.

The prices loop is just a raw loop of the prices in the price table.

The price matrix is to find a price based on the context and return that as-is.

If you want 50% off for all users logged in, create a price in the price matrix that matches exactly that.

BR Nicolai

Votes for this answer: 1
 
Martin Nielsen
Reply

Hi Nicolai,

I had a hunch that I was doing something wrong.

Thank you for clarifying. I'll work something out with this new-found knowledge :D

/Martin

 

You must be logged in to post in the forum