AI OnAI Off
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); } } }
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
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