示例#1
0
        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);
        }
示例#2
0
        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;
        }
示例#3
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;
        }
示例#4
0
        public static Shop AsWebModel(this Store store)
        {
            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      = new[] { "amex", "paypal", "google", "bitcoin" },
                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);
        }
示例#5
0
        public static Product AsWebModel(
            this Data.Product product, IEnumerable<Data.Price> prices,
            IEnumerable<Data.Marketing.PromotionReward> rewards, IEnumerable<Data.InventoryInfo> inventories, Collection collection = null)
        {
            var productModel = new Product();

            var pathTemplate = VirtualPathUtility.ToAbsolute("~/products/{0}");
            var description = product.EditorialReviews != null ?
                product.EditorialReviews.FirstOrDefault(er => er.ReviewType != null && er.ReviewType.Equals("quickreview", StringComparison.OrdinalIgnoreCase)) : null;

            var fieldsCollection = new MetafieldsCollection("global", product.Properties);
            var options = GetOptions(product.VariationProperties);

            var keywords = product.Seo != null ? product.Seo.Select(k => k.AsWebModel()) : null;

            var primaryImage = product.PrimaryImage ?? product.Images.FirstOrDefault();

            productModel.Description = description != null ? description.Content : null;
            productModel.Handle = product.Code;
            productModel.Id = product.Id;
            productModel.Images = new ItemCollection<Image>(product.Images.Select(i => i.AsWebModel(product.Name, product.Id)));
            productModel.FeaturedImage = primaryImage.AsWebModel(primaryImage.Name, product.Id);
            productModel.Keywords = keywords;
            productModel.Metafields = new MetaFieldNamespacesCollection(new[] { fieldsCollection });
            productModel.Options = options;
            productModel.Tags = null; // TODO
            productModel.TemplateSuffix = null; // TODO
            productModel.Title = product.Name;
            productModel.Type = product.ProductType;
            productModel.Url = string.Format(pathTemplate, product.Code);
            productModel.Vendor = fieldsCollection.ContainsKey("brand") ? fieldsCollection["brand"] as string : null;

            // form url
            // "/products/code" or "/en-us/store/collection/outline" 

            // specify SEO based url
            var urlHelper = GetUrlHelper();
            var url = String.Empty;
            if (urlHelper != null && productModel.Keywords != null && productModel.Keywords.Any())
            {
                var keyword = productModel.Keywords.SeoKeyword(Thread.CurrentThread.CurrentUICulture.Name);
                if (keyword != null)
                {
                    url = urlHelper.ItemUrl(keyword.Keyword, collection == null ? "" : collection.Outline);
                    if (!String.IsNullOrEmpty(url))
                        productModel.Url = url;
                }
            }

            if (String.IsNullOrEmpty(url) && urlHelper != null)
            {
                url = urlHelper.ItemUrl(productModel.Handle, collection == null ? "" : collection.Outline);
                if (!String.IsNullOrEmpty(url))
                    productModel.Url = url;
            }

            var productRewards = rewards.Where(r => r.RewardType == "CatalogItemAmountReward" && r.ProductId == product.Id);

            if (product.Variations != null)
            {
                foreach (var variation in product.Variations)
                {
                    var price = prices.FirstOrDefault(p => p.ProductId == variation.Id);

                    var variantInventory = inventories != null ?
                        inventories.FirstOrDefault(i => i.ProductId == variation.Id) : null;

                    productModel.Variants.Add(variation.AsVariantWebModel(price, options, productRewards, variantInventory));
                }
            }

            var productPrice = prices.FirstOrDefault(p => p.ProductId == product.Id);

            var productInventory = inventories != null ?
                inventories.FirstOrDefault(i => i.ProductId == product.Id) : null;

            var variant = product.AsVariantWebModel(productPrice, options, productRewards, productInventory);

            variant.Title = "Default Title";

            productModel.Variants.Add(variant);

            return productModel;
        }
        public static Product AsWebModel(
            this Data.Product product, IEnumerable <Data.Price> prices,
            IEnumerable <Data.Marketing.PromotionReward> rewards, IEnumerable <Data.InventoryInfo> inventories, Collection collection = null)
        {
            var productModel = new Product();

            var pathTemplate = VirtualPathUtility.ToAbsolute("~/products/{0}");
            var description  = product.EditorialReviews != null?
                               product.EditorialReviews.FirstOrDefault(er => er.ReviewType != null && er.ReviewType.Equals("quickreview", StringComparison.OrdinalIgnoreCase)) : null;

            var fieldsCollection = new MetafieldsCollection("global", product.Properties);
            var options          = GetOptions(product.VariationProperties);

            var keywords = product.Seo != null?product.Seo.Select(k => k.AsWebModel()) : null;

            productModel.Description    = description != null ? description.Content : null;
            productModel.Handle         = product.Code;
            productModel.Id             = product.Id;
            productModel.Images         = new ItemCollection <Image>(product.Images.Select(i => i.AsWebModel(product.Name, product.Id)));
            productModel.Keywords       = keywords;
            productModel.Metafields     = new MetaFieldNamespacesCollection(new[] { fieldsCollection });
            productModel.Options        = options;
            productModel.Tags           = null; // TODO
            productModel.TemplateSuffix = null; // TODO
            productModel.Title          = product.Name;
            productModel.Type           = product.ProductType;
            productModel.Url            = string.Format(pathTemplate, product.Code);
            productModel.Vendor         = fieldsCollection.ContainsKey("brand") ? fieldsCollection["brand"] as string : null;

            // form url
            // "/products/code" or "/en-us/store/collection/outline"

            // specify SEO based url
            var urlHelper = GetUrlHelper();
            var url       = String.Empty;

            if (urlHelper != null && productModel.Keywords != null && productModel.Keywords.Any())
            {
                var keyword = productModel.Keywords.SeoKeyword(Thread.CurrentThread.CurrentUICulture.Name);
                if (keyword != null)
                {
                    url = urlHelper.ItemUrl(keyword.Keyword, collection == null ? "" : collection.Outline);
                    if (!String.IsNullOrEmpty(url))
                    {
                        productModel.Url = url;
                    }
                }
            }

            if (String.IsNullOrEmpty(url) && urlHelper != null)
            {
                url = urlHelper.ItemUrl(productModel.Handle, collection == null ? "" : collection.Outline);
                if (!String.IsNullOrEmpty(url))
                {
                    productModel.Url = url;
                }
            }

            var productRewards = rewards.Where(r => r.RewardType == "CatalogItemAmountReward" && r.ProductId == product.Id);

            if (product.Variations != null)
            {
                foreach (var variation in product.Variations)
                {
                    var price = prices.FirstOrDefault(p => p.ProductId == variation.Id);

                    var variantInventory = inventories != null?
                                           inventories.FirstOrDefault(i => i.ProductId == variation.Id) : null;

                    productModel.Variants.Add(variation.AsVariantWebModel(price, options, productRewards, variantInventory));
                }
            }

            var productPrice = prices.FirstOrDefault(p => p.ProductId == product.Id);

            var productInventory = inventories != null?
                                   inventories.FirstOrDefault(i => i.ProductId == product.Id) : null;

            var variant = product.AsVariantWebModel(productPrice, options, productRewards, productInventory);

            productModel.Variants.Add(variant);

            return(productModel);
        }