Example #1
0
        /// <summary>
        /// Gets the source object.
        /// </summary>
        /// <param name="fieldId">The field id.</param>
        /// <param name="orderEntity">The order entity.</param>
        /// <returns>The source object.</returns>
        private static object GetSourceObject(string fieldId, object orderEntity)
        {
            if (!string.IsNullOrEmpty(fieldId))
            {
                if (!ID.IsID(fieldId))
                {
                    return(orderEntity);
                }

                var  id   = new ID(fieldId);
                Item item = Sitecore.Context.Database.GetItem(id);
                if (item != null)
                {
                    var          templateFieldItem = (TemplateFieldItem)item;
                    TemplateItem templateItem      = templateFieldItem.Template;
                    if (templateItem.Name.Equals("Order"))
                    {
                        return(orderEntity);
                    }

                    if (templateItem.Name.Equals("Company Master Data"))
                    {
                        BusinessCatalogSettings businessCatalogSettings = Context.Entity.GetConfiguration <BusinessCatalogSettings>();
                        return(Sitecore.Context.Database.GetItem(businessCatalogSettings.CompanyMasterDataLink));
                    }
                }
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// Processes the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public virtual void Process(PipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            Order order = args.CustomData["order"] as Order;

            if (order == null)
            {
                return;
            }

            BusinessCatalogSettings businnesCatalogSettings = Context.Entity.GetConfiguration <BusinessCatalogSettings>();
            Item companyMasterData = Sitecore.Context.Database.SelectSingleItem(businnesCatalogSettings.CompanyMasterDataLink);

            if (companyMasterData == null)
            {
                return;
            }

            string queryString    = string.Format("orderid={0}&mode=mail", order.OrderNumber);
            Item   saleDepartment = companyMasterData.Children["Sale"];
            var    saleParams     = new { Recipient = saleDepartment["Email"] };

            IMail mailProvider = Context.Entity.Resolve <IMail>();

            mailProvider.SendMail("Order Mail To Admin", saleParams, queryString);
        }
Example #3
0
        protected virtual string ExtractPaymentLinkUrl(string fieldName)
        {
            Assert.IsNotNullOrEmpty(fieldName, "fieldName");

            if (Sitecore.Web.WebUtil.IsExternalUrl(fieldName))
            {
                return(fieldName);
            }

            BusinessCatalogSettings businessCatalogSettings = Context.Entity.GetConfiguration <BusinessCatalogSettings>();
            Item paymentsItem = Sitecore.Context.Database.GetItem(businessCatalogSettings.PaymentSystemsLink);

            Assert.IsNotNull(paymentsItem, "Payments item is null");
            Assert.IsNotNull(paymentsItem.Fields[fieldName], string.Concat("Payments item does not contains field: '", fieldName, "'"));

            LinkField linkField = paymentsItem.Fields[fieldName];

            Assert.IsNotNull(linkField, string.Concat("'", fieldName, "' is not a link field"));

            // If link is not internal just return url value.
            string externalUrl = linkField.Url;

            if (!linkField.LinkType.Equals("internal"))
            {
                return(externalUrl);
            }

            // If the site doesn't contains Business Catalog/Payments item under itself, Payment pages urls are wrong.
            // E.g.: Site path is: '/sitecore/content/Examples/Home';
            // Business Catalog path is: '/sitecore/content/Examples/Business Catalog';
            // Payment item path is: '/sitecore/content/Examples/Business Catalog/Payments';
            // In this case return page url is: '/Examples/Home/checkout/paymentreturnpage.aspx';
            // But should be: '/checkout/paymentreturnpage.aspx';
            Item targetPageItem = Sitecore.Context.Database.GetItem(linkField.TargetID);

            Assert.IsNotNull(targetPageItem, string.Concat("'", fieldName, "' contains invalid target item"));

            UrlOptions urlOptions = new UrlOptions
            {
                SiteResolving     = true, ShortenUrls = true,
                AddAspxExtension  = true, EncodeNames = true,
                LanguageEmbedding = LanguageEmbedding.AsNeeded
            };
            string relativeTargetPageUrl = LinkManager.GetItemUrl(targetPageItem, urlOptions);

            Assert.IsNotNull(HttpContext.Current.Request, "Http request is null");
            UrlString url = new UrlString
            {
                HostName = HttpContext.Current.Request.Url.Host,
                Path     = relativeTargetPageUrl
            };

            return(url.ToString());
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OrderManager&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="searchProvider">The search provider.</param>
        /// <param name="orderIdGenerator">The order id generator.</param>
        public OrderManager(ISearchProvider searchProvider, OrderIDGenerator orderIdGenerator)
        {
            this.entityHelper     = Context.Entity.Resolve <EntityHelper>();
            this.searchProvider   = searchProvider;
            this.OrderIDGenerator = orderIdGenerator;

            BusinessCatalogSettings settings = Context.Entity.GetConfiguration <BusinessCatalogSettings>();

            Assert.IsNotNull(settings, typeof(BusinessCatalogSettings), "Unable initialize BusinessCatalogSettings.");
            Assert.IsNotNullOrEmpty(settings.OrdersLink, "Unable initialize Orders root item.");

            this.Database = Sitecore.Context.ContentDatabase;
            this.ItemId   = settings.OrdersLink;
        }
        /// <summary>
        /// Gets the option item from query.
        /// </summary>
        /// <param name="section">
        /// The section.
        /// </param>
        /// <param name="query">
        /// The query.
        /// </param>
        /// <returns>
        /// </returns>
        private static Item GetOptionItemFromQuery(string section, string query)
        {
            BusinessCatalogSettings businessCatalogSettings = Context.Entity.GetConfiguration <BusinessCatalogSettings>();
            EntityHelper            entityHelper            = Context.Entity.Resolve <EntityHelper>();
            string sectionValue = entityHelper.GetPropertyValueByField <string, BusinessCatalogSettings>(businessCatalogSettings, section);

            Assert.IsNotNullOrEmpty(sectionValue, "Item path is null");

            Item catalogItem = Sitecore.Context.Database.GetItem(sectionValue);

            Assert.IsNotNull(catalogItem, "Could not find BusinessCatalog/" + section);
            Item optionItem = catalogItem.Axes.SelectSingleItem(query);

            return(optionItem);
        }
Example #6
0
        /// <summary>
        /// Gets the country root item.
        /// </summary>
        /// <returns>The country root item.</returns>
        protected virtual Item GetCountryRootItem()
        {
            Assert.IsNotNull(this.ShopContext, "ShopContext cannot be null.");

            BusinessCatalogSettings businessCatalogSettings = this.ShopContext.BusinessCatalogSettings;

            Assert.IsNotNull(businessCatalogSettings, "Unable to read countries. Business catalog settings not found.");
            Assert.IsNotNullOrEmpty(businessCatalogSettings.CountriesLink, "Unable to read countries. Countries link not found.");

            Database database = this.ShopContext.Database;

            Assert.IsNotNull(database, "Unable to read countries. Database not found.");

            return(database.GetItem(businessCatalogSettings.CountriesLink));
        }
Example #7
0
        /// <summary>
        /// Builds the query.
        /// </summary>
        /// <param name="searchWords">The search words.</param>
        /// <returns>Return the lucene search query.</returns>
        protected virtual Lucene.Net.Search.Query BuildQuery(string searchWords)
        {
            BusinessCatalogSettings businessCatalogSettings = Sitecore.Ecommerce.Context.Entity.GetConfiguration <BusinessCatalogSettings>();
            string       productRepository = businessCatalogSettings.ProductsLink;
            BooleanQuery query             = new BooleanQuery();

            query.Add(new BooleanClause(new PrefixQuery(new Term(Sitecore.Search.BuiltinFields.Content, searchWords.ToLower())), Occur.MUST));
            query.Add(new TermQuery(new Term(Sitecore.Search.BuiltinFields.Language, Sitecore.Context.Language.Name)), Occur.MUST);

            ////we should avoid search hits from product repository.
            if (!string.IsNullOrEmpty(productRepository))
            {
                productRepository = ShortID.Encode(new ID(productRepository)).ToLowerInvariant();
                query.Add(new BooleanClause(new PrefixQuery(new Term(Sitecore.Search.BuiltinFields.Path, productRepository)), Occur.MUST_NOT));
            }

            return(query);
        }
Example #8
0
        protected virtual IEnumerable <OrderStatus> GetAvailableFollowingStatuses(OrderStatus status)
        {
            Assert.ArgumentNotNull(status, "status");
            IEntity entity = status as IEntity;

            if (entity != null && !string.IsNullOrEmpty(entity.Alias))
            {
                Item orderStatusItem = Sitecore.Context.ContentDatabase.GetItem(entity.Alias);
                Assert.IsNotNull(orderStatusItem, string.Concat("Order status item is null. ID: '", entity.Alias, "'"));
                ListString avalibleStatusesIds = new ListString(orderStatusItem["Available List"]);

                foreach (string statusId in avalibleStatusesIds)
                {
                    Item statusItem = Sitecore.Context.ContentDatabase.SelectSingleItem(statusId);
                    if (statusItem == null)
                    {
                        yield return(default(OrderStatus));
                    }

                    OrderStatus orderStatus = Context.Entity.Resolve <OrderStatus>(statusItem["Code"]);
                    ((IEntity)orderStatus).Alias = statusItem.ID.ToString();
                    yield return(orderStatus);
                }
            }
            else
            {
                BusinessCatalogSettings settings = Context.Entity.GetConfiguration <BusinessCatalogSettings>();
                if (settings != null && !string.IsNullOrEmpty(settings.OrderStatusesLink))
                {
                    Item orderStatusesRoot = Sitecore.Context.ContentDatabase.SelectSingleItem(settings.OrderStatusesLink);
                    if (orderStatusesRoot != null)
                    {
                        foreach (Item statusItem in orderStatusesRoot.Children)
                        {
                            OrderStatus orderStatus = Context.Entity.Resolve <OrderStatus>(statusItem["Code"]);
                            ((IEntity)orderStatus).Alias = statusItem.ID.ToString();
                            yield return(orderStatus);
                        }
                    }
                }
            }
        }
Example #9
0
        private Sitecore.Data.Items.Item GetRootItem()
        {
            Assert.IsNotNull(this.ShopContext, "Unable to get order states. ShopContext cannot be null.");

            BusinessCatalogSettings settings = this.ShopContext.BusinessCatalogSettings;

            Assert.IsNotNull(settings, "Unable to get order states. BusinessCatalogSettings cannot be null.");

            string orderStatusesLink = settings.OrderStatusesLink;

            Assert.IsNotNull(orderStatusesLink, "Unable to get order states. OrderStatusesLink cannot be null.");

            Database database = this.ShopContext.InnerSite.ContentDatabase;

            Assert.IsNotNull(database, "Unable to get order states. Database cannot be null.");

            Sitecore.Data.Items.Item root = database.GetItem(settings.OrderStatusesLink);
            Assert.IsNotNull(root, "Unable to get order state. RootItem cannot be null.");

            return(root);
        }
Example #10
0
        public virtual ShopContext GetShopContext([NotNull] SiteContext siteContext)
        {
            Assert.ArgumentNotNull(siteContext, "siteContext");

            if (siteContext.Properties["EcommerceSiteSettings"] == null)
            {
                return(null);
            }

            BusinessCatalogSettings businessSettings = Context.Entity.GetConfiguration <BusinessCatalogSettings>();
            GeneralSettings         generalSettings  = Context.Entity.GetConfiguration <GeneralSettings>();

            ShopContext shopContext = new ShopContext(siteContext)
            {
                BusinessCatalogSettings = businessSettings,
                GeneralSettings         = generalSettings,
                Database = siteContext.Database
            };

            return(shopContext);
        }
        protected virtual Query BuildSearchQuery([NotNull] Item catalogItem)
        {
            Assert.ArgumentNotNull(catalogItem, "catalogItem");

            string searchTextBoxesText  = catalogItem[this.searchTextBoxesFieldName];
            string searchCheckListsText = catalogItem[this.searchChecklistsFieldName];

            BusinessCatalogSettings businessCatalogSettings = Context.Entity.GetConfiguration <BusinessCatalogSettings>();

            Assert.IsNotNull(businessCatalogSettings, this.GetType(), "Business Catalog settings not found.");

            Item productRepositoryRootItem = catalogItem.Database.GetItem(businessCatalogSettings.ProductsLink);

            Assert.IsNotNull(productRepositoryRootItem, "Product Repository Root Item is null.");

            Query query = new Query {
                SearchRoot = productRepositoryRootItem.ID.ToString()
            };

            if (!string.IsNullOrEmpty(searchTextBoxesText))
            {
                this.ParseSearchTextBoxes(searchTextBoxesText, ref query);
            }

            if (!string.IsNullOrEmpty(searchTextBoxesText) && !string.IsNullOrEmpty(searchCheckListsText))
            {
                query.AppendCondition(QueryCondition.And);
                query.AppendSubquery(this.ParseSearchCheckLists(searchCheckListsText));
            }
            else if (!string.IsNullOrEmpty(searchCheckListsText))
            {
                query.AppendSubquery(this.ParseSearchCheckLists(searchCheckListsText));
            }

            return(query);
        }
Example #12
0
        /// <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));
        }
Example #13
0
        /// <summary>
        /// Gets the payment link URL.
        /// </summary>
        /// <param name="fieldName">Name of the field.</param>
        /// <returns>The payment link URL.</returns>
        protected string ExtractPaymentLinkUrl(string fieldName)
        {
            Assert.IsNotNullOrEmpty(fieldName, "fieldName");

            if (Sitecore.Web.WebUtil.IsExternalUrl(fieldName))
            {
                return(fieldName);
            }

            BusinessCatalogSettings businessCatalogSettings = Context.Entity.GetConfiguration <BusinessCatalogSettings>();
            Item paymentsItem = Sitecore.Context.Database.GetItem(businessCatalogSettings.PaymentSystemsLink);

            Assert.IsNotNull(paymentsItem, "Payments item is null");
            Assert.IsNotNull(paymentsItem.Fields[fieldName], string.Concat("Payments item does not contains field: '", fieldName, "'"));

            LinkField linkField = paymentsItem.Fields[fieldName];

            Assert.IsNotNull(linkField, string.Concat("'", fieldName, "' is not a link field"));

            // If link is not internal just return url value.
            string externalUrl = linkField.Url;

            if (!linkField.LinkType.Equals("internal"))
            {
                return(externalUrl);
            }

            // If the site doesn't contains Business Catalog/Payments item under itself, Payment pages urls are wrong.
            // E.g.: Site path is: '/sitecore/content/Examples/Home';
            // Business Catalog path is: '/sitecore/content/Examples/Business Catalog';
            // Payment item path is: '/sitecore/content/Examples/Business Catalog/Payments';
            // In this case return page url is: '/Examples/Home/checkout/paymentreturnpage.aspx';
            // But should be: '/checkout/paymentreturnpage.aspx';
            Item targetPageItem = Sitecore.Context.Database.GetItem(linkField.TargetID);

            Assert.IsNotNull(targetPageItem, string.Concat("'", fieldName, "' contains invalid target item"));

            UrlOptions urlOptions = new UrlOptions
            {
                SiteResolving     = true,
                ShortenUrls       = true,
                AddAspxExtension  = true,
                EncodeNames       = true,
                LanguageEmbedding = LanguageEmbedding.AsNeeded
            };
            string relativeTargetPageUrl = LinkManager.GetItemUrl(targetPageItem, urlOptions);

            Assert.IsNotNull(HttpContext.Current.Request, "Http request is null");

            // If non regular http ports are used with instances on different ports like in Azure local emulation, HttpContext.Current.Request.Url.Port contains incorrect port.
            // This can be removed if/when issue is fixed by Microsoft.
            string host;
            var    port = HttpContext.Current.Request.Url.Port;

            if (port == 80 || port == 443)
            {
                host = HttpContext.Current.Request.Url.Host;
            }
            else
            {
                host = HttpContext.Current.Request.ServerVariables["HTTP_HOST"];
            }

            UrlString url = new UrlString
            {
                HostName = host,
                Path     = relativeTargetPageUrl
            };

            return(url.ToString());
        }