public static Shop AsWebModel(this Store store)
        {
            string[] paymentTypeIds = null;

            ICollection<PaymentMethod> paymentMethodModels = null;
            if (store.PaymentMethods != null)
            {
                paymentMethodModels = store.PaymentMethods.OrderBy(pm => pm.Priority).Select(paymentMethod => paymentMethod.AsWebModel()).ToList();
            }

            if (paymentMethodModels != null)
            {
                paymentTypeIds = GetPaymentMethodLogoIds(paymentMethodModels);
            }

            var shop = new Shop
                       {
                           StoreId = store.Id,
                           Name = store.Name,
                           Email = "*****@*****.**",
                           Description = store.Description,
                           Currency = store.DefaultCurrency,
                           Url = String.IsNullOrEmpty(store.Url) ? String.Format("~/{0}/{1}", store.DefaultLanguage, store.Id).ToAbsoluteUrl() : store.Url,
                           SimplifiedUrl = "~/".ToAbsoluteUrl().Trim('/'),
                           SecureUrl = store.SecureUrl,
                           DefaultUrl = store.SecureUrl ?? store.Url,
                           CustomerAccountsEnabled = true,
                           Domain = "localhost",
                           CustomerAccountsOptional = true,
                           EnabledPaymentTypes = paymentTypeIds,
                           DefaultLanguage = store.DefaultLanguage,
                           State = store.StoreState,
                           Catalog = store.Catalog,
                           PaymentMethods = paymentMethodModels,
                           Languages = store.Languages,
                           Currencies = store.Currencies
                       };

            if (store.Seo != null)
            {
                shop.Keywords = store.Seo.Select(k => k.AsWebModel());
            }

            if (store.Settings != null && store.Settings.Any())
            {
                var fieldsCollection = new MetafieldsCollection("global", store.Settings);
                shop.Metafields = new MetaFieldNamespacesCollection(new[] { fieldsCollection });

                if(fieldsCollection.ContainsKey("enableQuotes"))
                {
                    shop.QuotesEnabled = (bool)fieldsCollection["enableQuotes"];
                }
            }

            return shop;
        }
Example #2
0
        public static Shop AsWebModel(this Store store, ICollection<PaymentMethod> acceptedPaymentMethods)
        {
            string[] paymentTypeIds = null;
            if (acceptedPaymentMethods != null)
            {
                paymentTypeIds = GetPaymentMethodLogoIds(acceptedPaymentMethods);
            }

            var shop = new Shop
                       {
                           StoreId = store.Id,
                           Name = store.Name,
                           Email = "*****@*****.**",
                           Description = store.Description,
                           Currency = store.DefaultCurrency,
                           Url = store.Url ?? String.Format("~/{0}/{1}", store.DefaultLanguage, store.Id).ToAbsoluteUrl(),
                           SecureUrl = store.SecureUrl,
                           DefaultUrl = store.SecureUrl ?? store.Url,
                           CustomerAccountsEnabled = true,
                           Domain = "localhost",
                           CustomerAccountsOptional = true,
                           EnabledPaymentTypes = paymentTypeIds,
                           DefaultLanguage = store.DefaultLanguage,
                           State = store.StoreState,
                           Catalog = store.Catalog,
                           Languages = store.Languages,
                           Currencies = store.Currencies
                       };

            if (store.Seo != null)
            {
                shop.Keywords = store.Seo.Select(k => k.AsWebModel());
            }

            if (store.Settings != null && store.Settings.Any())
            {
                var fieldsCollection = new MetafieldsCollection("global", store.Settings);
                shop.Metafields = new MetaFieldNamespacesCollection(new[] { fieldsCollection });
            }

            return shop;
        }
Example #3
0
        private string ResolveTheme(Shop shop, IOwinContext context)
        {
            #region Preview theme functionality
            var previewTheme = context.Request.Query["previewtheme"];
            var previewThemeCookie = PreviewThemeCookie + shop.StoreId;
            if (!String.IsNullOrEmpty(previewTheme)) // save in cookie and return
            {
                context.Response.Cookies.Append(previewThemeCookie, previewTheme/*, new CookieOptions() { Expires = DateTime.MinValue}*/);
            }
            else
            {
                previewTheme = context.Request.Cookies[previewThemeCookie];
            }

            if (!String.IsNullOrEmpty(previewTheme))
                return previewTheme;
            #endregion

            var theme = ConfigurationManager.AppSettings["Theme"];
            if (shop.Metafields != null)
            {
                var shopMetaFields = shop.Metafields["global"];
                if (shopMetaFields != null)
                {
                    object themeObject;
                    if (shop.Metafields["global"].TryGetValue("defaultThemeName", out themeObject))
                    {
                        return themeObject.ToString();
                    }
                }
            }

            return theme;
        }
Example #4
0
        protected virtual string GetStoreCurrency(IOwinContext context, Shop store)
        {
            var currency = context.Request.Query.Get("currency");

            if (String.IsNullOrEmpty(currency))
            {
                currency = context.Request.Cookies[CurrencyCookie];
            }

            if (String.IsNullOrEmpty(currency) ||
                !String.IsNullOrEmpty(currency) && !store.Currencies.Any(c => c.Equals(currency, StringComparison.OrdinalIgnoreCase)))
            {
                currency = store.Currency;
            }

            if (String.IsNullOrEmpty(currency))
            {
                currency = "USD";
            }

            return currency;
        }