public static IPriceValue GetSalePrice(string entryCode, MarketId marketId, Currency currency) { var customerPricing = new List <CustomerPricing> { new CustomerPricing(CustomerPricing.PriceType.AllCustomers, string.Empty), new CustomerPricing(CustomerPricing.PriceType.UserName, PrincipalInfo.Current.Name) }; if (CustomerContext.Current.CurrentContact != null) { customerPricing.Add(new CustomerPricing(CustomerPricing.PriceType.PriceGroup, CustomerContext.Current.CurrentContact.EffectiveCustomerGroup)); } var filter = new PriceFilter() { CustomerPricing = customerPricing, Currencies = new List <Currency> { currency }, ReturnCustomerPricing = true }; var prices = _priceService.Service.GetPrices(marketId, DateTime.Now, new CatalogKey(entryCode), filter); if (prices.Any()) { return(prices.OrderBy(x => x.UnitPrice.Amount).First()); } else { return(null); } }
public static IEnumerable <Price> Prices(this EntryContentBase entryContentBase) { //var market = MarketService.Value.GetAllMarkets().FirstOrDefault(x => x.DefaultLanguage.Name.Equals(entryContentBase.Language.Name)); var market = CurrentMarket.Value.GetCurrentMarket(); if (market == null) { return(Enumerable.Empty <Price>()); } var priceFilter = new PriceFilter { CustomerPricing = new[] { CustomerPricing.AllCustomers } }; if (entryContentBase is ProductContent productContent) { var variationLinks = productContent.GetVariants(); return(variationLinks.GetPrices(market.MarketId, priceFilter)); } if (entryContentBase is PackageContent packageContent) { return(packageContent.ContentLink.GetPrices(market.MarketId, priceFilter)); } return(entryContentBase is VariationContent variationContent ? variationContent.ContentLink.GetPrices(market.MarketId, priceFilter) : Enumerable.Empty <Price>()); }
protected void gvPrices_RowUpdate(object sender, GridViewUpdateEventArgs e) { int index = e.RowIndex; GridViewRow row = gvPrices.Rows[index]; Int64 PriceId = Int64.Parse(gvPrices.DataKeys[index].Value.ToString()); TextBox tb = (TextBox)row.Cells[0].FindControl("txtPriceName"); if (tb.Text == "") { Master.MessageCenter.DisplayErrorMessage(PricesStrings.GetText(@"PriceNameRequired")); return; } PriceFilter p = PriceFilter.FetchByName(tb.Text); if (p != null && p.PriceId != PriceId) { Master.MessageCenter.DisplayErrorMessage(PricesStrings.GetText(@"MessageSaveFailedNameAlreadyExists")); return; } p = PriceFilter.FetchByID(PriceId); p.PriceName = tb.Text; p.Save(); gvPrices.EditIndex = -1; LoadItems(); }
public static IPriceValue GetMsrpPrice(string entryCode, MarketId marketId, Currency currency) { var filter = new PriceFilter() { CustomerPricing = new List <CustomerPricing> { new CustomerPricing((CustomerPricing.PriceType) 4, string.Empty), }, Currencies = new List <Currency> { currency }, ReturnCustomerPricing = true }; var prices = _priceService.Service.GetPrices(marketId, DateTime.Now, new CatalogKey(entryCode), filter); if (prices.Any()) { return(prices.OrderBy(x => x.UnitPrice.Amount).First()); } else { return(null); } }
// new method for the... // \Infrastructure\Promotions\CustomPromotionEngineContentLoader.cs internal static IPriceValue GetSalePrice(ContentReference entryLink) { // Need the pricing context... have a look here List <CustomerPricing> customerPricing = GetCustomerPricingList(); IMarket theMarket = _currentMarket.Service.GetCurrentMarket(); IEnumerable <Currency> currencies = theMarket.Currencies; PriceFilter filter = new PriceFilter() { Quantity = 1M, // can be improved, simple for now Currencies = currencies, CustomerPricing = customerPricing, ReturnCustomerPricing = false }; VariationContent theEntry = _contentLoader.Service.Get <VariationContent>(entryLink); CatalogKey catalogKey = new CatalogKey(theEntry.Code); // 3 overloads //_pricingLoader.Service.GetPrices(entryLink,theMarket.MarketId.Value) IEnumerable <IPriceValue> prices = _priceService.Service.GetPrices( theMarket.MarketId.Value, FrameworkContext.Current.CurrentDateTime, catalogKey, filter); //_roPriceLoader.Service.GetCustomerPrices(contentReference,) // may use this one // Don't want the "BasePrice" ... this is the "SalePrice" return(prices.Where(x => x.CustomerPricing.PriceTypeId != (CustomerPricing.PriceType) 3) .OrderBy(pv => pv.UnitPrice).FirstOrDefault()); // Lowest price //return prices.OrderByDescending(p => p.UnitPrice.Amount).Last(); }
protected void gvPrices_RowCommand(object sender, GridViewCommandEventArgs e) { if (!e.CommandName.Equals("AddNew")) { return; } GridViewRow row = gvPrices.FooterRow; TextBox tb = (TextBox)row.FindControl("txtNewPriceName"); if (tb.Text == "") { Master.MessageCenter.DisplayErrorMessage(PricesStrings.GetText(@"PriceNameRequired")); return; } if (PriceFilter.FetchByName(tb.Text) != null) { Master.MessageCenter.DisplayErrorMessage(PricesStrings.GetText(@"MessageSaveFailedNameAlreadyExists")); return; } PriceFilter p = new PriceFilter(); p.PriceName = tb.Text; p.Save(); LoadItems(); }
#pragma warning restore 649 /// <summary> /// Saves the MSRP price /// </summary> /// <param name="priceDetailService"></param> /// <param name="contentLink"></param> /// <param name="marketId"></param> /// <param name="currency"></param> /// <param name="amount"></param> public static void SaveMsrp( this IPriceDetailService priceDetailService, ContentReference contentLink, MarketId marketId, Currency currency, decimal amount) { var priceFilter = new PriceFilter { Currencies = new List <Currency> { currency } }; var msrp = (PriceDetailValue)priceDetailService .List(contentLink, marketId, priceFilter, 0, int.MaxValue, out _) .FirstOrDefault( p => p.UnitPrice.Currency == currency && p.CustomerPricing.PriceTypeId == CustomerPricing.PriceType.PriceGroup && p.CustomerPricing.PriceCode == "MSRP"); if (msrp != null) { msrp.UnitPrice = new Money(amount, currency); } else { msrp = new PriceDetailValue(); var entryContent = _contentRepository.Service.Get <EntryContentBase>(contentLink); msrp.CatalogKey = new CatalogKey(entryContent.Code); msrp.CustomerPricing = new CustomerPricing(CustomerPricing.PriceType.PriceGroup, "MSRP"); msrp.UnitPrice = new Money(amount, currency); msrp.MarketId = marketId; msrp.MinQuantity = 0; msrp.ValidFrom = entryContent.StartPublish ?? DateTime.MinValue; } priceDetailService.Save(msrp); }
// Newer ECF 11 - Oct-17 internal Price GetTheRightCustomerPrice(ShirtVariation currentContent) { IEnumerable <IPriceValue> priceValues; // need to check if anonymous or not ... so the EffectiveGroup does not bother // Anonymous... could use the DefaultPrice, but may miss the tiered price if set at Anonymous if (CustomerContext.Current.CurrentContact == null) { PriceFilter filter = new PriceFilter() { Quantity = 1M, Currencies = new Currency[] { _marketService.GetCurrentMarket().Currencies.FirstOrDefault() }, // only have one at the moment... CustomerPricing = new CustomerPricing[] { new CustomerPricing(CustomerPricing.PriceType.AllCustomers, null), }, ReturnCustomerPricing = false // }; // The rest needed, CatKey, Market, TimeStamp CatalogKey catalogKey = new CatalogKey(currentContent.Code); // 3 overloads priceValues = _priceService.GetPrices( currentMarket.Service.GetCurrentMarket().MarketId.Value, FrameworkContext.Current.CurrentDateTime, catalogKey, filter); } else { // Logged on // no custom PriceTypes... yet PriceFilter filter = new PriceFilter() { Quantity = 1M, Currencies = new Currency[] { _marketService.GetCurrentMarket().Currencies.FirstOrDefault() }, // only have one at the moment... CustomerPricing = new CustomerPricing[] { new CustomerPricing(CustomerPricing.PriceType.AllCustomers, null), new CustomerPricing(CustomerPricing.PriceType.PriceGroup, CustomerContext.Current.CurrentContact.EffectiveCustomerGroup), // or several... new CustomerPricing(CustomerPricing.PriceType.UserName, CustomerContext.Current.CurrentContact.FirstName) }, ReturnCustomerPricing = false // // ... if true; gets all that applies }; // The rest needed, CatKey, Market, TimeStamp CatalogKey catalogKey = new CatalogKey(currentContent.Code); // 3 overloads priceValues = _priceService.GetPrices( currentMarket.Service.GetCurrentMarket().MarketId.Value, FrameworkContext.Current.CurrentDateTime, catalogKey, filter); } if (priceValues.Count() > 0) { return(new Price(priceValues.ToList().OrderBy(x => x.UnitPrice.Amount).FirstOrDefault())); } else { return(new Price()); // should not actually, could use default price... it's a demo } }
public IEnumerable <IPriceValue> GetPrices(string code) { List <IPriceValue> priceList = new List <IPriceValue>(); IMarket market = _marketService.GetCurrentMarket(); // DEFAULT if (String.IsNullOrEmpty(code)) { throw new ArgumentNullException("Code is needed"); } // need the key var catalogKey = new CatalogKey(code); //PriceFilter filter = new PriceFilter(); //priceList.(_priceService.GetPrices(market.MarketId, DateTime.Now, catalogKey, filter)); priceList = _priceService.GetCatalogEntryPrices(catalogKey).ToList(); foreach (IPriceValue item in priceList) { if (item.CustomerPricing.PriceTypeId.ToString() == "7") // could use the int { priceList.Clear(); break; } } //CustomerPricing.PriceType ppp = new CustomerPricing.PriceType(); // custom PriceTypeId, a bit cumbersome PriceFilter filter = new PriceFilter() { Quantity = 0M, Currencies = new Currency[] { "USD" }, CustomerPricing = new CustomerPricing[] { new CustomerPricing((CustomerPricing.PriceType) 7, "VIP") // or "Andersson"... need the code...or // ... do filtering (like remove from list) }, ReturnCustomerPricing = true // ...see below for info // interpretation of the CustomerPricing property... if true; gets all that applies }; //IEnumerable< CustomerPricing> custPrice = new CustomerPricing(CustomerPricing.PriceType.PriceGroup, "PriceOverride"); //filter.CustomerPricing = custPrice; priceList = _priceService.GetPrices( _marketService.GetCurrentMarket().MarketId.Value, DateTime.Now, catalogKey, filter).ToList(); // just checking var p = new PriceValue(); p.UnitPrice = new Money(99, "USD"); p.MinQuantity = 2; priceList.Add((IPriceValue)p); return(priceList); }
private void GetPriceInfo(DemoMarketsViewModel viewModel) { var filter = new PriceFilter(); viewModel.OptimizedPrices = _priceService.GetPrices(viewModel.SelectedMarket.MarketId, DateTime.Now, new CatalogKey(viewModel.Shirt.Code), filter); filter.Quantity = 1; var custPricing = new List <CustomerPricing> { new CustomerPricing(CustomerPricing.PriceType.AllCustomers, string.Empty) }; if (CustomerContext.Current.CurrentContact != null) { if (!string.IsNullOrEmpty(PrincipalInfo.Current.Name)) { custPricing.Add(new CustomerPricing(CustomerPricing.PriceType.UserName, PrincipalInfo.Current.Name)); } if (!string.IsNullOrEmpty(CustomerContext.Current.CurrentContact.EffectiveCustomerGroup)) { custPricing.Add(new CustomerPricing(CustomerPricing.PriceType.PriceGroup, CustomerContext.Current.CurrentContact.EffectiveCustomerGroup)); } } filter.CustomerPricing = custPricing; viewModel.FilteredPrices = _priceService.GetPrices(viewModel.SelectedMarket.MarketId, DateTime.Now, new CatalogKey(viewModel.Shirt.Code), filter); Money lowestPrice = viewModel.FilteredPrices.OrderBy(p => p.UnitPrice).First().UnitPrice; Money lowestAllowed = viewModel.OptimizedPrices .Where(p => p.CustomerPricing.PriceTypeId == (CustomerPricing.PriceType) 3) .First().UnitPrice; var promos = _promotionEngine.Evaluate(viewModel.Shirt.ContentLink); if (promos.Count() > 0) { viewModel.PromotionsTotal = promos.Sum(p => p.Percentage); lowestPrice -= lowestPrice * viewModel.PromotionsTotal / 100; if (lowestPrice < lowestAllowed) { viewModel.SellingPrice = lowestAllowed; } else { viewModel.SellingPrice = lowestPrice; viewModel.PromotionsApplied = true; } } }
// new method for the... // \Infrastructure\Promotions\CustomPromotionEngineContentLoader.cs public IPriceValue GetSalePrice(EntryContentBase entry, decimal quantity) { // some basic validation if (entry == null) { throw new NullReferenceException("entry object can't be null"); } if (entry as IPricing == null) { throw new InvalidCastException("entry object must implement IPricing"); } // Need the pricing context... // Get the groups List <CustomerPricing> customerPricing = GetCustomerPricingList(); IMarket theMarket = _currentMarket.GetCurrentMarket(); IEnumerable <Currency> currencies = theMarket.Currencies; PriceFilter filter = new PriceFilter() { Quantity = quantity, Currencies = currencies, CustomerPricing = customerPricing, ReturnCustomerPricing = false }; CatalogKey catalogKey = new CatalogKey(entry.Code); // 3 overloads //_pricingLoader.Service.GetPrices(entryLink,theMarket.MarketId.Value) IEnumerable <IPriceValue> prices = _priceService.GetPrices( theMarket.MarketId.Value, FrameworkContext.Current.CurrentDateTime, catalogKey, filter); #region Old garbage // Prob. don't want the "BasePrice" ... this is the "SalePrice" //return prices.Where(x => // x.CustomerPricing.PriceTypeId != (CustomerPricing.PriceType)3) // .OrderBy(pv => pv.UnitPrice).FirstOrDefault(); // Lowest price #endregion // doing for promos if (prices.Count() >= 1) { return(prices.OrderBy(p => p.UnitPrice.Amount).First()); //... } else { return(new PriceValue()); } }
public IList <IPriceValue> GetPriceList(string code, MarketId marketId, PriceFilter priceFilter) { if (String.IsNullOrEmpty(code)) { throw new ArgumentNullException("code"); } var catalogKey = new CatalogKey(code); return(_priceService.GetPrices(marketId, DateTime.Now, catalogKey, priceFilter) .OrderBy(x => x.UnitPrice.Amount) .ToList()); }
public IList<IPriceValue> GetPriceList(string code, MarketId marketId, PriceFilter priceFilter) { if (String.IsNullOrEmpty(code)) { throw new ArgumentNullException("code"); } var catalogKey = new CatalogKey(_appContext.ApplicationId, code); return _priceService.GetPrices(marketId, DateTime.Now, catalogKey, priceFilter) .OrderBy(x => x.UnitPrice.Amount) .ToList(); }
protected Money?GetItemPrice(CatalogEntryDto.CatalogEntryRow entry, LineItem lineItem, CustomerContact customerContact) { Currency currency = new Currency(lineItem.Parent.Parent.BillingCurrency); List <CustomerPricing> customerPricing = new List <CustomerPricing>(); customerPricing.Add(CustomerPricing.AllCustomers); if (customerContact != null) { var userKey = _mapUserKey.ToUserKey(customerContact.UserId); if (userKey != null && !string.IsNullOrWhiteSpace(userKey.ToString())) { customerPricing.Add(new CustomerPricing(CustomerPricing.PriceType.UserName, userKey.ToString())); } if (!string.IsNullOrEmpty(customerContact.EffectiveCustomerGroup)) { customerPricing.Add(new CustomerPricing(CustomerPricing.PriceType.PriceGroup, customerContact.EffectiveCustomerGroup)); } } IPriceService priceService = ServiceLocator.Current.GetInstance <IPriceService>(); PriceFilter priceFilter = new PriceFilter() { Currencies = new List <Currency>() { currency }, Quantity = lineItem.Quantity, CustomerPricing = customerPricing, ReturnCustomerPricing = false // just want one value }; // Get the lowest price among all the prices matching the parameters IPriceValue priceValue = priceService .GetPrices(lineItem.Parent.Parent.MarketId, FrameworkContext.Current.CurrentDateTime, new CatalogKey(entry), priceFilter) .OrderBy(pv => pv.UnitPrice) .FirstOrDefault(); if (priceValue != null) { return(priceValue.UnitPrice); } if (lineItem.PlacedPrice != 0) { return(new Money(lineItem.PlacedPrice, currency)); } return(null); }
public IEnumerable <IPriceValue> FakePromotion(EntryContentBase sku) // support case { //List<IPriceValue> priceList = new List<IPriceValue>(); IMarket market = _marketService.GetCurrentMarket(); // ...first add the default for all customer pricing List <CustomerPricing> customerPricing = new List <CustomerPricing> { new CustomerPricing(CustomerPricing.PriceType.AllCustomers, string.Empty) }; // ...then add the price type specific to a user and to a possible price group IPrincipal currentUser = PrincipalInfo.CurrentPrincipal; if (CustomerContext.Current.CurrentContact != null) { if (!string.IsNullOrEmpty(currentUser.Identity.Name)) { customerPricing.Add(new CustomerPricing(CustomerPricing.PriceType.UserName, currentUser.Identity.Name)); } CustomerContact currentUserContact = CustomerContext.Current.CurrentContact; if (currentUserContact != null && !string.IsNullOrEmpty(currentUserContact.EffectiveCustomerGroup)) { // Could look for both Org & Cust. customerPricing.Add(new CustomerPricing(CustomerPricing.PriceType.PriceGroup, currentUserContact.EffectiveCustomerGroup)); } } // Add the BasePrice (in this case the "PromotionPrice") customerPricing.Add(new CustomerPricing((CustomerPricing.PriceType) 3, string.Empty)); PriceFilter filter = new PriceFilter() { Quantity = 1M, Currencies = new Currency[] { "USD" }, CustomerPricing = customerPricing, ReturnCustomerPricing = true // note this arg. }; CatalogKey catalogKey = new CatalogKey(sku.Code); //priceList = _priceService.GetPrices( // market.MarketId.Value, DateTime.Now, catalogKey, filter).ToList(); return(_priceService.GetPrices( market.MarketId.Value, DateTime.Now, catalogKey, filter).ToList()); }
public IList<IPriceValue> GetPriceList(IEnumerable<CatalogKey> catalogKeys, MarketId marketId, PriceFilter priceFilter) { if (catalogKeys == null) { throw new ArgumentNullException("catalogKeys"); } if (!catalogKeys.Any()) { return Enumerable.Empty<IPriceValue>().ToList(); } return _priceService.GetPrices(marketId, DateTime.Now, catalogKeys, priceFilter) .OrderBy(x => x.UnitPrice.Amount) .ToList(); }
protected void gvPrices_RowDelete(object sender, GridViewDeleteEventArgs e) { int index = e.RowIndex; Int64 PriceId = Int64.Parse(gvPrices.DataKeys[index].Value.ToString()); Query qry = new Query(ProductYad2.TableSchema) .Where(ProductYad2.Columns.PriceId, PriceId); if (qry.GetCount() > 0) { Master.MessageCenter.DisplayErrorMessage(PricesStrings.GetText(@"MessageDeleteFailedInUse")); return; } PriceFilter.Delete(PriceId); LoadItems(); }
public void Check_That_PriceFilter_Returns_Right_Delegate() { // Arrange var container = new GameFilterContainer { Model = new GamesFilterModel { PriceFrom = 5, PriceTo = (decimal)10.5, } }; var filter = new PriceFilter(); var list = new List <Game> { new Game { Price = (decimal)4.9, }, new Game { Price = 5, }, new Game { Price = 7, }, new Game { Price = (decimal)10.5, }, new Game { Price = (decimal)10.6, }, }; // Act filter.Execute(container); Func <Game, bool> resultCondition = CombinePredicate <Game> .CombineWithAnd(container.Conditions); IEnumerable <Game> result = list.Where(x => (resultCondition(x))); // Assert Assert.IsTrue(result.Count() == 3); }
public IPriceValue GetDiscountPrice(CatalogKey catalogKey, MarketId marketId, Currency currency) { var market = _marketService.GetMarket(marketId); currency = currency != Currency.Empty ? currency : market.DefaultCurrency; var priceFilter = new PriceFilter { CustomerPricing = new[] { CustomerPricing.AllCustomers }, Quantity = 1, ReturnCustomerPricing = true, Currencies = new[] { currency } }; var prices = _priceService.GetPrices(marketId, DateTime.Now, catalogKey, priceFilter) .OrderBy(x => x.UnitPrice.Amount) .ToList(); foreach (var entry in GetEntries(prices)) { var price = prices .FirstOrDefault(x => x.CatalogKey.CatalogEntryCode.Equals(entry.Code) && x.UnitPrice.Currency.Equals(currency)); if (price == null) { continue; } var discountPrices = GetDiscountedPrices(entry.ContentLink, market, currency); if (!discountPrices.Any()) { return(price); } return(new PriceValue { CatalogKey = price.CatalogKey, CustomerPricing = CustomerPricing.AllCustomers, MarketId = price.MarketId, MinQuantity = 1, UnitPrice = discountPrices.SelectMany(x => x.DiscountPrices).OrderBy(x => x.Price).First().Price, ValidFrom = DateTime.UtcNow, ValidUntil = null }); } return(null); }
public static IPriceValue GetSalePrice(string entryCode, MarketId marketId, Currency currency) { var customerPricing = new List <CustomerPricing> { new CustomerPricing(CustomerPricing.PriceType.AllCustomers, string.Empty), new CustomerPricing(CustomerPricing.PriceType.UserName, PrincipalInfo.Current.Name) }; if (CustomerContext.Current.CurrentContact != null) { customerPricing.Add(new CustomerPricing(CustomerPricing.PriceType.PriceGroup, CustomerContext.Current.CurrentContact.EffectiveCustomerGroup)); } var filter = new PriceFilter() { CustomerPricing = customerPricing, Currencies = new List <Currency> { currency }, ReturnCustomerPricing = true }; var prices = _priceService.Service.GetPrices(marketId, DateTime.Now, new CatalogKey(entryCode), filter); if (prices.Any()) { return(prices.OrderBy(x => x.UnitPrice.Amount).First()); } else { // if the entry has no price without sale code prices = _priceService.Service.GetCatalogEntryPrices(new CatalogKey(entryCode)) .Where(x => x.ValidFrom <= DateTime.Now && (!x.ValidUntil.HasValue || x.ValidUntil.Value >= DateTime.Now)) .Where(x => x.UnitPrice.Currency == currency && x.MarketId == marketId); if (prices.Any()) { return(prices.OrderBy(x => x.UnitPrice.Amount).First()); } else { return(null); } } }
public IPriceValue GetDefaultPrice(MarketId market, DateTime validOn, CatalogKey catalogKey, Currency currency) { PriceFilter filter = new PriceFilter() { Quantity = new Decimal?(new Decimal(0)), Currencies = (IEnumerable <Mediachase.Commerce.Currency>) new Mediachase.Commerce.Currency[1] { currency }, CustomerPricing = (IEnumerable <CustomerPricing>) new CustomerPricing[1] { CustomerPricing.AllCustomers } }; return(GetPrices(market, validOn, catalogKey, filter).FirstOrDefault()); }
public IPriceValue GetDefaultPrice(MarketId market, DateTime validOn, CatalogKey catalogKey, Currency currency) { PriceFilter filter = new PriceFilter() { Quantity = new Decimal?(new Decimal(0)), Currencies = (IEnumerable<Mediachase.Commerce.Currency>)new Mediachase.Commerce.Currency[1] { currency }, CustomerPricing = (IEnumerable<CustomerPricing>)new CustomerPricing[1] { CustomerPricing.AllCustomers } }; return GetPrices(market, validOn, catalogKey, filter).FirstOrDefault(); }
/// <summary> /// Detches a list of allavailable filter options as a C# friendly object. /// </summary> /// <returns>a <see cref="List{T}"/> of <see cref="FilterBase"/> objects</returns> public List <FilterBase> GetAllFilters() { List <FilterBase> filters = new List <FilterBase>(); PriceFilter pf = new PriceFilter(); pf.Min = DatabaseContext.Products.Min(p => p.Price); pf.Max = DatabaseContext.Products.Max(p => p.Price); ColorFilter cf = new ColorFilter(); cf.Colors.AddRange(DatabaseContext.ColorOptions.Select(co => co.Color).Distinct()); filters.Add(pf); filters.Add(cf); return(filters); }
#pragma warning restore 649 /// <summary> /// Get's the MSRP price /// </summary> /// <param name="priceService"></param> /// <param name="contentLink"></param> /// <param name="marketId"></param> /// <param name="currency"></param> /// <returns></returns> public static IPriceValue LoadMsrp(this IPriceService priceService, ContentReference contentLink, MarketId marketId, Currency currency) { var contentRepository = ServiceLocator.Current.GetInstance <IContentRepository>(); var entryContent = contentRepository.Get <EntryContentBase>(contentLink); var catalogKey = new CatalogKey(entryContent.Code); var priceFilter = new PriceFilter { Currencies = new List <Currency> { currency } }; return(priceService .GetPrices(marketId, DateTime.UtcNow, catalogKey, priceFilter) .FirstOrDefault( p => p.CustomerPricing.PriceTypeId == CustomerPricing.PriceType.PriceGroup && p.CustomerPricing.PriceCode == "MSRP")); }
public override Money?GetPlacedPrice( EntryContentBase entry, decimal quantity, CustomerContact customerContact, MarketId marketId, Currency currency) { var customerPricing = new List <CustomerPricing> { CustomerPricing.AllCustomers }; if (customerContact != null) { var userKey = _mapUserKey.ToUserKey(customerContact.UserId); if (userKey != null && !string.IsNullOrWhiteSpace(userKey.ToString())) { customerPricing.Add(new CustomerPricing(CustomerPricing.PriceType.UserName, userKey.ToString())); } if (!string.IsNullOrEmpty(customerContact.EffectiveCustomerGroup)) { customerPricing.Add(new CustomerPricing(CustomerPricing.PriceType.PriceGroup, customerContact.EffectiveCustomerGroup)); } } var priceFilter = new PriceFilter { Currencies = new List <Currency> { currency }, Quantity = quantity, CustomerPricing = customerPricing, ReturnCustomerPricing = false }; var priceValue = _priceService .GetPrices(marketId, DateTime.UtcNow, new CatalogKey(entry.Code), priceFilter) .OrderBy(pv => pv.UnitPrice) .FirstOrDefault(); return(priceValue?.UnitPrice); }
/// <summary> /// Gets the sale price. /// </summary> /// <param name="entry">The entry used to fetch prices.</param> /// <param name="quantity">The quantity.</param> /// <param name="market">The market.</param> /// <param name="currency">The currency.</param> /// <returns></returns> public static Price GetSalePrice(Entry entry, decimal quantity, IMarket market, Currency currency) { List <CustomerPricing> customerPricing = new List <CustomerPricing>(); customerPricing.Add(CustomerPricing.AllCustomers); var principal = PrincipalInfo.CurrentPrincipal; if (principal != null) { if (!string.IsNullOrEmpty(principal.Identity.Name)) { customerPricing.Add(new CustomerPricing(CustomerPricing.PriceType.UserName, principal.Identity.Name)); } CustomerContact currentUserContact = principal.GetCustomerContact(); if (currentUserContact != null && !string.IsNullOrEmpty(currentUserContact.EffectiveCustomerGroup)) { customerPricing.Add(new CustomerPricing(CustomerPricing.PriceType.PriceGroup, currentUserContact.EffectiveCustomerGroup)); } } IPriceService priceService = ServiceLocator.Current.GetInstance <IPriceService>(); PriceFilter filter = new PriceFilter() { Quantity = quantity, Currencies = new Currency[] { currency }, CustomerPricing = customerPricing }; // return less price value IPriceValue priceValue = priceService.GetPrices(market.MarketId, FrameworkContext.Current.CurrentDateTime, new CatalogKey(entry), filter) .OrderBy(pv => pv.UnitPrice) .FirstOrDefault(); if (priceValue != null) { return(new Price(priceValue.UnitPrice)); } return(null); }
private static IQueryable <PriceDto> Filter(PriceFilter filter, IQueryable <PriceDto> results) { if (filter == null) { return(results); } if (filter.StartDate != null) { results = results.Where(item => item.Date >= filter.StartDate); } if (filter.EndDate != null) { results = results.Where(item => item.Date <= filter.EndDate); } if (!string.IsNullOrWhiteSpace(filter.CompanyName)) { results = results.Where(item => item.CompanyName == filter.CompanyName); } return(results); }
public static ItemCollection <Price> GetPrices(this IEnumerable <ContentReference> entryContents, MarketId marketId, PriceFilter priceFilter) { var customerPricingList = priceFilter.CustomerPricing != null ? priceFilter.CustomerPricing.Where(x => x != null).ToList() : Enumerable.Empty <CustomerPricing>().ToList(); var entryContentsList = entryContents.Where(x => x != null).ToList(); var catalogKeys = entryContentsList.Select(GetCatalogKey); IEnumerable <IPriceValue> priceCollection; if (marketId == MarketId.Empty && (!customerPricingList.Any() || customerPricingList.Any(x => string.IsNullOrEmpty(x.PriceCode)))) { priceCollection = PriceService.Value.GetCatalogEntryPrices(catalogKeys); } else { var customerPricingsWithPriceCode = customerPricingList.Where(x => !string.IsNullOrEmpty(x.PriceCode)).ToList(); if (customerPricingsWithPriceCode.Any()) { priceFilter.CustomerPricing = customerPricingsWithPriceCode; } priceCollection = PriceService.Value.GetPrices(marketId, DateTime.UtcNow, catalogKeys, priceFilter); } var result = new ItemCollection <Price>(); foreach (var priceValue in priceCollection) { var entryLink = entryContentsList.FirstOrDefault(c => GetCode(c).Equals(priceValue.CatalogKey.CatalogEntryCode, StringComparison.OrdinalIgnoreCase)); var entryContent = ContentLoader.Value.Get <EntryContentBase>(entryLink); result.Add(new Price(priceValue, entryContent)); } return(result); }
public IList<IPriceValue> GetDiscountPriceList(IEnumerable<CatalogKey> catalogKeys, MarketId marketId, Currency currency) { if (_marketService.GetMarket(marketId) == null) { throw new ArgumentException(string.Format("market '{0}' does not exist", marketId)); } var priceFilter = new PriceFilter { CustomerPricing = new[] { CustomerPricing.AllCustomers }, Quantity = 1, ReturnCustomerPricing = true, }; if (currency != Currency.Empty) { priceFilter.Currencies = new[] { currency }; } var prices = catalogKeys.SelectMany(x => _pricingService.GetPriceList(x.CatalogEntryCode, marketId, priceFilter)); return GetDiscountPrices(prices.ToList(), marketId, currency); }
public ActionResult Get([FromQuery] PriceFilter filter) { if (!filter.MinPrice.HasValue && !filter.MaxPrice.HasValue) { return(Ok(FakeData.Products.Values)); } if (!filter.MinPrice.HasValue) { filter.MinPrice = int.MinValue; } if (!filter.MaxPrice.HasValue) { filter.MaxPrice = int.MaxValue; } var items = FakeData.Products .Where(p => filter.MinPrice <= p.Value.Price && p.Value.Price <= filter.MaxPrice) .Select(p => p.Value); return(Ok(items)); }
public IList <IPriceValue> GetDiscountPriceList(IEnumerable <CatalogKey> catalogKeys, MarketId marketId, Currency currency) { if (_marketService.GetMarket(marketId) == null) { throw new ArgumentException(string.Format("market '{0}' does not exist", marketId)); } var priceFilter = new PriceFilter { CustomerPricing = new[] { CustomerPricing.AllCustomers }, Quantity = 1, ReturnCustomerPricing = true, }; if (currency != Currency.Empty) { priceFilter.Currencies = new[] { currency }; } var prices = catalogKeys.SelectMany(x => _pricingService.GetPriceList(x.CatalogEntryCode, marketId, priceFilter)); return(GetDiscountPrices(prices.ToList(), marketId, currency)); }
public void PriceFilterTest() { var expectedProductCount = 2; var productEntity1 = new ProductEntity { productId = 45848, name = "shorts", description = "short pants", price = 8, category = "pants" }; var productEntity2 = new ProductEntity { productId = 4184688, name = "trousers", description = "trousers", price = 12, category = "pants" }; var productEntity3 = new ProductEntity { productId = 848488, name = "blue shirt", description = "shirt", price = 88, category = "shirts" }; var productEntityList = new List <ProductEntity>(); productEntityList.Add(productEntity1); productEntityList.Add(productEntity2); productEntityList.Add(productEntity3); PriceFilter <ProductEntity> priceFilter = new PriceFilter <ProductEntity>(AppConstants.PRICE_THRESHOLD); var actualProductCount = priceFilter.Operation(productEntityList).Count; Assert.AreEqual(actualProductCount, expectedProductCount); }
public IEnumerable<IPriceValue> GetPrices(MarketId market, DateTime validOn, IEnumerable<CatalogKey> catalogKeys, PriceFilter filter) { var quantity = filter.Quantity ?? new Decimal(0); return GetPrices(market, validOn, catalogKeys.Select(x => new CatalogKeyAndQuantity(x, quantity)), filter); }
public IEnumerable<IPriceValue> GetPrices(MarketId market, DateTime validOn, CatalogKey catalogKey, PriceFilter filter) { return GetPrices(market, validOn, new CatalogKey[] { catalogKey }, filter); }
public IEnumerable<IPriceValue> GetPrices(MarketId marketId, DateTime validOn, IEnumerable<CatalogKeyAndQuantity> catalogKeysAndQuantities, PriceFilter filter) { var prices = new List<IPriceValue>(); foreach (var catalogKeyAndQuantity in catalogKeysAndQuantities) { var itemPrices = GetCatalogEntryPrices(catalogKeyAndQuantity.CatalogKey).ToList(); if (catalogKeyAndQuantity.Quantity > 0) { itemPrices.RemoveAll(x => x.MinQuantity > catalogKeyAndQuantity.Quantity); } prices.AddRange(itemPrices); } foreach (var price in prices.ToList()) { if (marketId != MarketId.Empty && price.MarketId != marketId) { prices.Remove(price); continue; } if (filter.CustomerPricing != null && filter.CustomerPricing.Any()) { if (!filter.CustomerPricing.Contains(price.CustomerPricing) && !IsPriceOverride(price.CustomerPricing)) { prices.Remove(price); continue; } } } var returnPrices = new List<IPriceValue>(); if (filter.ReturnCustomerPricing) { var groupedPrices = prices.GroupBy(x => new { x.CatalogKey, x.MinQuantity, x.CustomerPricing }); groupedPrices.ForEach(priceGroup => { var orderedPriceGroup = priceGroup.OrderBy(x => x.UnitPrice); returnPrices.Add(orderedPriceGroup.FirstOrDefault()); }); } else { var groupedPrices = prices.GroupBy(x => new { x.CatalogKey, x.MinQuantity }); groupedPrices.ForEach(priceGroup => { var orderedPriceGroup = priceGroup.OrderBy(x => x.UnitPrice); returnPrices.Add(orderedPriceGroup.FirstOrDefault(d => IsPriceOverride(d.CustomerPricing)) ?? orderedPriceGroup.FirstOrDefault()); }); } return returnPrices.OrderBy(x => x.UnitPrice); }
protected Money? GetItemPrice(CatalogEntryDto.CatalogEntryRow entry, LineItem lineItem, CustomerContact customerContact) { List<CustomerPricing> customerPricing = new List<CustomerPricing>(); customerPricing.Add(CustomerPricing.AllCustomers); if (customerContact != null) { var userKey = _mapUserKey.ToUserKey(customerContact.UserId); if (userKey != null && !string.IsNullOrWhiteSpace(userKey.ToString())) { customerPricing.Add(new CustomerPricing(CustomerPricing.PriceType.UserName, userKey.ToString())); } if (!string.IsNullOrEmpty(customerContact.EffectiveCustomerGroup)) { customerPricing.Add(new CustomerPricing(CustomerPricing.PriceType.PriceGroup, customerContact.EffectiveCustomerGroup)); } } IPriceService priceService = ServiceLocator.Current.GetInstance<IPriceService>(); PriceFilter priceFilter = new PriceFilter() { Currencies = new List<Currency>() { new Currency(lineItem.Parent.Parent.BillingCurrency) }, Quantity = lineItem.Quantity, CustomerPricing = customerPricing, ReturnCustomerPricing = false // just want one value }; // Get the lowest price among all the prices matching the parameters IPriceValue priceValue = priceService .GetPrices(lineItem.Parent.Parent.MarketId, FrameworkContext.Current.CurrentDateTime, new CatalogKey(entry), priceFilter) .OrderBy(pv => pv.UnitPrice) .FirstOrDefault(); if (priceValue == null) { return null; } else { return priceValue.UnitPrice; } }
// Where it happens for the new Promos/Cust-Pricing...need to clean this mess upp public Price CheckDiscountPrice( EntryContentBase entry, decimal quantity, decimal promoPrice) { // Get the list var customerPricing = GetCustomerPricingList(); // Add BasePrice - Lowest possible customerPricing.Add(new CustomerPricing((CustomerPricing.PriceType) 3, string.Empty)); // Define the PriceFilter PriceFilter filter = new PriceFilter() { Quantity = quantity, // need improvements here Currencies = new Currency[] { _currentMarket.GetCurrentMarket().Currencies.FirstOrDefault() }, // only have one at the moment... CustomerPricing = customerPricing, // changed ReturnCustomerPricing = true // // ... if true; gets all that applies }; // The rest needed, CatKey, Market, TimeStamp CatalogKey catalogKey = new CatalogKey(entry.Code); // 3 overloads #region This is old stuff, may not use /* more hassle to get it working you could say, but used in the right way ... * ...it could simplyfy ... but it's still old */ //ItemCollection<Price> prices = pricingSKU.GetPrices( // _readOnlyPricingLoader.Service // , _currentMarket.Service.GetCurrentMarket().MarketId // , customerPricing); #endregion // ToDo: Get all applicable prices //IEnumerable<IPriceValue> prices = null; // starter IEnumerable <IPriceValue> prices = // Solution _priceService.GetPrices(_currentMarket.GetCurrentMarket().MarketId , DateTime.Now, catalogKey , filter); #region Old garbage //ToDo: Identify the lowest price when the "base-price is excluded" // Outcommented is starter-code to make things work ... // ...exchange the below for lab-code //Price p = new Price(); //IPriceValue lowPrice = p.ToPriceValue(); // Solution //IPriceValue lowPrice = prices.Where(x => x.MinQuantity <= quantity // && x.CustomerPricing.PriceTypeId != (CustomerPricing.PriceType)3) // do not look on "BasePrice" // .OrderBy(pv => pv.UnitPrice).FirstOrDefault(); #endregion //ToDO: Get the base price (which is the lowest possible price) //IPriceValue basePrice = null; // is the starter #region New garbage //_priceService.GetPrices() //IPriceValue basePrice2 = null; //if (prices.Where(p => p.CustomerPricing.PriceTypeId == (CustomerPricing.PriceType)3).Any()) //{ #endregion // whatever price comes out IPriceValue lowestPrice = prices.Where (p => p.CustomerPricing.PriceTypeId != (CustomerPricing.PriceType) 3).First(); // get the base price IPriceValue basePrice = prices.Where( x => x.CustomerPricing.PriceTypeId == (CustomerPricing.PriceType) 3).First(); // Solution, pick the base price if promos goes below if (basePrice != null && basePrice.UnitPrice.Amount >= promoPrice) // new promos { return(new Price(basePrice)); } else { // returning the promo-Price ... comes as an arg. (decimal) return(new Price { UnitPrice = new Money(promoPrice, _currentMarket.GetCurrentMarket().DefaultCurrency), ValidFrom = lowestPrice.ValidFrom, ValidUntil = lowestPrice.ValidUntil, MinQuantity = lowestPrice.MinQuantity, MarketId = lowestPrice.MarketId, EntryContent = entry, CustomerPricing = lowestPrice.CustomerPricing }); } }
public IList <IPriceValue> GetPriceList(IEnumerable <CatalogKey> catalogKeys, MarketId marketId, PriceFilter priceFilter) { if (catalogKeys == null) { throw new ArgumentNullException("catalogKeys"); } if (!catalogKeys.Any()) { return(Enumerable.Empty <IPriceValue>().ToList()); } return(_priceService.GetPrices(marketId, DateTime.Now, catalogKeys, priceFilter) .OrderBy(x => x.UnitPrice.Amount) .ToList()); }
public IList<IPriceDetailValue> List(ContentReference catalogContentReference, MarketId marketId, PriceFilter filter, int offset, int count, out int totalCount) { var prices = List(catalogContentReference).ToList(); foreach (var price in prices.ToList()) { if (marketId != MarketId.Empty && price.MarketId != marketId) { prices.Remove(price); continue; } if (filter.Quantity != null) { if (price.MinQuantity > filter.Quantity) { prices.Remove(price); continue; } } if (filter.CustomerPricing != null && filter.CustomerPricing.Any()) { if (!filter.CustomerPricing.Contains(price.CustomerPricing)) { prices.Remove(price); continue; } } } totalCount = prices.Count(); var returnVal = prices.AsQueryable().Skip(offset).Take(count); return returnVal.ToList(); }