private void UpdatePriceOnSku(string code, DateTime from, DateTime until, IMarket market, string currency, decimal value) { var catalogKey = new CatalogKey(Mediachase.Commerce.Core.AppContext.Current.ApplicationId, code); var priceServiceDatabase = ServiceLocator.Current.GetInstance <IPriceService>(); CustomerPricing.PriceType type = (CustomerPricing.PriceType)Enum.Parse(typeof(CustomerPricing.PriceType), PriceType.SelectedValue); var priceCode = PriceCode.Text; var price = new PriceValue() { CatalogKey = catalogKey, CustomerPricing = new CustomerPricing(type, priceCode), MarketId = market.MarketId, MinQuantity = 0, UnitPrice = new Money(value, new Currency(currency)), ValidFrom = from, ValidUntil = until }; priceServiceDatabase.SetCatalogEntryPrices(catalogKey, new[] { price }); }
public void CompareTo_Works(int nodeId, int otherNodeId, string name, string otherName, int result) { var key = new CatalogKey(new CatalogNodeId((uint)nodeId), name); var other = new CatalogKey(new CatalogNodeId((uint)otherNodeId), otherName); Assert.Equal(result, key.CompareTo(other)); }
public void CompareTo_Null_Throws() { var key = new CatalogKey(); Assert.Throws <ArgumentNullException>(() => key.CompareTo((BTreeKey)null)); Assert.Throws <ArgumentNullException>(() => key.CompareTo((CatalogKey)null)); }
/// <summary> /// Get catalog entry prices of a catalog item /// </summary> /// <param name="catalogKey">catalog Key</param> /// <returns>list of <c>IPriceValue</c></returns> public IEnumerable <IPriceValue> GetCatalogEntryPrices(CatalogKey catalogKey) { List <IPriceValue> prices = new List <IPriceValue>(); prices.Add(XPriceParser.GetPrice(catalogKey, MarketId.Empty, new Currency("GBP"))); return(prices); }
public static EntryContentBase GetEntryContent(this CatalogKey catalogKey) { var entryContentLink = ReferenceConverter.Value .GetContentLink(catalogKey.CatalogEntryCode, CatalogContentType.CatalogEntry); return(ContentLoader.Value.Get <EntryContentBase>(entryContentLink)); }
/// <summary> /// Set catalog item prices /// </summary> /// <param name="catalogKey">catalog key</param> /// <param name="priceValues">price values</param> public void SetCatalogEntryPrices(CatalogKey catalogKey, IEnumerable <IPriceValue> priceValues) { if (!XPriceParser.prices.ContainsKey(catalogKey.CatalogEntryCode)) { XPriceParser.prices.Add(catalogKey.CatalogEntryCode, 10.99m); } }
// 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(); }
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); }
// 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 object Get(string id) { CatalogKey key = new CatalogKey(AppContext.Current.ApplicationId, id); var warehouseInventoryService = ServiceLocator.Current.GetInstance <IWarehouseInventoryService>(); return(warehouseInventoryService.List(key)); }
private IEnumerable <Attribute> GetLowestPricePerName(CatalogKey key) { return(_priceService.GetCatalogEntryPrices(key) .SelectMany(CreatePrices) .GroupBy(pt => pt.Item1) .Select(ptg => ptg.OrderBy(pt => pt.Item2).First()) .Select(pt => NewAttribute(pt.Item1, pt.Item2))); }
public ActionResult Index(DefaultVariation currentContent) // currentPage works { /* Implementation of action. You can create your own view model class that you pass to the view or * you can pass the page type for simpler templates */ MyCatalogKey = new CatalogKey(currentContent.Code); return(View(currentContent)); }
/// <summary> /// Default constructor /// </summary> /// <param name="catalogKey">catalog key</param> /// <param name="marketId">market Id</param> /// <param name="minQuantity">min quantity</param> /// <param name="unitPrice">unit price</param> /// <param name="customerPricing">customer Pricing</param> /// <param name="validFrom">valid from</param> /// <param name="validUntil">valid until</param> public ReadOnlyPriceValue(CatalogKey catalogKey, MarketId marketId, decimal minQuantity, Money unitPrice, CustomerPricing customerPricing, DateTime validFrom, DateTime?validUntil) { this.CatalogKey = catalogKey; this.MarketId = marketId; this.CustomerPricing = customerPricing; this.ValidFrom = validFrom; this.ValidUntil = validUntil; this.MinQuantity = minQuantity; this.UnitPrice = unitPrice; }
public void Constructor_SetsProperties() { var key = new CatalogKey(new CatalogNodeId(1), "Xcode"); Assert.Equal("Xcode", key.Name); Assert.Equal(new CatalogNodeId(1), key.NodeId); Assert.Equal(18, key.Size); Assert.Equal("Xcode (1)", key.ToString()); }
/// <summary> /// Retrive price value from enterprise services /// </summary> /// <param name="item">catalog item key</param> /// <param name="market">market id</param> /// <param name="currency">currency</param> /// <returns>product price</returns> public static IPriceValue GetPrice(CatalogKey item, MarketId market, Currency currency) { if (prices.ContainsKey(item.CatalogEntryCode)) { return(new ReadOnlyPriceValue(item, market, 0, new Money(prices[item.CatalogEntryCode], currency), CustomerPricing.AllCustomers, DateTime.MinValue, DateTime.MaxValue)); } else { return(new ReadOnlyPriceValue(item, market, 0, new Money(0m, currency), CustomerPricing.AllCustomers, DateTime.MinValue, DateTime.MaxValue)); } }
public object Get(string code) { CatalogKey key = new CatalogKey(AppContext.Current.ApplicationId, code); IPriceService priceService = ServiceLocator.Current.GetInstance <IPriceService>(); IPriceDetailService priceDetailService = ServiceLocator.Current.GetInstance <IPriceDetailService>(); IEnumerable <IPriceValue> catalogEntryPrices = priceService.GetCatalogEntryPrices(key); return(catalogEntryPrices); }
public IEnumerable <IPriceValue> GetCatalogEntryPrices(CatalogKey catalogKey) { List <IPriceValue> prices = new List <IPriceValue>(); foreach (var allMarket in _marketService.GetAllMarkets()) { prices.AddRange(GetPrices(allMarket.MarketId, DateTime.Now, catalogKey, null)); } return(prices); }
// 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 void ReadFrom_Works() { byte[] data = Convert.FromBase64String("ABAAAAABAAUAWABjAG8AZABl"); CatalogKey key = new CatalogKey(); Assert.Equal(18, key.ReadFrom(data, 0)); Assert.Equal("Xcode", key.Name); Assert.Equal(new CatalogNodeId(1), key.NodeId); Assert.Equal(18, key.Size); }
public static Price GetDefaultPrice(this ContentReference contentLink, MarketId marketId, Currency currency, DateTime validOn) { var catalogKey = new CatalogKey(ReferenceConverter.Value.GetCode(contentLink)); var priceValue = PriceService.Value.GetPrices(marketId, validOn, catalogKey, new PriceFilter() { Currencies = new[] { currency } }) .OrderBy(x => x.UnitPrice).FirstOrDefault(); return(priceValue == null ? new Price() : new Price(priceValue)); }
public ActionResult Index(DefaultVariation currentContent) // currentPage works { /* Implementation of action. You can create your own view model class that you pass to the view or * you can pass the page type for simpler templates */ // crashes if not set, fix that... //CustomerPricing priceGroupToUse = CheckInventory(currentContent); MyCatalogKey = new CatalogKey(AppContext.Current.ApplicationId, currentContent.Code); return(View(currentContent)); }
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(); }
private void SetupGetDiscountPrice(CatalogKey catalogKey, MarketId marketId, Money money) { _promotionServiceMock.Setup( x => x.GetDiscountPrice( catalogKey, marketId, money.Currency)) .Returns(new PriceValue { UnitPrice = money }); }
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 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); }
protected void AdjustOrderInventoryFromWarehouse(PurchaseOrderModel order) { var warehouseRepository = ServiceLocator.Current.GetInstance <IWarehouseRepository>(); var warehousesCache = warehouseRepository.List(); var warehouseInventory = ServiceLocator.Current.GetInstance <IWarehouseInventoryService>(); var expirationCandidates = new HashSet <ProductContent>(); var referenceConverter = ServiceLocator.Current.GetInstance <ReferenceConverter>(); var contentRepository = ServiceLocator.Current.GetInstance <IContentRepository>(); // Adjust inventory foreach (var f in order.OrderForms) { foreach (var i in f.LineItems) { try { var warehouse = warehousesCache.First(w => w.Code == i.WarehouseCode); var catalogEntry = CatalogContext.Current.GetCatalogEntry((string)i.CatalogEntryId); var catalogKey = new CatalogKey(catalogEntry); var inventory = new WarehouseInventory(warehouseInventory.Get(catalogKey, warehouse)); inventory.InStockQuantity = inventory.InStockQuantity - i.Quantity; if (inventory.InStockQuantity <= 0) { var contentLink = referenceConverter.GetContentLink(i.CatalogEntryId); var variant = contentRepository.Get <VariationContent>(contentLink); expirationCandidates.Add((ProductContent)variant.GetParent()); } // NOTE! Default implementation is to NOT save the inventory here, // as it will subtract double if the workflows also do this. // warehouseInventory.Save(inventory); } catch (Exception ex) { Log.Error("Unable to adjust inventory.", ex); } } } // TODO: Determine if you want to unpublish products with no sellable variants ExpireProductsWithNoInventory(expirationCandidates, contentRepository); // Alterntive approach is to notify the commerce admin about the products without inventory }
protected void AdjustOrderInventoryFromWarehouse(PurchaseOrderModel order) { var warehouseRepository = ServiceLocator.Current.GetInstance<IWarehouseRepository>(); var warehousesCache = warehouseRepository.List(); var warehouseInventory = ServiceLocator.Current.GetInstance<IWarehouseInventoryService>(); var expirationCandidates = new HashSet<ProductContent>(); var referenceConverter = ServiceLocator.Current.GetInstance<ReferenceConverter>(); var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>(); // Adjust inventory foreach (var f in order.OrderForms) { foreach (var i in f.LineItems) { try { var warehouse = warehousesCache.First(w => w.Code == i.WarehouseCode); var catalogEntry = CatalogContext.Current.GetCatalogEntry((string) i.CatalogEntryId); var catalogKey = new CatalogKey(catalogEntry); var inventory = new WarehouseInventory(warehouseInventory.Get(catalogKey, warehouse)); inventory.InStockQuantity = inventory.InStockQuantity - i.Quantity; if (inventory.InStockQuantity <= 0) { var contentLink = referenceConverter.GetContentLink(i.CatalogEntryId); var variant = contentRepository.Get<VariationContent>(contentLink); expirationCandidates.Add((ProductContent) variant.GetParent()); } // NOTE! Default implementation is to NOT save the inventory here, // as it will subtract double if the workflows also do this. // warehouseInventory.Save(inventory); } catch (Exception ex) { Log.Error("Unable to adjust inventory.", ex); } } } // TODO: Determine if you want to unpublish products with no sellable variants ExpireProductsWithNoInventory(expirationCandidates, contentRepository); // Alterntive approach is to notify the commerce admin about the products without inventory }
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()); }
#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")); }
/// <summary> /// Perform an additional stock check /// </summary> /// <param name="lineItems"></param> void ConfirmStocks(IEnumerable <LineItem> lineItems) { // TODO: Additonal stock check var warehouseInventory = ServiceLocator.Current.GetInstance <IWarehouseInventoryService>(); var warehouseRepository = ServiceLocator.Current.GetInstance <IWarehouseRepository>(); // TODO: Confirm use of default warehouse for your project var epiWarehouses = warehouseRepository.List().Where(w => w.Code.Equals("default")).ToList(); if (lineItems == null || lineItems.Any() == false) { return; } // [sku] = quantity, displayname var summary = new Dictionary <string, Tuple <decimal, string> >(); foreach (var i in lineItems) { Tuple <decimal, string> quantity; if (summary.TryGetValue(i.CatalogEntryId, out quantity)) { quantity = new Tuple <decimal, string>(quantity.Item1 + i.Quantity, quantity.Item2); } else { quantity = new Tuple <decimal, string>(i.Quantity, i.DisplayName); } summary[i.CatalogEntryId] = quantity; } foreach (var p in summary) { var catalogKey = new CatalogKey(AppContext.Current.ApplicationId, p.Key); var inventory = warehouseInventory.GetTotal(catalogKey, epiWarehouses); if (inventory == null || inventory.InStockQuantity < p.Value.Item1) { /// TODO: Add language string ModelState.AddModelError(string.Empty, "Variant is out of stock " + p.Value.Item2 + " (" + p.Key + ")"); } } }
protected void AdjustStocks(PurchaseOrder order) { var warehouseRepository = ServiceLocator.Current.GetInstance <IWarehouseRepository>(); var warehousesCache = warehouseRepository.List(); var warehouseInventory = ServiceLocator.Current.GetInstance <IWarehouseInventoryService>(); var expirationCandidates = new HashSet <ProductContent>(); var referenceConverter = ServiceLocator.Current.GetInstance <ReferenceConverter>(); var contentRepository = ServiceLocator.Current.GetInstance <IContentRepository>(); // Adjust inventory foreach (OrderForm f in order.OrderForms) { foreach (LineItem i in f.LineItems) { try { var warehouse = warehousesCache.Where(w => w.Code == i.WarehouseCode).First(); var catalogEntry = CatalogContext.Current.GetCatalogEntry(i.CatalogEntryId); var catalogKey = new CatalogKey(catalogEntry); var inventory = new WarehouseInventory(warehouseInventory.Get(catalogKey, warehouse)); //inventory.ReservedQuantity += i.Quantity; if ((inventory.InStockQuantity -= i.Quantity) <= 0) { var contentLink = referenceConverter.GetContentLink(i.CatalogEntryId); var variant = contentRepository.Get <VariationContent>(contentLink); expirationCandidates.Add((ProductContent)variant.GetParent()); } warehouseInventory.Save(inventory); } catch (Exception ex) { _log.Error("Unable to adjust inventory.", ex); } } } // TODO: Determine if you want to unpublish products with no sellable variants // ExpireProductsWithNoInventory(expirationCandidates, contentRepository); // Alterntive approach is to notify the commerce admin about the products without inventory }
public void AdjustStocks(PurchaseOrderModel order) { var warehouseRepository = ServiceLocator.Current.GetInstance<IWarehouseRepository>(); var warehousesCache = warehouseRepository.List(); var warehouseInventory = ServiceLocator.Current.GetInstance<IWarehouseInventoryService>(); var expirationCandidates = new HashSet<ProductContent>(); var referenceConverter = ServiceLocator.Current.GetInstance<ReferenceConverter>(); var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>(); // Adjust inventory foreach (var f in order.OrderForms) { foreach (var i in f.LineItems) { try { var warehouse = warehousesCache.First(w => w.Code == i.WarehouseCode); var catalogEntry = CatalogContext.Current.GetCatalogEntry(i.CatalogEntryId); var catalogKey = new CatalogKey(catalogEntry); var inventory = new WarehouseInventory(warehouseInventory.Get(catalogKey, warehouse)); if ((inventory.InStockQuantity -= i.Quantity) <= 0) { var contentLink = referenceConverter.GetContentLink(i.CatalogEntryId); var variant = contentRepository.Get<VariationContent>(contentLink); expirationCandidates.Add((ProductContent)variant.GetParent()); } warehouseInventory.Save(inventory); } catch (Exception ex) { LoggerExtensions.Error((ILogger) Log, "Unable to adjust inventory.", ex); } } } // TODO: Determine if you want to unpublish products with no sellable variants // ExpireProductsWithNoInventory(expirationCandidates, contentRepository); // Alterntive approach is to notify the commerce admin about the products without inventory }
protected void SetDefaultInventory(string code, decimal inStockQuantity, string warehouseCode = "default") { _log.Debug("Setting stock for {0} to {1}", code, inStockQuantity); var warehouse = _warehouseRepository.Get(warehouseCode); if (warehouse == null) throw new ArgumentNullException("warehouse"); if (inStockQuantity == 0) { throw new ArgumentNullException("inStockQuantity", "InStockQuantity is required"); } CatalogKey key = new CatalogKey(AppContext.Current.ApplicationId, code); var existingInventory = _inventoryService.Get(key, warehouse); WarehouseInventory inv; if (existingInventory != null) { inv = new WarehouseInventory(existingInventory); } else { inv = new WarehouseInventory(); inv.WarehouseCode = warehouse.Code; inv.CatalogKey = key; } inv.InStockQuantity = inStockQuantity; _inventoryService.Save(inv); }
public void SetCatalogEntryPrices(CatalogKey catalogKey, IEnumerable<IPriceValue> priceValues) { throw new NotImplementedException(); }
public IEnumerable<IPriceValue> GetCatalogEntryPrices(CatalogKey catalogKey) { return GetCatalogEntryPrices(new CatalogKey[] { catalogKey }); }
public IEnumerable<IPriceValue> GetPrices(MarketId market, DateTime validOn, CatalogKey catalogKey, PriceFilter filter) { return GetPrices(market, validOn, new CatalogKey[] { catalogKey }, filter); }
private void UpdatePriceOnSku(string code, DateTime from, DateTime until, IMarket market, string currency, decimal value) { var catalogKey = new CatalogKey(AppContext.Current.ApplicationId, code); var priceServiceDatabase =ServiceLocator.Current.GetInstance<IPriceService>(); CustomerPricing.PriceType type = (CustomerPricing.PriceType)Enum.Parse(typeof(CustomerPricing.PriceType), PriceType.SelectedValue); var priceCode = PriceCode.Text; var price = new PriceValue() { CatalogKey = catalogKey, CustomerPricing = new CustomerPricing(type, priceCode), MarketId = market.MarketId, MinQuantity = 0, UnitPrice = new Money(value, new Currency(currency)), ValidFrom = from, ValidUntil = until }; priceServiceDatabase.SetCatalogEntryPrices(catalogKey,new[]{price}); }
public void Setup() { _cheapPriceUSD = new Money(1000, "USD"); _expensivePriceGBP = new Money(2000, "GBP"); _discountPriceUSD = new Money(500, "USD"); _discountPriceGBP = new Money(500, "GBP"); var catalogSystemMock = new Mock<ICatalogSystem>(); _promotionServiceMock = new Mock<IPromotionService>(); _contentLoaderMock = new Mock<IContentLoader>(); _priceServiceMock = new Mock<IPriceService>(); _relationRepositoryMock = new Mock<IRelationRepository>(); _promotionServiceMock = new Mock<IPromotionService>(); _fakeAppContext = new FakeAppContext(); _referenceConverterMock = new Mock<ReferenceConverter>(catalogSystemMock.Object) { CallBase = true }; _urlResolverMock = new Mock<UrlResolver>(); _assetUrlConventionsMock = new Mock<AssetUrlConventions>(); _assetUrlResolverMock = new Mock<AssetUrlResolver>(_urlResolverMock.Object, _assetUrlConventionsMock.Object, _contentLoaderMock.Object); _subject = new CatalogIndexer(catalogSystemMock.Object, _priceServiceMock.Object, new Mock<IInventoryService>().Object, new MetaDataContext(), _contentLoaderMock.Object, _promotionServiceMock.Object, _referenceConverterMock.Object, _assetUrlResolverMock.Object, _relationRepositoryMock.Object, _fakeAppContext, new Mock<ILogger>().Object); var productReference = GetContentReference(444, CatalogContentType.CatalogEntry); var greenVariantReference = GetContentReference(445, CatalogContentType.CatalogEntry); var bluevariantReference = GetContentReference(446, CatalogContentType.CatalogEntry); var rootNodeReference = GetContentReference(10, CatalogContentType.CatalogNode); var catalogReference = GetContentReference(4, CatalogContentType.Catalog); var variants = new[] { bluevariantReference, greenVariantReference }; var greenCatalogKey = new CatalogKey(_fakeAppContext.ApplicationId, "Variant 1"); var blueCatalogKey = new CatalogKey(_fakeAppContext.ApplicationId, "Variant 2"); SetupGetContentLink("code", productReference); SetupGetFashionProduct(productReference, rootNodeReference); SetupGetVariants(productReference, variants); SetupGetRootNode(rootNodeReference, catalogReference); SetupGetCatalog(catalogReference); SetupGetDiscountPrice(blueCatalogKey, MarketId.Default, _discountPriceGBP); SetupGetDiscountPrice(blueCatalogKey, MarketId.Default, _discountPriceUSD); SetupGetDiscountPrice(greenCatalogKey, MarketId.Default, _discountPriceGBP); SetupGetDiscountPrice(greenCatalogKey, MarketId.Default, _discountPriceUSD); SetupGetItems(variants, CultureInfo.GetCultureInfo("en"), new List<FashionVariant> { new FashionVariant { Code = "Variant 1", Color = "Green", }, new FashionVariant { Code = "Variant 2", Color = "Blue", } }); SetupGetCatalogEntryPrices(new[] { greenCatalogKey, blueCatalogKey }); }
public IPriceValue GetDiscountPrice(CatalogKey catalogKey, MarketId marketId, Currency currency) { return GetDiscountPriceList(new[] { catalogKey }, marketId, currency).FirstOrDefault(); }
private decimal GetNewLineItemQty(LineItem lineItem, List<string> changeQtyReason) { var newLineItemQty = lineItem.Quantity; if (newLineItemQty < lineItem.MinQuantity || newLineItemQty > lineItem.MaxQuantity) { newLineItemQty = Math.Max(lineItem.MinQuantity, newLineItemQty); if (newLineItemQty != lineItem.Quantity) { changeQtyReason.Add("by Min Quantity setting"); } newLineItemQty = Math.Min(lineItem.MaxQuantity, newLineItemQty); if (newLineItemQty != lineItem.Quantity) { changeQtyReason.Add("by Max Quantity setting"); } } if (lineItem.InventoryStatus == (int)InventoryTrackingStatus.Enabled) { IWarehouse warehouse = ServiceLocator.Current.GetInstance<IWarehouseRepository>().Get(lineItem.WarehouseCode); IWarehouseInventory inventory = null; CatalogKey catalogKey = new CatalogKey(lineItem.Parent.Parent.ApplicationId, lineItem.CatalogEntryId); if (warehouse != null) { if (!warehouse.IsActive) { return 0; } inventory = ServiceLocator.Current.GetInstance<IWarehouseInventoryService>().Get( new CatalogKey(lineItem.Parent.Parent.ApplicationId, lineItem.CatalogEntryId), warehouse); } // if no inventory, return 0; if (inventory == null) { return 0; } decimal availableQuantity = inventory.InStockQuantity - inventory.ReservedQuantity; // item exists with appropriate quantity if (availableQuantity < newLineItemQty) { if (availableQuantity > 0) // there still exist items in stock { // check if we can backorder some items if ((inventory.AllowBackorder | inventory.AllowPreorder)) { //Increase stock qty by backorder qty if var availStockAndBackorderQty = availableQuantity + inventory.BackorderQuantity; if (availStockAndBackorderQty >= newLineItemQty) { //NONE } else { newLineItemQty = availStockAndBackorderQty; changeQtyReason.Add("by BackOrder quantity"); } } else { newLineItemQty = availableQuantity; } } else { if ((inventory.AllowBackorder | inventory.AllowPreorder) && inventory.PreorderQuantity > 0) { if (inventory.PreorderQuantity >= newLineItemQty) { //NONE } else { newLineItemQty = inventory.PreorderQuantity; changeQtyReason.Add("by Preorder quantity"); } } else if ((inventory.AllowBackorder | inventory.AllowPreorder) && inventory.BackorderQuantity > 0) { if (inventory.BackorderQuantity >= newLineItemQty) { } else { newLineItemQty = inventory.BackorderQuantity; changeQtyReason.Add("by BackOrder quantity"); } } else { newLineItemQty = 0; } } } } return newLineItemQty; }
public void Setup() { var synchronizedObjectInstanceCache = new Mock<ISynchronizedObjectInstanceCache>(); _cheapPriceUSD = new Money(1000, "USD"); _expensivePriceGBP = new Money(2000, "GBP"); _discountPriceUSD = new Money(500, "USD"); _discountPriceGBP = new Money(500, "GBP"); var catalogSystemMock = new Mock<ICatalogSystem>(); _promotionServiceMock = new Mock<IPromotionService>(); _contentLoaderMock = new Mock<IContentLoader>(); _priceServiceMock = new Mock<IPriceService>(); _relationRepositoryMock = new Mock<IRelationRepository>(); _promotionServiceMock = new Mock<IPromotionService>(); _fakeAppContext = new FakeAppContext(); _referenceConverterMock = new Mock<ReferenceConverter>( new EntryIdentityResolver(synchronizedObjectInstanceCache.Object), new NodeIdentityResolver(synchronizedObjectInstanceCache.Object)) { CallBase = true }; _urlResolverMock = new Mock<UrlResolver>(); _assetUrlConventionsMock = new Mock<AssetUrlConventions>(); _assetUrlResolverMock = new Mock<AssetUrlResolver>(_urlResolverMock.Object, _assetUrlConventionsMock.Object, _contentLoaderMock.Object); _subject = new SearchDocumentController(_priceServiceMock.Object, _promotionServiceMock.Object, _contentLoaderMock.Object, _referenceConverterMock.Object, _assetUrlResolverMock.Object, _relationRepositoryMock.Object, _fakeAppContext) { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration() }; var productReference = GetContentReference(444, CatalogContentType.CatalogEntry); var greenVariantReference = GetContentReference(445, CatalogContentType.CatalogEntry); var bluevariantReference = GetContentReference(446, CatalogContentType.CatalogEntry); var rootNodeReference = GetContentReference(10, CatalogContentType.CatalogNode); var catalogReference = GetContentReference(4, CatalogContentType.Catalog); var variants = new[] { bluevariantReference, greenVariantReference }; var greenCatalogKey = new CatalogKey(_fakeAppContext.ApplicationId, "Variant 1"); var blueCatalogKey = new CatalogKey(_fakeAppContext.ApplicationId, "Variant 2"); SetupGetContentLink("Product", productReference); SetupGetFashionProduct(productReference, rootNodeReference); SetupGetVariants(productReference, variants); SetupGetRootNode(rootNodeReference, catalogReference); SetupGetCatalog(catalogReference); SetupGetDiscountPrice(blueCatalogKey, MarketId.Default, _discountPriceGBP); SetupGetDiscountPrice(blueCatalogKey, MarketId.Default, _discountPriceUSD); SetupGetDiscountPrice(greenCatalogKey, MarketId.Default, _discountPriceGBP); SetupGetDiscountPrice(greenCatalogKey, MarketId.Default, _discountPriceUSD); SetupGetItems(variants, CultureInfo.GetCultureInfo("en"), new List<FashionVariant> { new FashionVariant { Code = "Variant 1", Color = "Green", Size = "Small" }, new FashionVariant { Code = "Variant 2", Color = "Blue", } }); SetupGetCatalogEntryPrices(new[] { greenCatalogKey, blueCatalogKey }); }
protected void SetPrices(string code, List<Price> prices) { if (code == null) throw new ArgumentNullException("code"); if (prices == null) return; CatalogKey key = new CatalogKey(AppContext.Current.ApplicationId, code); var catalogEntryPrices = _priceService.GetCatalogEntryPrices(key); //.ToList(); List<IPriceValue> priceValues = new List<IPriceValue>(catalogEntryPrices); foreach (Price price in prices) { // Already there? IPriceValue priceValue = priceValues.FirstOrDefault(p => p.MarketId.Value == price.marketId); if(priceValue == null) { // No - add it PriceValue newPrice = new PriceValue() { CatalogKey = key, MarketId = price.marketId, UnitPrice = new Money(price.price, new Currency(price.currency)), ValidFrom = DateTime.Now, CustomerPricing = CustomerPricing.AllCustomers, MinQuantity = 0 }; priceValues.Add(newPrice); } else { // We don't touch prices for the same market } } _log.Debug("Saving {0} prices for {1}", priceValues.Count, code); // Save prices back _priceService.SetCatalogEntryPrices(key, priceValues); }