/// <summary> /// Gets the order from item. /// </summary> /// <param name="orderItem">The order item.</param> /// <returns>The order from item.</returns> protected virtual T GetOrderFromItem(Item orderItem) { if (orderItem == null) { return(Context.Entity.Resolve <T>()); } IDataMapper dataMapper = Context.Entity.Resolve <IDataMapper>(); T order = dataMapper.GetEntity <T>(orderItem, "OrderMappingRule"); order.OrderLines = new List <DomainModel.Orders.OrderLine>(); foreach (Item orderLineItem in orderItem.Children) { DomainModel.Orders.OrderLine orderLine = dataMapper.GetEntity <DomainModel.Orders.OrderLine>(orderLineItem, "OrderLineMappingRule"); orderLine.Id = orderLineItem.ID.ToString(); Assert.IsNotNull(orderLine.Product, "There is no products in the orderline"); order.OrderLines.Add(orderLine); } return(order); }
/// <summary> /// Converts the specified input totals. /// </summary> /// <param name="inputTotals">The input totals.</param> /// <param name="outputCurrency">The output currency.</param> /// <returns>The output totals.</returns> public virtual TTotals Convert(TTotals inputTotals, TCurrency outputCurrency) { Assert.ArgumentNotNull(inputTotals, "Input totals"); Assert.ArgumentNotNull(outputCurrency, "Output currency"); Assert.IsNotNull(this.ShopContext, "Unable to convert currency. ShopContext should be set."); GeneralSettings generalSettings = this.ShopContext.GeneralSettings; Assert.IsNotNull(generalSettings, "Unable to convert currency. General Settings should be set."); if (!ID.IsID(generalSettings.MasterCurrency)) { Log.Warn("Master currency item Id is invalid.", this); return(inputTotals); } Item item = ItemManager.GetItem(generalSettings.MasterCurrency, Language.Current, Sitecore.Data.Version.Latest, Sitecore.Context.Database); if (item == null) { Log.Error("Master currency item was not found.", this); return(inputTotals); } IDataMapper dataMapper = Context.Entity.Resolve <IDataMapper>(); TCurrency masterCurrency = dataMapper.GetEntity <TCurrency>(item); if (masterCurrency == null) { Log.Error("Master currency was not defined.", this); return(inputTotals); } if (masterCurrency.Code.Equals(outputCurrency.Code, StringComparison.OrdinalIgnoreCase)) { return(inputTotals); } BusinessCatalogSettings businessCatalogSettings = this.ShopContext.BusinessCatalogSettings; Assert.IsNotNull(businessCatalogSettings, "Unable to convert currency. Business Catalog Settings should be set."); Item currencyMatrixRootItem = Sitecore.Context.Database.GetItem(businessCatalogSettings.CurrencyMatrixLink); if (currencyMatrixRootItem == null) { Log.Error("Currency matrix root item was not found.", this); return(inputTotals); } Item currenciesRootItem = Sitecore.Context.Database.GetItem(businessCatalogSettings.CurrenciesLink); if (currenciesRootItem == null) { Log.Error("Currencies root item was not found.", this); return(inputTotals); } string currencyQuery = string.Format(".//*[@Code='{0}']", outputCurrency.Code); Item outputCurrencyItem = currenciesRootItem.Axes.SelectSingleItem(currencyQuery); if (outputCurrencyItem == null) { Log.Error("Output currency item was not found.", this); return(inputTotals); } string query = string.Format(".//*[@Currency Link='{0}']/*[@Currency Link='{1}']", generalSettings.MasterCurrency, outputCurrencyItem.ID); Item exchangeRateItem = currencyMatrixRootItem.Axes.SelectSingleItem(query); if (exchangeRateItem == null) { Log.Error("Exchange rate item was not found.", this); return(inputTotals); } Assert.IsNotNullOrEmpty(exchangeRateItem["Exchange Rate"], string.Concat("Exchange rate was no set for currencies. Master currency: ", masterCurrency.Code, ", Display currency: ", outputCurrency.Code)); decimal exchangeRate; if (!decimal.TryParse(exchangeRateItem["Exchange Rate"], NumberStyles.Currency, CultureInfo.InvariantCulture, out exchangeRate)) { Log.Error(string.Concat("Can not convert the exchange rate. Master currency: ", masterCurrency.Code, ", Display currency: ", outputCurrency.Code), this); exchangeRate = 1; } return(this.Convert(inputTotals, exchangeRate)); }
/// <summary> /// Registers the settings object instance. /// </summary> /// <param name="args">The arguments.</param> /// <param name="container">The container.</param> /// <param name="source">The source.</param> protected virtual void RegisterInstance(ConfigurationPipelineArgs args, IEntity container, Item source) { IDataMapper mapper = Context.Entity.Resolve <IDataMapper>(); args.ConfigurationItem = mapper.GetEntity(source, args.ConfigurationItemType); }