Try our conversational search powered by Generative AI!

Always choose CustomerGroup price

Vote:
 

Hi!

Our customer has price groups for their customers and if you are not connected to a price group the have better prices if you buy 5 instead of 1 and so on. The thing is that a customer connected to a price group should not get the better price if they buy 5, it should always be the price in the price group.
How do I handle this? The totalt in the cart are calculated with the cheaper price but the customer should get the higher price since they are connected to a price group.
So what I want to do is to have Commerce to always pick the price group price even if it is higher.

Thanks!

/Kristoffer

#147133
Apr 06, 2016 16:56
Vote:
 

You could do something like this.  Add logic to determine customer price group.  Then register your implementation of IPriceService in container

using EPiServer.Events.ChangeNotification;
using EPiServer.Framework.Cache;
using Mediachase.Commerce;
using Mediachase.Commerce.Catalog;
using Mediachase.Commerce.Engine.Events;
using Mediachase.Commerce.Pricing;
using Mediachase.Commerce.Pricing.Database;
using System;
using System.Collections.Generic;
using System.Linq;

namespace EPiServer.Commerce.Sample.Business
{
    /// <summary>
    /// /
    /// </summary>
    /// <seealso cref="Mediachase.Commerce.Pricing.Database.PriceServiceDatabase" />
    public class PriceGroupPricingProvider : PriceServiceDatabase
    {
        public PriceGroupPricingProvider(ICatalogSystem catalogSystem,
            IChangeNotificationManager changeManager,
            ISynchronizedObjectInstanceCache objectInstanceCache,
            CatalogKeyEventBroadcaster broadcaster,
            IApplicationContext applicationContext,
            EntryIdentityResolver identityResolver) : base(catalogSystem, changeManager, objectInstanceCache, broadcaster, applicationContext, identityResolver) { }

        public IPriceValue GetDefaultPrice(MarketId market, DateTime validOn, CatalogKey catalogKey, Currency currency)
        {
            var myPricingGroup = CustomerPricing.AllCustomers;
            if (true)//enter logic here to get customer price group
            {
                myPricingGroup = new CustomerPricing (CustomerPricing.PriceType.PriceGroup, "mycode");
            }
            PriceFilter filter = new PriceFilter()
            {
                Quantity = 0,
                Currencies = new Currency[] { currency },
                CustomerPricing = new CustomerPricing[] { myPricingGroup }
            };

            return GetPrices(market, validOn, catalogKey, filter).SingleOrDefault();
        }


        public IEnumerable<IPriceValue> GetPrices(MarketId market, DateTime validOn, CatalogKey catalogKey, PriceFilter filter)
        {
            var myPricingGroup = CustomerPricing.AllCustomers;
            if (true)//enter logic here to get customer price group
            {
                myPricingGroup = new CustomerPricing(CustomerPricing.PriceType.PriceGroup, "mycode");
            }
            filter.CustomerPricing = new CustomerPricing[] { myPricingGroup };
            return base.GetPrices(market, validOn, catalogKey, filter);
        }


        public IEnumerable<IPriceValue> GetPrices(MarketId market, DateTime validOn, IEnumerable<CatalogKey> catalogKeys, PriceFilter filter)
        {
            var myPricingGroup = CustomerPricing.AllCustomers;
            if (true)//enter logic here to get customer price group
            {
                myPricingGroup = new CustomerPricing(CustomerPricing.PriceType.PriceGroup, "mycode");
            }
            filter.CustomerPricing = new CustomerPricing[] { myPricingGroup };
            return base.GetPrices(market, validOn, catalogKeys, filter);
        }


        public IEnumerable<IPriceValue> GetPrices(MarketId market, DateTime validOn, IEnumerable<CatalogKeyAndQuantity> catalogKeysAndQuantities, PriceFilter filter)
        {
            var myPricingGroup = CustomerPricing.AllCustomers;
            if (true)//enter logic here to get customer price group
            {
                myPricingGroup = new CustomerPricing(CustomerPricing.PriceType.PriceGroup, "mycode");
            }
            filter.CustomerPricing = new CustomerPricing[] { myPricingGroup };
            return base.GetPrices(market, validOn, catalogKeysAndQuantities, filter);
        }
    }
        
}
#147240
Apr 08, 2016 11:36
Vote:
 

Hi Mark!

This look really good. And this will work even when the workflow kicks in? I solved it by implementing my own workflows but maybe this is better?

/Kristoffer

#147257
Apr 08, 2016 12:48
Vote:
 

Yes the workflow calls the following 

GetPrices(lineItem.Parent.Parent.MarketId, FrameworkContext.Current.CurrentDateTime, new CatalogKey(entry), priceFilter)
#147265
Apr 08, 2016 15:10
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.