示例#1
0
        public async Task <IPagedList <ShoppingCart> > SearchCartsAsync(CartSearchCriteria criteria)
        {
            if (criteria == null)
            {
                throw new ArgumentNullException(nameof(criteria));
            }
            var cacheKey = CacheKey.With(GetType(), "SearchCartsAsync", criteria.GetCacheKey());

            return(await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(CartCacheRegion.CreateCustomerChangeToken(criteria.Customer?.Id));

                var resultDto = await _cartApi.SearchAsync(criteria.ToSearchCriteriaDto());
                var result = new List <ShoppingCart>();
                foreach (var cartDto in resultDto.Results)
                {
                    var currency = _workContextAccessor.WorkContext.AllCurrencies.FirstOrDefault(x => x.Equals(cartDto.Currency));
                    var language = string.IsNullOrEmpty(cartDto.LanguageCode) ? Language.InvariantLanguage : new Language(cartDto.LanguageCode);
                    var user = await _userManager.FindByIdAsync(cartDto.CustomerId) ?? criteria.Customer;
                    var cart = cartDto.ToShoppingCart(currency, language, user);
                    result.Add(cart);
                }
                return new StaticPagedList <ShoppingCart>(result, criteria.PageNumber, criteria.PageSize, resultDto.TotalCount.Value);
            }));
        }
        public async Task <ActionResult <ShoppingCartSearchResult> > SearchLists([FromBody] CartSearchCriteria searchCriteria)
        {
            if (searchCriteria == null)
            {
                searchCriteria = new CartSearchCriteria();
            }

            //restricting query to lists belongs to other customers
            searchCriteria.StoreId  = WorkContext.CurrentStore.Id;
            searchCriteria.Customer = WorkContext.CurrentUser;
            searchCriteria.Currency = WorkContext.CurrentCurrency;
            searchCriteria.Language = WorkContext.CurrentLanguage;

            var cartPagedList = await _cartService.SearchCartsAsync(searchCriteria);


            var result = new ShoppingCartSearchResult
            {
                Results    = cartPagedList.ToArray(),
                TotalCount = cartPagedList.TotalItemCount
            };

            var productIds = result.Results.SelectMany(x => x.Items).Select(x => x.ProductId).Distinct().ToArray();
            var products   = await _catalogService.GetProductsAsync(productIds, Model.Catalog.ItemResponseGroup.ItemSmall | Model.Catalog.ItemResponseGroup.ItemWithPrices | Model.Catalog.ItemResponseGroup.Inventory);

            foreach (var item in result.Results.SelectMany(x => x.Items).ToArray())
            {
                item.Product = products.FirstOrDefault(x => x.Id == item.ProductId);
            }

            return(result);
        }
示例#3
0
        public string AddCarts(O_CartGoods model)
        {
            O_CartGoods        Cartgoods      = new O_CartGoods();
            CartSearchCriteria SearchCriteria = new CartSearchCriteria();

            SearchCriteria.Flag    = 2;
            SearchCriteria.Creater = UserContext.Current.Id;
            var cars = this._icartService.SearchCart(SearchCriteria).Item1.FirstOrDefault();

            if (cars != null)
            {
                O_Cart Newcar = new O_Cart()
                {
                    Creater    = UserContext.Current.Id,
                    Flag       = 2,
                    CreateTime = DateTime.Now
                };
                this._icartService.Insert(Newcar);
                Cartgoods.CartId = Newcar.Id;
            }
            else
            {
                Cartgoods.CartId = cars.Id;
            }
            Cartgoods.GoodsCount = model.GoodsCount;
            Cartgoods.GoodsId    = model.GoodsId;
            Cartgoods.Price      = model.Price;
            this._icartGoodsService.Insert(Cartgoods);
            return("ok");
        }
示例#4
0
        public static cartDto.ShoppingCartSearchCriteria ToSearchCriteriaDto(this CartSearchCriteria criteria)
        {
            var result = new cartDto.ShoppingCartSearchCriteria
            {
                Name         = criteria.Name,
                Type         = criteria.Type,
                StoreId      = criteria.StoreId,
                CustomerId   = criteria.Customer?.Id,
                Currency     = criteria.Currency?.Code,
                LanguageCode = criteria.Language?.CultureName,
                Skip         = criteria.Start,
                Take         = criteria.PageSize,
                Sort         = criteria.Sort
            };

            return(result);
        }
        public async Task <ActionResult> GetListsWithProduct([FromBody] GetCartsWithProductRequest request)
        {
            var result = new List <string>();

            using (await AsyncLock.GetLockByKey(GetAsyncLockCartKey(WorkContext, "*", request.Type)).LockAsync())
            {
                var criteria = new CartSearchCriteria {
                    Type     = request.Type,
                    StoreId  = WorkContext.CurrentStore.Id,
                    Customer = WorkContext.CurrentUser,
                    Currency = WorkContext.CurrentCurrency,
                    Language = WorkContext.CurrentLanguage,
                    PageSize = int.MaxValue
                };
                var carts = await _cartService.SearchCartsAsync(criteria);

                result.AddRange(carts.Where(c => c.Items.Any(i => i.ProductId == request.ProductId)).Select(x => x.Name));
            }
            return(Json(result));
        }
示例#6
0
        public async Task <ActionResult <GenericSearchResult <ShoppingCart> > > SearchLists([FromBody] CartSearchCriteria searchCriteria)
        {
            if (searchCriteria == null)
            {
                searchCriteria = new CartSearchCriteria();
            }

            //restricting query to lists belongs to other customers
            searchCriteria.StoreId  = WorkContext.CurrentStore.Id;
            searchCriteria.Customer = WorkContext.CurrentUser;
            searchCriteria.Currency = WorkContext.CurrentCurrency;
            searchCriteria.Language = WorkContext.CurrentLanguage;

            var cartPagedList = await _cartService.SearchCartsAsync(searchCriteria);

            return(new GenericSearchResult <ShoppingCart>
            {
                Results = cartPagedList.ToArray(),
                TotalCount = cartPagedList.TotalItemCount
            });
        }
            /// <summary>
            /// Gets the latest modified shopping cart associated with the current user.
            /// </summary>
            /// <returns>
            /// The active shopping cart.
            /// </returns>
            public virtual async Task <Cart> GetActiveShoppingCart()
            {
                ManagerFactory      managerFactory      = Utilities.GetManagerFactory(this.EcommerceContext);
                ICartManager        cartManager         = managerFactory.GetManager <ICartManager>();
                QueryResultSettings queryResultSettings = new QueryResultSettings()
                {
                    Paging = new PagingInfo {
                        Skip = 0, Top = 1
                    }
                };
                SortingInfo sortingInfo = new SortingInfo();
                ObservableCollection <SortColumn> sortColumns = new ObservableCollection <SortColumn>();
                SortColumn sortColumn = new SortColumn();

                sortColumn.ColumnName   = "ModifiedDateTime";
                sortColumn.IsDescending = true;
                sortColumns.Add(sortColumn);
                sortingInfo.Columns         = sortColumns;
                queryResultSettings.Sorting = sortingInfo;
                CartSearchCriteria cartSearchCriteria = new CartSearchCriteria();

                cartSearchCriteria.CartTypeValue    = (int)CartType.Shopping;
                cartSearchCriteria.IncludeAnonymous = false;

                IEnumerable <Cart> carts = await cartManager.Search(cartSearchCriteria, queryResultSettings);

                Cart cart = carts.FirstOrDefault();

                if (cart != null)
                {
                    DateTime cartLastModifiedDate = cart.ModifiedDateTime.HasValue ? cart.ModifiedDateTime.Value.DateTime : DateTime.UtcNow;
                    if (this.HasCartExpired(cartLastModifiedDate))
                    {
                        cart = null;
                    }
                }

                return(cart);
            }
示例#8
0
 public Task <PagedResult <Cart> > Search(CartSearchCriteria cartSearchCriteria, QueryResultSettings queryResultSettings)
 {
     return(Task.Run(() => OrderManager.Create(CommerceRuntimeManager.Runtime).SearchCarts(cartSearchCriteria, queryResultSettings)));
 }