public StorefrontHomeController(WorkContext context, ICatalogSearchService catalogSearchService, ICatalogModuleApi catalogModuleApi, ISearchModuleApi searchApi)
 {
     _catalogSearchService = catalogSearchService;
     _workContext = context;
     _catalogModuleApi = catalogModuleApi;
     _searchApi = searchApi;
 }
Ejemplo n.º 2
0
        public static Shop ToShopifyModel(this Store store, StorefrontModel.WorkContext workContext)
        {
            Shop result = new Shop();

            if (workContext.Categories != null)
            {
                result.Collections = new MutablePagedList <Collection>((pageNumber, pageSize, sortInfos) =>
                {
                    workContext.Categories.Slice(pageNumber, pageSize, sortInfos);
                    return(new StaticPagedList <Collection>(workContext.Categories.Select(x => x.ToShopifyModel(workContext)), workContext.Categories));
                });
            }
            result.InjectFrom <NullableAndEnumValueInjecter>(store);
            result.CustomerAccountsEnabled  = true;
            result.CustomerAccountsOptional = true;
            result.Currency                = workContext.CurrentCurrency.Code;
            result.Description             = store.Description;
            result.Domain                  = store.Url;
            result.Email                   = store.Email;
            result.MoneyFormat             = "";
            result.MoneyWithCurrencyFormat = "";
            result.Url        = store.Url ?? "~/";
            result.Currencies = store.Currencies.Select(x => x.Code).ToArray();
            result.Languages  = store.Languages.Select(x => x.ToShopifyModel()).ToArray();
            result.Catalog    = store.Catalog;
            result.Status     = store.StoreState.ToString();
            result.Metafields = new MetaFieldNamespacesCollection(new[] { new MetafieldsCollection("dynamic_properties", workContext.CurrentLanguage, store.DynamicProperties), new MetafieldsCollection("settings", store.Settings) });

            return(result);
        }
 public ApiCommonController(WorkContext workContext, IStorefrontUrlBuilder urlBuilder, IStoreModuleApi storeModuleApi)
     : base(workContext, urlBuilder)
 {
     _storeModuleApi = storeModuleApi;
     _countriesWithoutRegions = workContext.AllCountries
      .Select(c => new Country { Name = c.Name, Code2 = c.Code2, Code3 = c.Code3, RegionType = c.RegionType })
      .ToArray();
 }
 public CatalogSearchServiceImpl(WorkContext workContext, ICatalogModuleApi catalogModuleApi, IPricingModuleApi pricingModuleApi, IInventoryModuleApi inventoryModuleApi, ISearchModuleApi searchApi)
 {
     _workContext = workContext;
     _catalogModuleApi = catalogModuleApi;
     _pricingModuleApi = pricingModuleApi;
     _inventoryModuleApi = inventoryModuleApi;
     _searchApi = searchApi;
 }
Ejemplo n.º 5
0
 public MarketingController(WorkContext workContext, IStorefrontUrlBuilder urlBuilder, IMarketingService marketingService,
     IPromotionEvaluator promotionEvaluator, IPricingModuleApi pricingApi)
     : base(workContext, urlBuilder)
 {
     _marketingService = marketingService;
     _pricingApi = pricingApi;
     _promotionEvaluator = promotionEvaluator;
 }
 public ShopifyCompatibilityController(WorkContext workContext, IStorefrontUrlBuilder urlBuilder, ICartBuilder cartBuilder, ICatalogSearchService catalogService)
     : base(workContext, urlBuilder)
 {
     _workContext = workContext;
     _urlBuilder = urlBuilder;
     _cartBuilder = cartBuilder;
     _catalogService = catalogService;
 }
 public static VirtoCommerceStoreModuleWebModelSendDynamicNotificationRequest ToServiceModel(this ContactUsForm contactUsForm, WorkContext workContext)
 {
     var retVal = new VirtoCommerceStoreModuleWebModelSendDynamicNotificationRequest();
     retVal.Language = workContext.CurrentLanguage.CultureName;
     retVal.StoreId = workContext.CurrentStore.Id;
     retVal.Type = contactUsForm.FormType;
     retVal.Fields = contactUsForm.Contact.ToDictionary(x => x.Key, x => (object)((string[])x.Value).FirstOrDefault());
     return retVal;
 }
 public ApiQuoteRequestController(WorkContext workContext, IStorefrontUrlBuilder urlBuilder, ICartBuilder cartBuilder,
     IQuoteModuleApi quoteApi, IQuoteRequestBuilder quoteRequestBuilder, ICatalogSearchService catalogSearchService)
     : base(workContext, urlBuilder)
 {
     _quoteApi = quoteApi;
     _quoteRequestBuilder = quoteRequestBuilder;
     _cartBuilder = cartBuilder;
     _catalogSearchService = catalogSearchService;
 }
Ejemplo n.º 9
0
        public virtual Customer ToLiquidCustomer(CustomerInfo customer, StorefrontModel.WorkContext workContext, IStorefrontUrlBuilder urlBuilder)
        {
            var factory = ServiceLocator.Current.GetInstance <ShopifyModelFactory>();
            var result  = factory.CreateCustomer();

            result.InjectFrom <NullableAndEnumValueInjecter>(customer);
            result.Name = customer.FullName;
            if (customer.DefaultAddress != null)
            {
                result.DefaultAddress = ToLiquidAddress(customer.DefaultAddress);
            }
            if (customer.DefaultBillingAddress != null)
            {
                result.DefaultBillingAddress = ToLiquidAddress(customer.DefaultBillingAddress);
            }
            if (customer.DefaultShippingAddress != null)
            {
                result.DefaultShippingAddress = ToLiquidAddress(customer.DefaultShippingAddress);
            }

            if (customer.Tags != null)
            {
                result.Tags = customer.Tags.ToList();
            }

            if (customer.Addresses != null)
            {
                var addresses = customer.Addresses.Select(a => ToLiquidAddress(a)).ToList();
                result.Addresses = new MutablePagedList <Address>(addresses);
            }

            if (customer.Orders != null)
            {
                result.Orders = new MutablePagedList <Order>((pageNumber, pageSize, sortInfos) =>
                {
                    customer.Orders.Slice(pageNumber, pageSize, sortInfos);
                    return(new StaticPagedList <Order>(customer.Orders.Select(x => ToLiquidOrder(x, workContext.CurrentLanguage, urlBuilder)), customer.Orders));
                }, customer.Orders.PageNumber, customer.Orders.PageSize);
            }

            if (customer.QuoteRequests != null)
            {
                result.QuoteRequests = new MutablePagedList <QuoteRequest>((pageNumber, pageSize, sortInfos) =>
                {
                    customer.QuoteRequests.Slice(pageNumber, pageSize, sortInfos);
                    return(new StaticPagedList <QuoteRequest>(customer.QuoteRequests.Select(x => ToLiquidQuoteRequest(x)), customer.QuoteRequests));
                }, customer.QuoteRequests.PageNumber, customer.QuoteRequests.PageSize);
            }

            if (customer.DynamicProperties != null)
            {
                result.Metafields = new MetaFieldNamespacesCollection(new[] { new MetafieldsCollection("dynamic_properties", workContext.CurrentLanguage, customer.DynamicProperties) });
            }
            return(result);
        }
Ejemplo n.º 10
0
 public ApiCartController(WorkContext workContext, ICatalogSearchService catalogSearchService, ICartBuilder cartBuilder,
                          IOrderModuleApi orderApi, ICartValidator cartValidator, IStorefrontUrlBuilder urlBuilder,
                          IEventPublisher<OrderPlacedEvent> orderPlacedEventPublisher)
     : base(workContext, urlBuilder)
 {
     _cartBuilder = cartBuilder;
     _orderApi = orderApi;
     _cartValidator = cartValidator;
     _catalogSearchService = catalogSearchService;
     _orderPlacedEventPublisher = orderPlacedEventPublisher;
 }
Ejemplo n.º 11
0
 public AccountController(WorkContext workContext, IStorefrontUrlBuilder urlBuilder, ICommerceCoreModuleApi commerceCoreApi,
     IAuthenticationManager authenticationManager, IVirtoCommercePlatformApi platformApi,
     ICustomerService customerService, IOrderModuleApi orderApi, IEventPublisher<UserLoginEvent> userLoginEventPublisher)
     : base(workContext, urlBuilder)
 {
     _commerceCoreApi = commerceCoreApi;
     _customerService = customerService;
     _authenticationManager = authenticationManager;
     _platformApi = platformApi;
     _orderApi = orderApi;
     _userLoginEventPublisher = userLoginEventPublisher;
 }
Ejemplo n.º 12
0
 public AccountController(WorkContext workContext, IStorefrontUrlBuilder urlBuilder, ICommerceCoreModuleApi commerceCoreApi,
     ICustomerManagementModuleApi customerApi, IAuthenticationManager authenticationManager, IVirtoCommercePlatformApi platformApi,
     IOrderModuleApi orderApi, ICartBuilder cartBuilder)
     : base(workContext, urlBuilder)
 {
     _commerceCoreApi = commerceCoreApi;
     _customerApi = customerApi;
     _authenticationManager = authenticationManager;
     _platformApi = platformApi;
     _orderApi = orderApi;
     _cartBuilder = cartBuilder;
 }
Ejemplo n.º 13
0
        public static Customer ToShopifyModel(this CustomerInfo customer, StorefrontModel.WorkContext workContext, IStorefrontUrlBuilder urlBuilder)
        {
            var result = new Customer();

            result.InjectFrom <NullableAndEnumValueInjecter>(customer);
            result.Name                   = customer.FullName;
            result.DefaultAddress         = customer.DefaultAddress.ToShopifyModel();
            result.DefaultBillingAddress  = customer.DefaultBillingAddress.ToShopifyModel();
            result.DefaultShippingAddress = customer.DefaultShippingAddress.ToShopifyModel();

            if (customer.Tags != null)
            {
                result.Tags = customer.Tags.ToList();
            }

            if (customer.Addresses != null)
            {
                var addresses = customer.Addresses.Select(a => a.ToShopifyModel()).ToList();

                // Add virtual ID to each address
                var id = 1;
                foreach (var address in addresses)
                {
                    address.Id = id.ToString(CultureInfo.InvariantCulture);
                    id++;
                }
                result.Addresses = new MutablePagedList <Address>(addresses);
            }

            if (customer.Orders != null)
            {
                result.Orders = new MutablePagedList <Order>((pageNumber, pageSize, sortInfos) =>
                {
                    customer.Orders.Slice(pageNumber, pageSize, sortInfos);
                    return(new StaticPagedList <Order>(customer.Orders.Select(x => x.ToShopifyModel(urlBuilder)), customer.Orders));
                }, customer.Orders.PageNumber, customer.Orders.PageSize);
            }

            if (customer.QuoteRequests != null)
            {
                result.QuoteRequests = new MutablePagedList <QuoteRequest>((pageNumber, pageSize, sortInfos) =>
                {
                    customer.QuoteRequests.Slice(pageNumber, pageSize, sortInfos);
                    return(new StaticPagedList <QuoteRequest>(customer.QuoteRequests.Select(x => x.ToShopifyModel()), customer.QuoteRequests));
                }, customer.QuoteRequests.PageNumber, customer.QuoteRequests.PageSize);
            }

            if (customer.DynamicProperties != null)
            {
                result.Metafields = new MetaFieldNamespacesCollection(new[] { new MetafieldsCollection("dynamic_properties", workContext.CurrentLanguage, customer.DynamicProperties) });
            }
            return(result);
        }
Ejemplo n.º 14
0
 public CartController(WorkContext workContext, IShoppingCartModuleApi cartApi, IOrderModuleApi orderApi, IStorefrontUrlBuilder urlBuilder,
                       ICartBuilder cartBuilder, ICatalogSearchService catalogService, IMarketingModuleApi marketingApi, ICommerceCoreModuleApi commerceApi,
                       ICustomerManagementModuleApi customerApi)
     : base(workContext, urlBuilder)
 {
     _cartBuilder = cartBuilder;
     _catalogService = catalogService;
     _cartApi = cartApi;
     _orderApi = orderApi;
     _marketingApi = marketingApi;
     _commerceApi = commerceApi;
     _customerApi = customerApi;
 }
Ejemplo n.º 15
0
        public static Customer ToShopifyModel(this CustomerInfo customer, StorefrontModel.WorkContext workContext, StorefrontModel.Common.IStorefrontUrlBuilder urlBuilder)
        {
            var result = new Customer();

            result.InjectFrom <StorefrontModel.Common.NullableAndEnumValueInjecter>(customer);
            result.Name                   = customer.FullName;
            result.DefaultAddress         = customer.DefaultAddress.ToShopifyModel();
            result.DefaultBillingAddress  = customer.DefaultBillingAddress.ToShopifyModel();
            result.DefaultShippingAddress = customer.DefaultShippingAddress.ToShopifyModel();

            if (customer.Tags != null)
            {
                result.Tags = customer.Tags.ToList();
            }

            if (customer.Addresses != null)
            {
                var addresses = customer.Addresses.Select(a => a.ToShopifyModel()).ToList();

                // Add virtual ID to each address
                var id = 1;
                foreach (var address in addresses)
                {
                    address.Id = id.ToString(CultureInfo.InvariantCulture);
                    id++;
                }
                result.Addresses      = new MutablePagedList <Address>(addresses, 1, 20);
                result.AddressesCount = addresses.Count;
            }

            if (customer.Orders != null)
            {
                result.Orders = new MutablePagedList <Order>((pageNumber, pageSize) =>
                {
                    customer.Orders.Slice(pageNumber, pageSize);
                    return(new StaticPagedList <Order>(customer.Orders.Select(x => x.ToShopifyModel(urlBuilder)), customer.Orders));
                }, customer.Orders.PageNumber, customer.Orders.PageSize);
            }

            if (customer.QuoteRequests != null)
            {
                result.QuoteRequests = new MutablePagedList <QuoteRequest>((pageNumber, pageSize) =>
                {
                    customer.QuoteRequests.Slice(pageNumber, pageSize);
                    return(new StaticPagedList <QuoteRequest>(customer.QuoteRequests.Select(x => x.ToShopifyModel()), customer.QuoteRequests));
                }, customer.QuoteRequests.PageNumber, customer.QuoteRequests.PageSize);
            }

            return(result);
        }
Ejemplo n.º 16
0
 public CartController(WorkContext workContext, IOrderModuleApi orderApi, IStorefrontUrlBuilder urlBuilder,
                       ICartBuilder cartBuilder, ICatalogSearchService catalogService, IMarketingModuleApi marketingApi, ICommerceCoreModuleApi commerceApi,
                       ICustomerManagementModuleApi customerApi, ICartValidator cartValidator, IEventPublisher<OrderPlacedEvent> orderPlacedEventPublisher)
     : base(workContext, urlBuilder)
 {
     _cartBuilder = cartBuilder;
     _catalogService = catalogService;
     _orderApi = orderApi;
     _marketingApi = marketingApi;
     _commerceApi = commerceApi;
     _customerApi = customerApi;
     _cartValidator = cartValidator;
     _orderPlacedEventPublisher = orderPlacedEventPublisher;
 }
Ejemplo n.º 17
0
        public static Customer ToShopifyModel(this CustomerInfo customer, StorefrontModel.WorkContext workContext, StorefrontModel.Common.IStorefrontUrlBuilder urlBuilder)
        {
            var result = new Customer();

            result.InjectFrom <StorefrontModel.Common.NullableAndEnumValueInjecter>(customer);
            result.Name                   = customer.FullName;
            result.DefaultAddress         = customer.DefaultAddress.ToShopifyModel();
            result.DefaultBillingAddress  = customer.DefaultBillingAddress.ToShopifyModel();
            result.DefaultShippingAddress = customer.DefaultShippingAddress.ToShopifyModel();

            if (customer.Tags != null)
            {
                result.Tags = customer.Tags.ToList();
            }

            if (customer.Addresses != null)
            {
                var addresses = customer.Addresses.Select(a => a.ToShopifyModel()).ToList();

                // Add virtual ID to each address
                var id = 1;
                foreach (var address in addresses)
                {
                    address.Id = id.ToString(CultureInfo.InvariantCulture);
                    id++;
                }
                //TODO: make customer.Addresses as IPagedList
                result.Addresses      = new StorefrontModel.Common.StorefrontPagedList <Address>(addresses, 1, 10, addresses.Count, page => workContext.RequestUrl.SetQueryParameter("page", page.ToString()).ToString());
                result.AddressesCount = addresses.Count;
            }

            if (customer.Orders != null)
            {
                var orders = customer.Orders.Select(o => o.ToShopifyModel(urlBuilder)).ToList();
                result.Orders      = new StorefrontModel.Common.StorefrontPagedList <Order>(orders, customer.Orders, customer.Orders.GetPageUrl);
                result.OrdersCount = orders.Count;
            }

            if (customer.QuoteRequests != null)
            {
                var quoteRequests = customer.QuoteRequests.Select(qr => qr.ToShopifyModel()).ToList();
                result.QuoteRequests = new StorefrontModel.Common.StorefrontPagedList <QuoteRequest>(quoteRequests, customer.QuoteRequests, customer.QuoteRequests.GetPageUrl);
            }

            return(result);
        }
Ejemplo n.º 18
0
        protected WorkContext GetTestWorkContext()
        {
            var apiClientCfg = new Client.Client.Configuration(GetApiClient());
            var storeApi = new StoreModuleApi(apiClientCfg);
            var commerceApi = new CommerceCoreModuleApi(apiClientCfg);
            var allStores = storeApi.StoreModuleGetStores().Select(x => x.ToWebModel());
            var defautStore = allStores.FirstOrDefault(x => string.Equals(x.Id, "Electronics", StringComparison.InvariantCultureIgnoreCase));
            var currencies = commerceApi.CommerceGetAllCurrencies().Select(x => x.ToWebModel(defautStore.DefaultLanguage));
            defautStore.SyncCurrencies(currencies, defautStore.DefaultLanguage);

            var retVal = new WorkContext
            {
                AllCurrencies = defautStore.Currencies,
                CurrentLanguage = defautStore.DefaultLanguage,
                CurrentCurrency = defautStore.DefaultCurrency,
                CurrentStore = defautStore
            };
            return retVal;
        }
 public static VirtoCommerceDomainCatalogModelSearchCriteria ToServiceModel(this CatalogSearchCriteria criteria, WorkContext workContext)
 {
     var result = new VirtoCommerceDomainCatalogModelSearchCriteria
     {
         StoreId = workContext.CurrentStore.Id,
         Keyword = criteria.Keyword,
         ResponseGroup = criteria.ResponseGroup.ToString(),
         SearchInChildren = criteria.SearchInChildren,
         CategoryId = criteria.CategoryId,
         CatalogId = criteria.CatalogId,
         Currency = criteria.Currency == null ?  workContext.CurrentCurrency.Code : criteria.Currency.Code,
         HideDirectLinkedCategories = true,
         Terms = criteria.Terms.ToStrings(),
         PricelistIds = workContext.CurrentPricelists.Where(p => p.Currency == workContext.CurrentCurrency.Code).Select(p => p.Id).ToList(),
         Skip = criteria.Start,
         Take = criteria.PageSize,
         Sort = criteria.SortBy
     };
     return result;
 }
        public static VirtoCommerceDomainPricingModelPriceEvaluationContext ToServiceModel(this IEnumerable<Product> products, WorkContext workContext)
        {
            if(products == null)
            {
                throw new ArgumentNullException("products");
            }
            //Evaluate products prices
            var retVal = new VirtoCommerceDomainPricingModelPriceEvaluationContext
            {
                ProductIds = products.Select(p => p.Id).ToList(),
                PricelistIds = workContext.CurrentPricelists.Select(p => p.Id).ToList(),
                CatalogId = workContext.CurrentStore.Catalog,
                CustomerId = workContext.CurrentCustomer.Id,
                Language = workContext.CurrentLanguage.CultureName,
                CertainDate = workContext.StorefrontUtcNow,
                StoreId = workContext.CurrentStore.Id
            };
            return retVal;

        }
Ejemplo n.º 21
0
        public virtual Shop ToLiquidShop(Store store, storefrontModel.WorkContext workContext)
        {
            var result = new Shop();

            result.Catalog             = store.Catalog;
            result.Id                  = store.Id;
            result.Name                = store.Name;
            result.SubscriptionEnabled = store.SubscriptionEnabled;

            result.CustomerAccountsEnabled  = true;
            result.CustomerAccountsOptional = true;
            result.Currency                = workContext.CurrentCurrency.Code;
            result.Description             = store.Description;
            result.Domain                  = store.Url;
            result.Email                   = store.Email;
            result.MoneyFormat             = "";
            result.MoneyWithCurrencyFormat = "";
            result.Url        = store.Url ?? "~/";
            result.Currencies = workContext.AllCurrencies.Select(x => x.Code).ToArray();
            result.Languages  = store.Languages.Select(x => x.ToShopifyModel()).ToArray();
            result.Catalog    = store.Catalog;
            result.Status     = store.StoreState.ToString();

            result.Metafields = new MetaFieldNamespacesCollection(new[]
            {
                new MetafieldsCollection("dynamic_properties", workContext.CurrentLanguage, store.DynamicProperties),
                new MetafieldsCollection("settings", store.Settings)
            });

            if (workContext.Categories != null)
            {
                result.Collections = new MutablePagedList <Collection>((pageNumber, pageSize, sortInfos) =>
                {
                    workContext.Categories.Slice(pageNumber, pageSize, sortInfos);
                    return(new StaticPagedList <Collection>(workContext.Categories.Select(x => ToLiquidCollection(x, workContext)), workContext.Categories));
                }, 1, workContext.Categories.PageSize);
            }

            return(result);
        }
Ejemplo n.º 22
0
        public static Shop ToShopifyModel(this StorefrontModel.Store store, StorefrontModel.WorkContext workContext)
        {
            Shop result = new Shop();

            result.InjectFrom <StorefrontModel.Common.NullableAndEnumValueInjecter>(store);
            result.CustomerAccountsEnabled  = true;
            result.CustomerAccountsOptional = true;
            result.Currency                = workContext.CurrentCurrency.Code;
            result.CollectionsCount        = "0";
            result.Description             = store.Description;
            result.Domain                  = store.Url;
            result.Email                   = store.Email;
            result.MoneyFormat             = "";
            result.MoneyWithCurrencyFormat = "";
            result.Url        = store.Url ?? "~/";
            result.Currencies = store.Currencies.Select(x => x.Code).ToArray();
            result.Languages  = store.Languages.Select(x => x.ToShopifyModel()).ToArray();
            result.Catalog    = store.Catalog;
            //result.Metafields = new MetaFieldNamespacesCollection(new[] { new MetafieldsCollection("global", store.DynamicProperties) });

            return(result);
        }
Ejemplo n.º 23
0
        public static ShopifyThemeWorkContext ToShopifyModel(this storefrontModel.WorkContext workContext, IStorefrontUrlBuilder urlBuilder)
        {
            var converter = new ShopifyModelConverter();

            return(converter.ToLiquidContext(workContext, urlBuilder));
        }
        public static ShopifyThemeWorkContext ToShopifyModel(this storefrontModel.WorkContext workContext, IStorefrontUrlBuilder urlBuilder)
        {
            var result = new ShopifyThemeWorkContext();

            result.CurrentPage       = 1;
            result.CountryOptionTags = string.Join("\r\n", workContext.AllCountries.OrderBy(c => c.Name).Select(c => c.ToOptionTag()));
            result.PageDescription   = workContext.CurrentPageSeo != null ? workContext.CurrentPageSeo.MetaDescription : string.Empty;
            result.PageTitle         = workContext.CurrentPageSeo != null ? workContext.CurrentPageSeo.Title : string.Empty;
            result.Shop = workContext.CurrentStore != null?workContext.CurrentStore.ToShopifyModel(workContext) : null;

            result.Cart = workContext.CurrentCart != null?workContext.CurrentCart.ToShopifyModel(workContext) : null;

            result.Product = workContext.CurrentProduct != null?workContext.CurrentProduct.ToShopifyModel(workContext) : null;

            result.Customer  = workContext.CurrentCustomer != null && workContext.CurrentCustomer.IsRegisteredUser ? workContext.CurrentCustomer.ToShopifyModel(workContext, urlBuilder) : null;
            result.AllStores = workContext.AllStores.Select(x => x.ToShopifyModel(workContext)).ToArray();

            result.CurrentCurrency = workContext.CurrentCurrency != null?workContext.CurrentCurrency.ToShopifyModel() : null;

            result.CurrentLanguage = workContext.CurrentLanguage != null?workContext.CurrentLanguage.ToShopifyModel() : null;

            if (workContext.CurrentProduct != null && workContext.CurrentProduct.Category != null)
            {
                result.Collection = workContext.CurrentProduct.Category.ToShopifyModel(workContext);
            }

            if (workContext.CurrentCatalogSearchCriteria != null && workContext.CurrentCatalogSearchCriteria.Terms.Any())
            {
                result.CurrentTags =
                    new TagCollection(
                        workContext.CurrentCatalogSearchCriteria.Terms.Select(t => t.ToShopifyModel()).ToList());
            }

            var searchResult = workContext.CurrentCatalogSearchResult;

            if (searchResult != null)
            {
                result.Collection = searchResult.ToShopifyModel(workContext);

                if (searchResult.Categories != null)
                {
                    result.Collections = new Collections(searchResult.Categories.Select(x => x.ToShopifyModel(workContext)));
                }
            }

            if (workContext.CurrentLinkLists != null)
            {
                result.Linklists = new Linklists(workContext.CurrentLinkLists.Select(x => x.ToShopifyModel(workContext)));
            }

            if (workContext.CurrentOrder != null)
            {
                result.Order = workContext.CurrentOrder.ToShopifyModel(urlBuilder);
            }

            if (workContext.CurrentQuoteRequest != null)
            {
                result.QuoteRequest = workContext.CurrentQuoteRequest.ToShopifyModel();
            }

            result.PaymentFormHtml = workContext.PaymentFormHtml;

            if (workContext.CurrentPage != null)
            {
                result.Page = workContext.CurrentPage.ToShopifyModel();
            }

            if (workContext.CurrentBlog != null)
            {
                result.Blog = workContext.CurrentBlog.ToShopifyModel();
            }

            if (workContext.CurrentBlogArticle != null)
            {
                result.Article = workContext.CurrentBlogArticle.ToShopifyModel();
            }

            if (workContext.ContactUsForm != null)
            {
                result.Form = workContext.ContactUsForm.ToShopifyModel();
            }

            if (workContext.Login != null)
            {
                result.Form = workContext.Login.ToShopifyModel();
            }

            if (workContext.StorefrontNotification != null)
            {
                result.Notification = workContext.StorefrontNotification.ToShopifyModel();
            }

            //Powered by link
            if (workContext.CurrentStore != null)
            {
                var storeName = workContext.CurrentStore.Name;
                var hashCode  = (uint)storeName.GetHashCode();
                result.PoweredByLink = _poweredLinks[hashCode % _poweredLinks.Length];
            }
            return(result);
        }
Ejemplo n.º 25
0
        public static Shop ToShopifyModel(this Store store, storefrontModel.WorkContext workContext)
        {
            var converter = new ShopifyModelConverter();

            return(converter.ToLiquidShop(store, workContext));
        }
Ejemplo n.º 26
0
        public static ShopifyThemeWorkContext ToShopifyModel(this storefrontModel.WorkContext workContext, IStorefrontUrlBuilder urlBuilder)
        {
            var result = new ShopifyThemeWorkContext();

            result.CurrentPage       = 1;
            result.CountryOptionTags = string.Join("\r\n", workContext.AllCountries.OrderBy(c => c.Name).Select(c => c.ToOptionTag()));
            result.PageDescription   = workContext.CurrentPageSeo != null ? workContext.CurrentPageSeo.MetaDescription : string.Empty;
            result.PageTitle         = workContext.CurrentPageSeo != null ? workContext.CurrentPageSeo.Title : string.Empty;
            result.Shop    = workContext.CurrentStore.ToShopifyModel(workContext);
            result.Cart    = workContext.CurrentCart.ToShopifyModel(workContext);
            result.Product = workContext.CurrentProduct != null?workContext.CurrentProduct.ToShopifyModel(workContext) : null;

            result.Customer  = workContext.CurrentCustomer.HasAccount ? workContext.CurrentCustomer.ToShopifyModel(workContext, urlBuilder) : null;
            result.AllStores = workContext.AllStores.Select(x => x.ToShopifyModel(workContext)).ToArray();

            result.CurrentCurrency = workContext.CurrentCurrency.ToShopifyModel();
            result.CurrentLanguage = workContext.CurrentLanguage.ToShopifyModel();

            if (workContext.CurrentProduct != null && workContext.CurrentProduct.Category != null)
            {
                result.Collection = workContext.CurrentProduct.Category.ToShopifyModel(workContext);
            }

            if (workContext.CurrentCatalogSearchCriteria.Terms.Any())
            {
                result.CurrentTags =
                    new TagCollection(
                        workContext.CurrentCatalogSearchCriteria.Terms.Select(t => t.ToShopifyModel()).ToList());
            }

            var searchResult = workContext.CurrentCatalogSearchResult;

            if (searchResult != null)
            {
                result.Collection = searchResult.ToShopifyModel(workContext);

                if (searchResult.Categories != null)
                {
                    result.Collections = new Collections(searchResult.Categories.Select(x => x.ToShopifyModel(workContext)));
                }
            }

            if (workContext.CurrentLinkLists != null)
            {
                result.Linklists = new Linklists(workContext.CurrentLinkLists.Select(x => x.ToShopifyModel()));
            }

            if (workContext.Order != null)
            {
                result.Order = workContext.Order.ToShopifyModel(urlBuilder);
            }

            result.PaymentFormHtml = workContext.PaymentFormHtml;

            if (workContext.CurrentPage != null)
            {
                result.Page = workContext.CurrentPage.ToShopifyModel();
            }

            if (workContext.CurrentBlog != null)
            {
                result.Blog = workContext.CurrentBlog.ToShopifyModel();
            }

            if (workContext.CurrentBlogArticle != null)
            {
                result.Article = workContext.CurrentBlogArticle.ToShopifyModel();
            }

            if (workContext.ContactUsForm != null)
            {
                result.Form = workContext.ContactUsForm.ToShopifyModel();
            }

            if (workContext.Login != null)
            {
                result.Form = workContext.Login.ToShopifyModel();
            }

            return(result);
        }
Ejemplo n.º 27
0
        public virtual Customer ToLiquidCustomer(User user, StorefrontModel.WorkContext workContext, IStorefrontUrlBuilder urlBuilder)
        {
            var result = new Customer
            {
                DefaultLanguage  = user.DefaultLanguage,
                Email            = user.Email,
                OperatorUserId   = user.OperatorUserId,
                OperatorUserName = user.OperatorUserName,
                UserName         = user.UserName
            };

            if (user.Orders != null)
            {
                result.Orders = new MutablePagedList <Order>((pageNumber, pageSize, sortInfos) =>
                {
                    user.Orders.Slice(pageNumber, pageSize, sortInfos);
                    return(new StaticPagedList <Order>(user.Orders.Select(x => ToLiquidOrder(x, workContext.CurrentLanguage, urlBuilder)), user.Orders));
                }, user.Orders.PageNumber, user.Orders.PageSize);
            }

            if (user.QuoteRequests != null)
            {
                result.QuoteRequests = new MutablePagedList <QuoteRequest>((pageNumber, pageSize, sortInfos) =>
                {
                    user.QuoteRequests.Slice(pageNumber, pageSize, sortInfos);
                    return(new StaticPagedList <QuoteRequest>(user.QuoteRequests.Select(x => ToLiquidQuoteRequest(x)), user.QuoteRequests));
                }, user.QuoteRequests.PageNumber, user.QuoteRequests.PageSize);
            }

            var contact = user?.Contact;

            if (contact != null)
            {
                result.AcceptsMarketing = contact.AcceptsMarketing;
                result.FirstName        = contact.FirstName;
                result.LastName         = contact.LastName;
                result.MiddleName       = contact.MiddleName;
                result.Name             = contact.FullName;
                result.TimeZone         = contact.TimeZone;
                if (contact.DefaultAddress != null)
                {
                    result.DefaultAddress = ToLiquidAddress(contact.DefaultAddress);
                }
                if (contact.DefaultBillingAddress != null)
                {
                    result.DefaultBillingAddress = ToLiquidAddress(contact.DefaultBillingAddress);
                }
                if (contact.DefaultShippingAddress != null)
                {
                    result.DefaultShippingAddress = ToLiquidAddress(contact.DefaultShippingAddress);
                }

                if (contact.Addresses != null)
                {
                    var addresses = contact.Addresses.Select(a => ToLiquidAddress(a)).ToList();
                    result.Addresses = new MutablePagedList <Address>(addresses);
                }

                if (contact.DynamicProperties != null)
                {
                    result.Metafields = new MetaFieldNamespacesCollection(new[] { new MetafieldsCollection("dynamic_properties", workContext.CurrentLanguage, contact.DynamicProperties) });
                }
            }


            return(result);
        }
 public ApiCatalogController(WorkContext workContext, IStorefrontUrlBuilder urlBuilder, ICatalogSearchService catalogSearchService)
     : base(workContext, urlBuilder)
 {
     _catalogSearchService = catalogSearchService;
 }
Ejemplo n.º 29
0
        private string GetSlug(List<VirtoCommerceDomainCommerceModelSeoInfo> seoRecords, WorkContext workContext, string entityType, string entityId, string language)
        {
            var result = string.Empty;

            // Get slug for requested language
            if (!string.IsNullOrEmpty(language) && workContext.CurrentStore.Languages.Count >= 2)
            {
                result = FindActiveSlug(seoRecords, entityType, entityId, language);
            }

            // Get slug for default language
            if (string.IsNullOrEmpty(result))
            {
                result = FindActiveSlug(seoRecords, entityType, entityId, null);
            }

            return result;
        }
 public CatalogSearchController(WorkContext workContext, IStorefrontUrlBuilder urlBuilder, ICatalogSearchService searchService)
     : base(workContext, urlBuilder)
 {
     _searchService = searchService;
 }
 public ApiMarketingController(WorkContext workContext, IStorefrontUrlBuilder urlBuilder, IMarketingService marketingService)
     : base(workContext, urlBuilder)
 {
     _marketingService = marketingService;
 }
Ejemplo n.º 32
0
        public static Collection ToShopifyModel(this storefrontModel.Catalog.Category category, storefrontModel.WorkContext workContext)
        {
            var result = new Collection
            {
                Id          = category.Id,
                Description = null,
                Handle      = category.SeoInfo != null ? category.SeoInfo.Slug : category.Id,
                Title       = category.Name,
                Url         = "~/category/" + category.Id
            };

            if (category.PrimaryImage != null)
            {
                result.Image = category.PrimaryImage.ToShopifyModel();
            }

            if (category.SeoInfo != null)
            {
                result.Url = "~/" + category.SeoInfo.Slug;
            }

            return(result);
        }
Ejemplo n.º 33
0
        public static Collection ToShopifyModel(this storefrontModel.Catalog.CatalogSearchResult searchResult, storefrontModel.WorkContext workContext)
        {
            var result = new Collection();

            if (searchResult.Category != null)
            {
                result = searchResult.Category.ToShopifyModel(workContext);
            }

            if (searchResult.Products != null)
            {
                result.Products         = new StorefrontPagedList <Product>(searchResult.Products.Select(x => x.ToShopifyModel(workContext)), searchResult.Products, searchResult.Products.GetPageUrl);
                result.ProductsCount    = searchResult.Products.TotalItemCount;
                result.AllProductsCount = searchResult.Products.TotalItemCount;
            }

            if (searchResult.Aggregations != null)
            {
                var tags = searchResult.Aggregations
                           .Where(a => a.Items != null)
                           .SelectMany(a => a.Items.Select(item => item.ToShopifyModel(a.Field, a.Label)))
                           .ToList();

                result.Tags = new TagCollection(tags);
            }

            result.DefaultSortBy = "manual";
            if (workContext.CurrentCatalogSearchCriteria != null)
            {
                result.SortBy = workContext.CurrentCatalogSearchCriteria.SortBy;
            }

            return(result);
        }
Ejemplo n.º 34
0
 public StorefrontUrlBuilder(WorkContext workContext)
 {
     _workContext = workContext;
 }
Ejemplo n.º 35
0
        public virtual ShopifyThemeWorkContext ToLiquidContext(storefrontModel.WorkContext workContext, IStorefrontUrlBuilder urlBuilder)
        {
            var result = new ShopifyThemeWorkContext();


            result.CurrentPage       = 1;
            result.CountryOptionTags = string.Join("\r\n", workContext.AllCountries.OrderBy(c => c.Name).Select(c => c.ToOptionTag()));
            result.PageDescription   = workContext.CurrentPageSeo != null ? workContext.CurrentPageSeo.MetaDescription : string.Empty;
            result.PageTitle         = workContext.CurrentPageSeo != null ? workContext.CurrentPageSeo.Title : string.Empty;
            result.PageImageUrl      = workContext.CurrentPageSeo != null ? workContext.CurrentPageSeo.ImageUrl : string.Empty;
            result.CanonicalUrl      = workContext.CurrentPageSeo != null?urlBuilder.ToAppAbsolute(workContext.CurrentPageSeo.Slug) : null;

            result.Shop = workContext.CurrentStore != null?ToLiquidShop(workContext.CurrentStore, workContext) : null;

            result.Cart = workContext.CurrentCart != null?ToLiquidCart(workContext.CurrentCart, workContext.CurrentLanguage, urlBuilder) : null;

            result.Product = workContext.CurrentProduct != null?ToLiquidProduct(workContext.CurrentProduct) : null;

            result.Vendor = workContext.CurrentVendor != null?ToLiquidVendor(workContext.CurrentVendor) : null;

            result.Customer        = workContext.CurrentCustomer != null && workContext.CurrentCustomer.IsRegisteredUser ? ToLiquidCustomer(workContext.CurrentCustomer, workContext, urlBuilder) : null;
            result.AllStores       = workContext.AllStores.Select(x => ToLiquidShop(x, workContext)).ToArray();
            result.CurrentCurrency = workContext.CurrentCurrency != null?ToLiquidCurrency(workContext.CurrentCurrency) : null;

            result.CurrentLanguage = workContext.CurrentLanguage != null?ToLiquidLanguage(workContext.CurrentLanguage) : null;

            if (workContext.CurrentProductSearchCriteria != null && workContext.CurrentProductSearchCriteria.Terms.Any())
            {
                result.CurrentTags =
                    new TagCollection(
                        workContext.CurrentProductSearchCriteria.Terms.Select(t => ToLiquidTag(t)).ToList());
            }

            if (workContext.CurrentCategory != null)
            {
                result.Collection = ToLiquidCollection(workContext.CurrentCategory, workContext);
            }

            if (workContext.Categories != null)
            {
                result.Collections = new Collections(new MutablePagedList <Collection>((pageNumber, pageSize, sortInfos) =>
                {
                    workContext.Categories.Slice(pageNumber, pageSize, sortInfos);
                    return(new StaticPagedList <Collection>(workContext.Categories.Select(x => ToLiquidCollection(x, workContext)), workContext.Categories));
                }, 1, workContext.Categories.PageSize));
            }

            if (workContext.Products != null)
            {
                result.Products = new MutablePagedList <Product>((pageNumber, pageSize, sortInfos) =>
                {
                    workContext.Products.Slice(pageNumber, pageSize, sortInfos);
                    return(new StaticPagedList <Product>(workContext.Products.Select(x => ToLiquidProduct(x)), workContext.Products));
                }, workContext.Products.PageNumber, workContext.Products.PageSize);
            }

            if (workContext.Vendors != null)
            {
                result.Vendors = new MutablePagedList <Vendor>((pageNumber, pageSize, sortInfos) =>
                {
                    workContext.Vendors.Slice(pageNumber, pageSize, sortInfos);
                    return(new StaticPagedList <Vendor>(workContext.Vendors.Select(x => ToLiquidVendor(x)), workContext.Vendors));
                }, workContext.Vendors.PageNumber, workContext.Vendors.PageSize);
            }

            if (!string.IsNullOrEmpty(workContext.CurrentProductSearchCriteria.Keyword) && workContext.Products != null)
            {
                result.Search = ToLiquidSearch(workContext.Products, workContext);
            }
            else if (workContext.CurrentStaticSearchCriteria != null && !string.IsNullOrEmpty(workContext.CurrentStaticSearchCriteria.Keyword))
            {
                result.Search = new Search
                {
                    Performed = true,
                    SearchIn  = workContext.CurrentStaticSearchCriteria.SearchIn,
                    Terms     = workContext.CurrentStaticSearchCriteria.Keyword
                };
                if (workContext.StaticContentSearchResult != null && workContext.StaticContentSearchResult.Any())
                {
                    result.Search.Results = new MutablePagedList <Drop>((pageNumber, pageSize, sortInfos) =>
                    {
                        var pagedContentItems = new MutablePagedList <ContentItem>(workContext.StaticContentSearchResult);
                        pagedContentItems.Slice(pageNumber, pageSize, sortInfos);
                        return(new StaticPagedList <Drop>(workContext.StaticContentSearchResult.Select(x => ToLiquidPage(x)), pagedContentItems));
                    }, 1, workContext.StaticContentSearchResult.PageSize);
                }
            }

            if (workContext.CurrentLinkLists != null)
            {
                result.Linklists = new Linklists(workContext.CurrentLinkLists.Select(x => ToLiquidLinklist(x, workContext, urlBuilder)));
            }

            if (workContext.Pages != null)
            {
                result.Pages = new Pages(workContext.Pages.OfType <ContentPage>().Select(x => ToLiquidPage(x)));
                result.Blogs = new Blogs(workContext.Blogs.Select(x => ToLiquidBlog(x, workContext.CurrentLanguage)));
            }

            if (workContext.CurrentOrder != null)
            {
                result.Order = ToLiquidOrder(workContext.CurrentOrder, workContext.CurrentLanguage, urlBuilder);
            }

            if (workContext.CurrentQuoteRequest != null)
            {
                result.QuoteRequest = ToLiquidQuoteRequest(workContext.CurrentQuoteRequest);
            }

            result.PaymentFormHtml = workContext.PaymentFormHtml;

            if (workContext.CurrentPage != null)
            {
                result.Page = ToLiquidPage(workContext.CurrentPage);
            }

            if (workContext.CurrentBlog != null)
            {
                result.Blog = ToLiquidBlog(workContext.CurrentBlog, workContext.CurrentLanguage);
            }
            if (workContext.CurrentBlogSearchCritera != null)
            {
                result.BlogSearch = ToLiquidBlogSearch(workContext.CurrentBlogSearchCritera);
            }

            if (workContext.CurrentBlogArticle != null)
            {
                result.Article = ToLiquidArticle(workContext.CurrentBlogArticle);
            }

            if (workContext.ContactUsForm != null)
            {
                result.Form = workContext.ContactUsForm.ToShopifyModel();
            }

            if (workContext.Login != null)
            {
                result.Form = workContext.Login.ToShopifyModel();
            }

            if (workContext.StorefrontNotification != null)
            {
                result.Notification = ToLiquidNotification(workContext.StorefrontNotification);
            }

            result.ExternalLoginProviders = workContext.ExternalLoginProviders.Select(p => new LoginProvider
            {
                AuthenticationType = p.AuthenticationType,
                Caption            = p.Caption,
                Properties         = p.Properties
            }).ToList();

            result.ApplicationSettings = new MetafieldsCollection("application_settings", workContext.ApplicationSettings);

            //Powered by link
            if (workContext.CurrentStore != null)
            {
                var storeName = workContext.CurrentStore.Name;
                var hashCode  = (uint)storeName.GetHashCode();
                result.PoweredByLink = _poweredLinks[hashCode % _poweredLinks.Length];
            }

            if (workContext.RequestUrl != null)
            {
                result.RequestUrl = workContext.RequestUrl.ToString();

                //Populate current page number
                result.CurrentPage = workContext.PageNumber ?? 1;
                result.PageSize    = workContext.PageSize ?? 0;
            }

            return(result);
        }
Ejemplo n.º 36
0
        public static Customer ToShopifyModel(this CustomerInfo customer, StorefrontModel.WorkContext workContext, IStorefrontUrlBuilder urlBuilder)
        {
            var converter = ServiceLocator.Current.GetInstance <ShopifyModelConverter>();

            return(converter.ToLiquidCustomer(customer, workContext, urlBuilder));
        }
Ejemplo n.º 37
0
        public static Customer ToShopifyModel(this User user, StorefrontModel.WorkContext workContext, IStorefrontUrlBuilder urlBuilder)
        {
            var converter = new ShopifyModelConverter();

            return(converter.ToLiquidCustomer(user, workContext, urlBuilder));
        }
Ejemplo n.º 38
0
        public static Link ToShopfiyModel(this StorefrontModel.MenuLink storefrontModel, StorefrontModel.WorkContext workContext)
        {
            var shopifyModel = new Link();

            shopifyModel.Active = storefrontModel.IsActive;
            shopifyModel.Object = "";
            shopifyModel.Title  = storefrontModel.Title;
            shopifyModel.Type   = "";
            shopifyModel.Url    = storefrontModel.Url;

            var productLink  = storefrontModel as StorefrontModel.ProductMenuLink;
            var categoryLink = storefrontModel as StorefrontModel.CategoryMenuLink;

            if (productLink != null)
            {
                shopifyModel.Type = "product";
                if (productLink.Product != null)
                {
                    shopifyModel.Object = productLink.Product.ToShopifyModel(workContext);
                }
            }
            if (categoryLink != null)
            {
                shopifyModel.Type = "collection";
                if (categoryLink.Category != null)
                {
                    shopifyModel.Object = categoryLink.Category.ToShopifyModel(workContext);
                }
            }
            return(shopifyModel);
        }
Ejemplo n.º 39
0
        public static LineItem ToShopifyModel(this StorefrontModel.Cart.LineItem lineItem, StorefrontModel.WorkContext workContext)
        {
            var shopifyModel = new LineItem();

            //shopifyModel.Product = lineItem.Product.ToShopifyModel();
            shopifyModel.Fulfillment = null; // TODO
            shopifyModel.Grams       = lineItem.Weight;
            shopifyModel.Id          = lineItem.Id;
            //shopifyModel.Image = lineItem.Product.PrimaryImage != null ? lineItem.Product.PrimaryImage.ToShopifyModel() : null;
            shopifyModel.LinePrice = lineItem.ExtendedPrice.Amount;
            shopifyModel.Price     = lineItem.PlacedPrice.Amount;
            shopifyModel.ProductId = lineItem.ProductId;
            //shopifyModel.Properties = null; // TODO
            shopifyModel.Quantity         = lineItem.Quantity;
            shopifyModel.RequiresShipping = lineItem.RequiredShipping;
            shopifyModel.Sku       = lineItem.Sku;
            shopifyModel.Taxable   = lineItem.TaxIncluded;
            shopifyModel.Title     = lineItem.Name;
            shopifyModel.Type      = null; // TODO
            shopifyModel.Url       = null; // TODO
            shopifyModel.Variant   = null; // TODO
            shopifyModel.VariantId = null; // TODO
            shopifyModel.Vendor    = null; // TODO

            return(shopifyModel);
        }
 public QuoteRequestController(WorkContext workContext, IStorefrontUrlBuilder urlBuilder, IQuoteRequestBuilder quoteRequestBuilder)
     : base(workContext, urlBuilder)
 {
     _quoteRequestBuilder = quoteRequestBuilder;
  }
Ejemplo n.º 41
0
        public static ShopifyThemeWorkContext ToShopifyModel(this storefrontModel.WorkContext workContext, IStorefrontUrlBuilder urlBuilder)
        {
            var result = new ShopifyThemeWorkContext();

            result.CurrentPage       = 1;
            result.CountryOptionTags = string.Join("\r\n", workContext.AllCountries.OrderBy(c => c.Name).Select(c => c.ToOptionTag()));
            result.PageDescription   = workContext.CurrentPageSeo != null ? workContext.CurrentPageSeo.MetaDescription : string.Empty;
            result.PageTitle         = workContext.CurrentPageSeo != null ? workContext.CurrentPageSeo.Title : string.Empty;
            result.Shop = workContext.CurrentStore != null?workContext.CurrentStore.ToShopifyModel(workContext) : null;

            result.Cart = workContext.CurrentCart != null?workContext.CurrentCart.ToShopifyModel(workContext) : null;

            result.Product = workContext.CurrentProduct != null?workContext.CurrentProduct.ToShopifyModel() : null;

            result.Customer  = workContext.CurrentCustomer != null && workContext.CurrentCustomer.IsRegisteredUser ? workContext.CurrentCustomer.ToShopifyModel(workContext, urlBuilder) : null;
            result.AllStores = workContext.AllStores.Select(x => x.ToShopifyModel(workContext)).ToArray();

            result.CurrentCurrency = workContext.CurrentCurrency != null?workContext.CurrentCurrency.ToShopifyModel() : null;

            result.CurrentLanguage = workContext.CurrentLanguage != null?workContext.CurrentLanguage.ToShopifyModel() : null;

            if (workContext.CurrentCatalogSearchCriteria != null && workContext.CurrentCatalogSearchCriteria.Terms.Any())
            {
                result.CurrentTags =
                    new TagCollection(
                        workContext.CurrentCatalogSearchCriteria.Terms.Select(t => t.ToShopifyModel()).ToList());
            }

            if (workContext.CurrentCategory != null)
            {
                result.Collection = workContext.CurrentCategory.ToShopifyModel(workContext);
            }

            if (workContext.Categories != null)
            {
                result.Collections = new Collections(new MutablePagedList <Collection>((pageNumber, pageSize) =>
                {
                    workContext.Categories.Slice(pageNumber, pageSize);
                    return(new StaticPagedList <Collection>(workContext.Categories.Select(x => x.ToShopifyModel(workContext)), workContext.Categories));
                }));
            }

            if (!string.IsNullOrEmpty(workContext.CurrentCatalogSearchCriteria.Keyword) && workContext.Products != null)
            {
                result.Search = workContext.Products.ToShopifyModel(workContext.CurrentCatalogSearchCriteria.Keyword);
            }

            if (workContext.CurrentLinkLists != null)
            {
                result.Linklists = new Linklists(workContext.CurrentLinkLists.Select(x => x.ToShopifyModel(workContext, urlBuilder)));
            }

            if (workContext.Pages != null)
            {
                result.Pages = new Pages(workContext.Pages.OfType <ContentPage>().Select(x => x.ToShopifyModel()));
                result.Blogs = new Blogs(workContext.Blogs.Select(x => x.ToShopifyModel(workContext.CurrentLanguage)));
            }

            if (workContext.CurrentOrder != null)
            {
                result.Order = workContext.CurrentOrder.ToShopifyModel(urlBuilder);
            }

            if (workContext.CurrentQuoteRequest != null)
            {
                result.QuoteRequest = workContext.CurrentQuoteRequest.ToShopifyModel();
            }


            result.PaymentFormHtml = workContext.PaymentFormHtml;

            if (workContext.CurrentPage != null)
            {
                result.Page = workContext.CurrentPage.ToShopifyModel();
            }

            if (workContext.CurrentBlog != null)
            {
                result.Blog = workContext.CurrentBlog.ToShopifyModel(workContext.CurrentLanguage);
            }

            if (workContext.CurrentBlogArticle != null)
            {
                result.Article = workContext.CurrentBlogArticle.ToShopifyModel();
            }

            if (workContext.ContactUsForm != null)
            {
                result.Form = workContext.ContactUsForm.ToShopifyModel();
            }

            if (workContext.Login != null)
            {
                result.Form = workContext.Login.ToShopifyModel();
            }

            if (workContext.StorefrontNotification != null)
            {
                result.Notification = workContext.StorefrontNotification.ToShopifyModel();
            }

            result.ExternalLoginProviders = workContext.ExternalLoginProviders.Select(p => new LoginProvider
            {
                AuthenticationType = p.AuthenticationType,
                Caption            = p.Caption,
                Properties         = p.Properties
            }).ToList();

            //Powered by link
            if (workContext.CurrentStore != null)
            {
                var storeName = workContext.CurrentStore.Name;
                var hashCode  = (uint)storeName.GetHashCode();
                result.PoweredByLink = _poweredLinks[hashCode % _poweredLinks.Length];
            }

            result.CurrentPage = 1;
            if (workContext.RequestUrl != null)
            {
                result.RequestUrl = workContext.RequestUrl.ToString();
                //Populate current page number
                var qs = HttpUtility.ParseQueryString(workContext.RequestUrl.Query);
                result.CurrentPage = Convert.ToInt32(qs.Get("page") ?? 1.ToString());
            }
            return(result);
        }
Ejemplo n.º 42
0
        public static Shop ToShopifyModel(this Store store, storefrontModel.WorkContext workContext)
        {
            var converter = ServiceLocator.Current.GetInstance <ShopifyModelConverter>();

            return(converter.ToLiquidShop(store, workContext));
        }
Ejemplo n.º 43
0
        public static Product ToShopifyModel(this StorefrontModel.Catalog.Product product, StorefrontModel.WorkContext workContext)
        {
            var result = new Product();

            result.InjectFrom <StorefrontModel.Common.NullableAndEnumValueInjecter>(product);
            result.Variants.Add(product.ToVariant(workContext));

            if (product.Variations != null)
            {
                result.Variants.AddRange(product.Variations.Select(x => x.ToVariant(workContext)));
            }

            result.Available = true;// product.IsActive && product.IsBuyable;

            result.CatalogId  = product.CatalogId;
            result.CategoryId = product.CategoryId;

            result.CompareAtPriceMax    = result.Variants.Select(x => x.CompareAtPrice).Max();
            result.CompareAtPriceMin    = result.Variants.Select(x => x.CompareAtPrice).Min();
            result.CompareAtPriceVaries = result.CompareAtPriceMax != result.CompareAtPriceMin;

            result.CompareAtPrice = product.Price.ListPrice.Amount;
            result.Price          = product.Price.SalePrice.Amount;
            if (product.Price.ActiveDiscount != null)
            {
                result.Price = result.Price - product.Price.ActiveDiscount.Amount.Amount;
            }
            result.PriceMax    = result.Variants.Select(x => x.Price).Max();
            result.PriceMin    = result.Variants.Select(x => x.Price).Min();
            result.PriceVaries = result.PriceMax != result.PriceMin;

            result.Content       = product.Description;
            result.Description   = result.Content;
            result.FeaturedImage = product.PrimaryImage != null?product.PrimaryImage.ToShopifyModel() : null;

            if (result.FeaturedImage != null)
            {
                result.FeaturedImage.ProductId         = product.Id;
                result.FeaturedImage.AttachedToVariant = false;
            }
            result.FirstAvailableVariant = result.Variants.FirstOrDefault(x => x.Available);
            result.Handle = product.SeoInfo != null ? product.SeoInfo.Slug : product.Id;
            result.Images = product.Images.Select(x => x.ToShopifyModel()).ToArray();
            foreach (var image in result.Images)
            {
                image.ProductId         = product.Id;
                image.AttachedToVariant = false;
            }
            if (product.VariationProperties != null)
            {
                result.Options = product.VariationProperties.Select(x => x.Name).ToArray();
            }
            if (product.Properties != null)
            {
                result.Properties = product.Properties.Select(x => x.ToShopifyModel()).ToList();
            }
            result.SelectedVariant = result.Variants.First();
            result.Title           = product.Name;
            result.Type            = product.ProductType;
            result.Url             = "~/product/" + product.Id;
            if (product.SeoInfo != null)
            {
                result.Url = "~/" + product.SeoInfo.Slug;
            }

            return(result);
        }
 public StorefrontControllerBase(WorkContext context, IStorefrontUrlBuilder urlBuilder)
 {
     WorkContext = context;
     UrlBuilder = urlBuilder;
 }
Ejemplo n.º 45
0
 public PageController(WorkContext context, IStorefrontUrlBuilder urlBuilder, IStaticContentService contentService)
     : base(context, urlBuilder)
 {
     _contentService = contentService;
 }
Ejemplo n.º 46
0
        public static Linklist ToShopifyModel(this StorefrontModel.MenuLinkList storefrontModel, StorefrontModel.WorkContext workContext)
        {
            var shopifyModel = new Linklist();

            shopifyModel.Handle = storefrontModel.Name;
            shopifyModel.Id     = storefrontModel.Id;
            shopifyModel.Links  = storefrontModel.MenuLinks.Select(ml => ml.ToShopfiyModel(workContext)).ToList();
            shopifyModel.Title  = storefrontModel.Name;

            return(shopifyModel);
        }
Ejemplo n.º 47
0
 public ProductController(WorkContext context, IStorefrontUrlBuilder urlBuilder, ICatalogSearchService catalogSearchService)
     : base(context, urlBuilder)
 {
     _catalogSearchService = catalogSearchService;
 }
Ejemplo n.º 48
0
 public CartController(WorkContext workContext, IOrderModuleApi orderApi, IStorefrontUrlBuilder urlBuilder, ICommerceCoreModuleApi commerceApi)
     : base(workContext, urlBuilder)
 {
     _orderApi = orderApi;
     _commerceApi = commerceApi;
 }
Ejemplo n.º 49
0
        public static Variant ToVariant(this StorefrontModel.Catalog.Product product, StorefrontModel.WorkContext workContext)
        {
            var result = new Variant();

            result.Available = true; //product.IsActive && product.IsBuyable;
            result.Barcode   = product.Gtin;

            result.CatalogId  = product.CatalogId;
            result.CategoryId = product.CategoryId;

            result.FeaturedImage = product.PrimaryImage != null?product.PrimaryImage.ToShopifyModel() : null;

            if (result.FeaturedImage != null)
            {
                result.FeaturedImage.ProductId         = product.Id;
                result.FeaturedImage.AttachedToVariant = true;
                result.FeaturedImage.Variants          = new[] { result };
            }
            result.Id = product.Id;
            result.InventoryPolicy   = "continue";
            result.InventoryQuantity = product.Inventory != null ? product.Inventory.InStockQuantity ?? 0 : 0;
            result.Options           = product.VariationProperties.Select(p => p.Value).ToArray();
            result.CompareAtPrice    = product.Price.ListPrice.Amount;
            result.Price             = product.Price.SalePrice.Amount;
            if (product.Price.ActiveDiscount != null)
            {
                result.Price = result.Price - product.Price.ActiveDiscount.Amount.Amount;
            }

            result.Selected = false;
            result.Sku      = product.Sku;
            result.Title    = product.Name;

            result.Url = "~/product/" + product.Id;
            if (product.SeoInfo != null)
            {
                result.Url = "~/" + product.SeoInfo.Slug;
            }
            result.Weight     = product.Weight;
            result.WeightUnit = product.WeightUnit;
            return(result);
        }
 protected virtual CatalogSearchCriteria GetSearchCriteria(WorkContext workContext)
 {
     var qs = HttpUtility.ParseQueryString(workContext.RequestUrl.Query);
     var retVal = CatalogSearchCriteria.Parse(qs);
     retVal.CatalogId = workContext.CurrentStore.Catalog;
     retVal.Currency = workContext.CurrentCurrency;
     retVal.Language = workContext.CurrentLanguage;
     return retVal;
 }
Ejemplo n.º 51
0
        public static Cart ToShopifyModel(this StorefrontModel.Cart.ShoppingCart cart, StorefrontModel.WorkContext workContext)
        {
            var result = new Cart();

            result.Items       = cart.Items.Select(x => x.ToShopifyModel(workContext)).ToList();
            result.ItemCount   = cart.Items.Count();
            result.Note        = cart.Comment;
            result.TotalPrice  = cart.Total.Amount;
            result.TotalWeight = cart.Weight;

            return(result);
        }
 public ApiAccountController(WorkContext workContext, IStorefrontUrlBuilder urlBuilder)
     : base(workContext, urlBuilder)
 {
 }
Ejemplo n.º 53
0
        public virtual ShopifyThemeWorkContext ToLiquidContext(storefrontModel.WorkContext workContext, IStorefrontUrlBuilder urlBuilder)
        {
            var result = new ShopifyThemeWorkContext();


            result.CurrentPage       = 1;
            result.Layout            = workContext.Layout;
            result.CountryOptionTags = string.Join("\r\n", workContext.AllCountries.OrderBy(c => c.Name).Select(c => c.ToOptionTag()));
            result.PageDescription   = workContext.CurrentPageSeo != null ? workContext.CurrentPageSeo.MetaDescription : string.Empty;
            result.PageTitle         = workContext.CurrentPageSeo != null ? workContext.CurrentPageSeo.Title : string.Empty;
            result.PageImageUrl      = workContext.CurrentPageSeo != null ? workContext.CurrentPageSeo.ImageUrl : string.Empty;
            result.CanonicalUrl      = workContext.CurrentPageSeo != null?urlBuilder.ToAppAbsolute(workContext.CurrentPageSeo.Slug) : null;

            result.Shop = workContext.CurrentStore != null?ToLiquidShop(workContext.CurrentStore, workContext) : null;

            result.Cart    = workContext.CurrentCart != null && workContext.CurrentCart.IsValueCreated ? ToLiquidCart(workContext.CurrentCart.Value, workContext.CurrentLanguage, urlBuilder) : null;
            result.Product = workContext.CurrentProduct != null?ToLiquidProduct(workContext.CurrentProduct) : null;

            result.Vendor = workContext.CurrentVendor != null?ToLiquidVendor(workContext.CurrentVendor) : null;

            result.Customer        = workContext.CurrentUser != null && workContext.CurrentUser.IsRegisteredUser ? ToLiquidCustomer(workContext.CurrentUser, workContext, urlBuilder) : null;
            result.AllStores       = workContext.AllStores.Select(x => ToLiquidShop(x, workContext)).ToArray();
            result.CurrentCurrency = workContext.CurrentCurrency != null?ToLiquidCurrency(workContext.CurrentCurrency) : null;

            result.CurrentLanguage = workContext.CurrentLanguage != null?ToLiquidLanguage(workContext.CurrentLanguage) : null;

            if (workContext.CurrentProductSearchCriteria != null && workContext.CurrentProductSearchCriteria.Terms.Any())
            {
                result.CurrentTags =
                    new TagCollection(
                        workContext.CurrentProductSearchCriteria.Terms.Select(t => ToLiquidTag(t)).ToList());
            }

            if (workContext.CurrentCategory != null)
            {
                result.Collection = ToLiquidCollection(workContext.CurrentCategory, workContext);
            }

            if (workContext.Categories != null)
            {
                result.Collections = new Collections(new MutablePagedList <Collection>((pageNumber, pageSize, sortInfos) =>
                {
                    workContext.Categories.Slice(pageNumber, pageSize, sortInfos);
                    return(new StaticPagedList <Collection>(workContext.Categories.Select(x => ToLiquidCollection(x, workContext)), workContext.Categories));
                }, 1, workContext.Categories.PageSize));
            }

            if (workContext.Products != null)
            {
                result.Products = new MutablePagedList <Product>((pageNumber, pageSize, sortInfos) =>
                {
                    workContext.Products.Slice(pageNumber, pageSize, sortInfos);
                    return(new StaticPagedList <Product>(workContext.Products.Select(x => ToLiquidProduct(x)), workContext.Products));
                }, workContext.Products.PageNumber, workContext.Products.PageSize);
            }

            if (workContext.Vendors != null)
            {
                result.Vendors = new MutablePagedList <Vendor>((pageNumber, pageSize, sortInfos) =>
                {
                    workContext.Vendors.Slice(pageNumber, pageSize, sortInfos);
                    return(new StaticPagedList <Vendor>(workContext.Vendors.Select(x => ToLiquidVendor(x)), workContext.Vendors));
                }, workContext.Vendors.PageNumber, workContext.Vendors.PageSize);
            }

            if (workContext.CurrentProductSearchCriteria != null && !string.IsNullOrEmpty(workContext.CurrentProductSearchCriteria.Keyword) && workContext.Products != null)
            {
                result.Search = ToLiquidSearch(workContext.Products, workContext);
            }
            else if (workContext.CurrentStaticSearchCriteria != null && !string.IsNullOrEmpty(workContext.CurrentStaticSearchCriteria.Keyword))
            {
                result.Search = new Search
                {
                    Performed = true,
                    SearchIn  = workContext.CurrentStaticSearchCriteria.SearchIn,
                    Terms     = workContext.CurrentStaticSearchCriteria.Keyword
                };
                if (workContext.StaticContentSearchResult != null && workContext.StaticContentSearchResult.Any())
                {
                    result.Search.Results = new MutablePagedList <Drop>((pageNumber, pageSize, sortInfos) =>
                    {
                        var pagedContentItems = new MutablePagedList <ContentItem>(workContext.StaticContentSearchResult);
                        pagedContentItems.Slice(pageNumber, pageSize, sortInfos);
                        return(new StaticPagedList <Drop>(workContext.StaticContentSearchResult.Select(x => ToLiquidPage(x)), pagedContentItems));
                    }, 1, workContext.StaticContentSearchResult.PageSize);
                }
            }

            if (workContext.CurrentLinkLists != null)
            {
                result.Linklists = new Linklists(workContext.CurrentLinkLists.Select(x => ToLiquidLinklist(x, workContext, urlBuilder)));
            }

            if (workContext.Pages != null)
            {
                result.Pages = new Pages(workContext.Pages.OfType <ContentPage>().Select(x => ToLiquidPage(x)));
                result.Blogs = new Blogs(workContext.Blogs.Select(x => ToLiquidBlog(x, workContext.CurrentLanguage)));
            }

            if (workContext.CurrentOrder != null)
            {
                result.Order = ToLiquidOrder(workContext.CurrentOrder, workContext.CurrentLanguage, urlBuilder);
            }

            if (workContext.CurrentQuoteRequest != null)
            {
                result.QuoteRequest = ToLiquidQuoteRequest(workContext.CurrentQuoteRequest.Value);
            }

            result.PaymentFormHtml = workContext.PaymentFormHtml;

            if (workContext.CurrentPage != null)
            {
                result.Page = ToLiquidPage(workContext.CurrentPage);
            }

            if (workContext.CurrentBlog != null)
            {
                result.Blog = ToLiquidBlog(workContext.CurrentBlog, workContext.CurrentLanguage);
            }
            if (workContext.CurrentBlogSearchCritera != null)
            {
                result.BlogSearch = ToLiquidBlogSearch(workContext.CurrentBlogSearchCritera);
            }

            if (workContext.CurrentBlogArticle != null)
            {
                result.Article = ToLiquidArticle(workContext.CurrentBlogArticle);
            }

            if (workContext.Form != null)
            {
                result.Form = new Form
                {
                    Properties = new Dictionary <string, object>()
                };
                var formProps     = workContext.Form.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
                var formPropNames = formProps.Select(x => x.Name).ToArray();
                foreach (var property in formProps)
                {
                    var propertyValue = property.GetValue(workContext.Form);
                    if (propertyValue != null)
                    {
                        result.Form.Properties[Template.NamingConvention.GetMemberName(property.Name)] = propertyValue;
                        if (typeof(IEntity).IsAssignableFrom(property.PropertyType) || typeof(IValueObject).IsAssignableFrom(property.PropertyType))
                        {
                            //For it is user type need to register this type as Drop in Liquid Template
                            Template.RegisterSafeType(property.GetType(), formPropNames);
                            var allChildEntities = propertyValue.GetFlatObjectsListWithInterface <IEntity>();
                            foreach (var type in allChildEntities.Select(x => x.GetType()).Distinct())
                            {
                                Template.RegisterSafeType(type, formPropNames);
                            }
                            var allChildLiquidObjects = propertyValue.GetFlatObjectsListWithInterface <IValueObject>();
                            foreach (var type in allChildLiquidObjects.Select(x => x.GetType()).Distinct())
                            {
                                Template.RegisterSafeType(type, formPropNames);
                            }
                        }
                    }
                }
            }

            if (workContext.StorefrontNotification != null)
            {
                result.Notification = ToLiquidNotification(workContext.StorefrontNotification);
            }

            result.ExternalLoginProviders = workContext.ExternalLoginProviders.Select(p => new LoginProvider
            {
                AuthenticationType = p.AuthenticationType,
                Caption            = p.Caption,
                Properties         = p.Properties
            }).ToList();

            result.ApplicationSettings = new MetafieldsCollection("application_settings", workContext.ApplicationSettings);

            //Powered by link
            if (workContext.CurrentStore != null)
            {
                var storeName = workContext.CurrentStore.Name;
                var hashCode  = (uint)storeName.GetHashCode();
                result.PoweredByLink = _poweredLinks[hashCode % _poweredLinks.Length];
            }

            if (workContext.RequestUrl != null)
            {
                result.RequestUrl = workContext.RequestUrl.ToString();

                //Populate current page number
                result.CurrentPage = workContext.PageNumber ?? 1;
                result.PageSize    = workContext.PageSize ?? 0;
            }

            if (workContext.AvailableRoles != null)
            {
                result.AvailableRoles = workContext.AvailableRoles.Select(x => new Role
                {
                    Id   = x.Id,
                    Name = x.Name
                }).ToArray();
            }

            if (workContext.CurrentFulfillmentCenter != null)
            {
                result.FulfillmentCenter = workContext.CurrentFulfillmentCenter.ToShopifyModel();
            }

            if (workContext.FulfillmentCenters != null)
            {
                result.FulfillmentCenters = new MutablePagedList <FulfillmentCenter>((pageNumber, pageSize, sortInfos) =>
                {
                    workContext.FulfillmentCenters.Slice(pageNumber, pageSize, sortInfos);
                    return(new StaticPagedList <FulfillmentCenter>(workContext.FulfillmentCenters.Select(x => x.ToShopifyModel()), workContext.FulfillmentCenters));
                }, workContext.FulfillmentCenters.PageNumber, workContext.FulfillmentCenters.PageSize);
            }
            return(result);
        }
Ejemplo n.º 54
0
 public ProductController(WorkContext context, IStorefrontUrlBuilder urlBuilder, ICatalogSearchService productService, ICatalogSearchService searchService)
     : base(context, urlBuilder)
 {
     _productService = productService;
     _searchService = searchService;
 }
Ejemplo n.º 55
0
        public static ShopifyThemeWorkContext ToShopifyModel(this storefrontModel.WorkContext workContext, IStorefrontUrlBuilder urlBuilder)
        {
            var converter = ServiceLocator.Current.GetInstance <ShopifyModelConverter>();

            return(converter.ToLiquidContext(workContext, urlBuilder));
        }
Ejemplo n.º 56
0
        private void MaintainAnonymousCustomerCookie(IOwinContext context, WorkContext workContext)
        {
            string anonymousCustomerId = context.Request.Cookies[StorefrontConstants.AnonymousCustomerIdCookie];

            if (workContext.CurrentCustomer.IsRegisteredUser)
            {
                if (!string.IsNullOrEmpty(anonymousCustomerId))
                {
                    // Remove anonymous customer cookie for registered customer
                    context.Response.Cookies.Append(StorefrontConstants.AnonymousCustomerIdCookie, string.Empty, new CookieOptions { Expires = DateTime.UtcNow.AddDays(-30) });
                }
            }
            else
            {
                if (string.IsNullOrEmpty(anonymousCustomerId))
                {
                    // Add anonymous customer cookie for nonregistered customer
                    anonymousCustomerId = Guid.NewGuid().ToString();
                    workContext.CurrentCustomer.Id = anonymousCustomerId;
                    context.Response.Cookies.Append(StorefrontConstants.AnonymousCustomerIdCookie, anonymousCustomerId, new CookieOptions { Expires = DateTime.UtcNow.AddDays(30) });
                }
            }
        }
Ejemplo n.º 57
0
        public static Collection ToShopifyModel(this storefrontModel.Catalog.Category category, storefrontModel.WorkContext workContext)
        {
            var result = new Collection
            {
                Id            = category.Id,
                Description   = null,
                Handle        = category.SeoInfo != null ? category.SeoInfo.Slug : category.Id,
                Title         = category.Name,
                Url           = category.Url,
                DefaultSortBy = "manual",
            };

            if (category.PrimaryImage != null)
            {
                result.Image = category.PrimaryImage.ToShopifyModel();
            }

            if (category.Products != null)
            {
                result.Products = new MutablePagedList <Product>((pageNumber, pageSize, sortInfos) =>
                {
                    category.Products.Slice(pageNumber, pageSize, sortInfos);
                    return(new StaticPagedList <Product>(category.Products.Select(x => x.ToShopifyModel()), category.Products));
                }, category.Products.PageNumber, category.Products.PageSize);
            }

            if (workContext.Aggregations != null)
            {
                result.Tags = new TagCollection(new MutablePagedList <Tag>((pageNumber, pageSize, sortInfos) =>
                {
                    workContext.Aggregations.Slice(pageNumber, pageSize, sortInfos);
                    var tags = workContext.Aggregations.Where(a => a.Items != null)
                               .SelectMany(a => a.Items.Select(item => item.ToShopifyModel(a.Field, a.Label)));
                    return(new StaticPagedList <Tag>(tags, workContext.Aggregations));
                }, workContext.Aggregations.PageNumber, workContext.Aggregations.PageSize));
            }

            if (workContext.CurrentCatalogSearchCriteria.SortBy != null)
            {
                result.SortBy = workContext.CurrentCatalogSearchCriteria.SortBy;
            }

            if (!category.Properties.IsNullOrEmpty())
            {
                result.Metafields = new MetaFieldNamespacesCollection(new[] { new MetafieldsCollection("properties", category.Properties) });
            }

            return(result);
        }
Ejemplo n.º 58
0
 public HomeController(WorkContext context, ICatalogSearchService catalogSearchService)
 {
     _catalogSearchService = catalogSearchService;
     _workContext = context;
 }