Kentico 11 - CartItemPrice Removal :( How can I use a different source than SKUPrice for pricing?

Mark McKenna asked on January 9, 2018 16:15

Hello,

I've got a ticket in about this but it's not really going anywhere!

We use external systems to get a product price on a per customer basis. No customer actually uses standard pricing - every product/customer combo has a custom price.

Old Kentico 10 solution:

SKUPrice contained our standard price, and only really exists to prevent any errors with null pricing. Override the Add and Update shopping cart item handlers to populate CartItemPrice with our custom price, which the shopping cart then automatically (Without custom code) used instead of SKUPrice.

Kentico have removed CartItemPrice in K11. There doesn't seem any clear way to repeat the old functionality.

It seems a simple request, but how can I use a price not based on SKUPrice?

My current ideas include:

UnitPrice - but this set on every call of ShoppingCart.Evaluate() so doesn't seem possible Custom discount - discretely discount every product to the correct customer price (Always lower than standard) Something else - any ideas?

Thanks,

Mark

Correct Answer

Suneel Jhangiani answered on January 9, 2018 19:36

Kenitco 11 uses a new Ecommerce Customization Model

To implement a price per customer I think you should look at implemnting a custom IProductPricingService and in particular the GetPrices method - you can see an example at https://docs.kentico.com/k11/e-commerce-features/customizing-and-developing-your-store/product-related-customizing/customizing-product-prices#Customizingproductprices-Example%E2%80%93Usinganexternalpricingservice

1 votesVote for this answer Unmark Correct answer

Recent Answers


Peter Cranston answered on January 9, 2018 17:00

An approach we took (admittedly on a kentico 9 site, but I believe it should work for kentico 11) was to override the GetSKUPriceInternal method for SKUInfoProvider (following the approach outlined here). You can then use your own logic to decide what price should be returned.

0 votesVote for this answer Mark as a Correct answer

Mark McKenna answered on January 9, 2018 17:07

Peter, very first impressions are that that will work nicely. We went with ShoppingCart mods via advice from support, but actually overriding the skuprice would potentially work better in future with discounts.

It's a fairly large scale change since I assume ideally you'd use this in transformations on product detail views etc but there are ways around that.

I'll give it a go - many thanks for the suggestion!

Mark

0 votesVote for this answer Mark as a Correct answer

Mark McKenna answered on January 9, 2018 21:40

Suneel, well that appears at first glance to be a perfect answer. It sounds made for us to be honest.

I’ll accept I’m not up to date with the new documentation however I’m not really sure why Kentico Support have said I need to pay for consultancy and not mentioned IProductPricingService.

Will get building tomorrow! Thanks very much!

0 votesVote for this answer Mark as a Correct answer

Mark McKenna answered on January 10, 2018 10:17 (last edited on January 10, 2018 10:39)

My earlier excitement has been lower a little bit because I'm not sure how the ProductPricing option will work with the customer issue. IE: Does the service just populate SKUPrice each time, or does it effectively remove any access to SKUPrice by the ecommerce model?

This isn't an actual question - I'll investigate it myself.

I've also had another response from support with an option that sounds pretty bad/long winded but I'm not sure why this hasn't been mentioned by them. I'll email them a link to this thread for their views.

EDIT: Actually this'll teach me to read the documentation properly rather than skim reading :P I can see it appears to support exactly what we need - the GetPrices basic solution doesn't, but the service also supports getting the current shopping cart, which in turn means the user data is accessible.

It seems like this might actually provide a better system than the previous CartItemPrice anyway. Still not sure why support don't have this information....

0 votesVote for this answer Mark as a Correct answer

Suneel Jhangiani answered on January 10, 2018 12:33

The PriceParameters object should have all the information you need to retrieve the correct price. You need to note that the User object and Customer object will be NULL for an anonymous user.

The new model is incredibly flexible and I have found it very easy to implement a custom pricing service that is based on price lists such that prices can be based on country, role, or even an individual customer. I use additional tables for storing PriceList definition and PriceListItems which allows me to do something like the following:

if (!string.IsNullOrEmpty(list.PriceListObjectType))
{
            // check to see if the list applies to this customer
            switch (list.PriceListObjectType.ToLowerCSafe())
            {
                case "ecommerce.customer":
                    string fieldName = list.PriceListObjectField;
                    string fieldValue = list.PriceListObjectValue;
                    string customerFieldValue = priceParams.Customer.GetValue(fieldName).ToString();
                    if (fieldValue == customerFieldValue)
                    {
                        priceInfo = PriceListItemInfoProvider.GetPriceListItemInfo(sku.SKUID, list.PriceListID, currencyId);
                    }
                    break;
            }
    }

The above is just an example to give you an idea, however, you do need to consider the impact on the site if doing lots of these lookups.

0 votesVote for this answer Mark as a Correct answer

Mark McKenna answered on January 11, 2018 11:56

Suneel,

Thanks for the code sample. Yep I read the caching recommendation on the documentation. This is easily doable really. Our prices are fairly set so they don't need to be "live".

I see in your code sample you have set pricelists. Unfortunately due to the ancient external system I'm working with, I have to use a web service to get individual prices (I did bodge something together to get a page worth at a time but even so).

Still, this should still work. I'm just working out whether to just cache prices or save a copy to a local table as well.

The answer to my original question then is a resounding yes. I haven't received a reply back from support yet as to why they seeming tried to push me to consultations despite this being available.

Thanks so much for the headsup.

Mark

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.