コード例 #1
0
        public virtual pricingDto.PriceEvaluationContext ToPriceEvaluationContextDto(WorkContext workContext, IEnumerable <Product> products = null)
        {
            //Evaluate products prices
            var retVal = new pricingDto.PriceEvaluationContext
            {
                PricelistIds = workContext.CurrentPricelists.Select(p => p.Id).ToList(),
                CatalogId    = workContext.CurrentStore.Catalog,
                Language     = workContext.CurrentLanguage.CultureName,
                CertainDate  = workContext.StorefrontUtcNow,
                StoreId      = workContext.CurrentStore.Id
            };

            if (workContext.CurrentCustomer != null)
            {
                retVal.CustomerId = workContext.CurrentCustomer.Id;
                if (workContext.CurrentCustomer.UserGroups != null)
                {
                    retVal.UserGroups = workContext.CurrentCustomer.UserGroups.ToList();
                }
            }

            if (products != null)
            {
                retVal.ProductIds = products.Select(p => p.Id).ToList();
            }
            return(retVal);
        }
コード例 #2
0
        public virtual pricingDto.PriceEvaluationContext ToPriceEvaluationContextDto(IEnumerable <Product> products, WorkContext workContext)
        {
            if (products == null)
            {
                throw new ArgumentNullException("products");
            }

            //Evaluate products prices
            var retVal = new pricingDto.PriceEvaluationContext
            {
                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);
        }
コード例 #3
0
        public virtual pricingDto.PriceEvaluationContext ToPriceEvaluationContextDto(WorkContext workContext, IEnumerable <Product> products = null)
        {
            //Evaluate products prices
            var retVal = new pricingDto.PriceEvaluationContext
            {
                PricelistIds = workContext.CurrentPricelists.Select(p => p.Id).ToList(),
                CatalogId    = workContext.CurrentStore.Catalog,
                Language     = workContext.CurrentLanguage.CultureName,
                CertainDate  = workContext.StorefrontUtcNow,
                StoreId      = workContext.CurrentStore.Id
            };

            if (workContext.CurrentCustomer != null)
            {
                retVal.CustomerId  = workContext.CurrentCustomer.Id;
                retVal.GeoTimeZone = workContext.CurrentCustomer.TimeZone;
                var address = workContext.CurrentCustomer.DefaultShippingAddress ?? workContext.CurrentCustomer.DefaultBillingAddress;
                if (address != null)
                {
                    retVal.GeoCity    = address.City;
                    retVal.GeoCountry = address.CountryCode;
                    retVal.GeoState   = address.RegionName;
                    retVal.GeoZipCode = address.PostalCode;
                }
                if (workContext.CurrentCustomer.UserGroups != null)
                {
                    retVal.UserGroups = workContext.CurrentCustomer.UserGroups.ToList();
                }
            }

            if (products != null)
            {
                retVal.ProductIds = products.Select(p => p.Id).ToList();
            }
            return(retVal);
        }
コード例 #4
0
        protected virtual async Task HandleNonAssetRequest(IOwinContext context, WorkContext workContext)
        {
            //Shopping cart
            var cartBuilder = Container.Resolve <ICartBuilder>();
            await cartBuilder.LoadOrCreateNewTransientCartAsync("default", workContext.CurrentStore, workContext.CurrentCustomer, workContext.CurrentLanguage, workContext.CurrentCurrency);

            workContext.CurrentCart = cartBuilder.Cart;

            if (workContext.CurrentStore.QuotesEnabled)
            {
                var quoteRequestBuilder = Container.Resolve <IQuoteRequestBuilder>();
                await quoteRequestBuilder.GetOrCreateNewTransientQuoteRequestAsync(workContext.CurrentStore, workContext.CurrentCustomer, workContext.CurrentLanguage, workContext.CurrentCurrency);

                workContext.CurrentQuoteRequest = quoteRequestBuilder.QuoteRequest;
            }

            var linkListService = Container.Resolve <IMenuLinkListService>();
            var linkLists       = await CacheManager.GetAsync("GetAllStoreLinkLists-" + workContext.CurrentStore.Id, "ApiRegion", async() => await linkListService.LoadAllStoreLinkListsAsync(workContext.CurrentStore.Id));

            workContext.CurrentLinkLists = linkLists.GroupBy(x => x.Name).Select(x => x.FindWithLanguage(workContext.CurrentLanguage)).Where(x => x != null).ToList();
            // load all static content
            var staticContents = CacheManager.Get(string.Join(":", "AllStoreStaticContent", workContext.CurrentStore.Id), "ContentRegion", () =>
            {
                var staticContentService = Container.Resolve <IStaticContentService>();
                var allContentItems      = staticContentService.LoadStoreStaticContent(workContext.CurrentStore).ToList();
                var blogs             = allContentItems.OfType <Blog>().ToArray();
                var blogArticlesGroup = allContentItems.OfType <BlogArticle>().GroupBy(x => x.BlogName, x => x).ToList();

                foreach (var blog in blogs)
                {
                    var blogArticles = blogArticlesGroup.FirstOrDefault(x => string.Equals(x.Key, blog.Name, StringComparison.OrdinalIgnoreCase));
                    if (blogArticles != null)
                    {
                        blog.Articles = new MutablePagedList <BlogArticle>(blogArticles);
                    }
                }

                return(new { Pages = allContentItems, Blogs = blogs });
            });

            workContext.Pages = new MutablePagedList <ContentItem>(staticContents.Pages.Where(x => x.Language.IsInvariant || x.Language == workContext.CurrentLanguage));
            workContext.Blogs = new MutablePagedList <Blog>(staticContents.Blogs.Where(x => x.Language.IsInvariant || x.Language == workContext.CurrentLanguage));

            // Initialize blogs search criteria
            workContext.CurrentBlogSearchCritera = new BlogSearchCriteria(workContext.QueryString);

            //Pricelists
            var pricelistCacheKey = string.Join("-", "EvaluatePriceLists", workContext.CurrentStore.Id, workContext.CurrentCustomer.Id);

            workContext.CurrentPricelists = await CacheManager.GetAsync(pricelistCacheKey, "ApiRegion", async() =>
            {
                var evalContext = new pricingModel.PriceEvaluationContext
                {
                    StoreId    = workContext.CurrentStore.Id,
                    CatalogId  = workContext.CurrentStore.Catalog,
                    CustomerId = workContext.CurrentCustomer.Id,
                    Quantity   = 1
                };

                var pricingModuleApi = Container.Resolve <IPricingModuleApiClient>();
                var pricingResult    = await pricingModuleApi.PricingModule.EvaluatePriceListsAsync(evalContext);
                return(pricingResult.Select(p => p.ToPricelist(workContext.AllCurrencies, workContext.CurrentLanguage)).ToList());
            });

            // Vendors with their products
            workContext.Vendors = new MutablePagedList <Vendor>((pageNumber, pageSize, sortInfos) =>
            {
                var catalogSearchService = Container.Resolve <ICatalogSearchService>();
                var customerService      = Container.Resolve <ICustomerService>();
                var vendors = customerService.SearchVendors(null, pageNumber, pageSize, sortInfos);

                foreach (var vendor in vendors)
                {
                    vendor.Products = new MutablePagedList <Product>((pageNumber2, pageSize2, sortInfos2) =>
                    {
                        var criteria = new ProductSearchCriteria
                        {
                            VendorId      = vendor.Id,
                            PageNumber    = pageNumber2,
                            PageSize      = pageSize2,
                            ResponseGroup = ItemResponseGroup.ItemSmall,
                            SortBy        = SortInfo.ToString(sortInfos2),
                        };
                        var searchResult = catalogSearchService.SearchProducts(criteria);
                        return(searchResult.Products);
                    });
                }

                return(vendors);
            });
        }