public void ShouldLoadCart()
        {
            // arrange
            var cartLineModel = new ShoppingCartItemModel
            {
                Id        = "CartLineId",
                Price     = 100500,
                Quantity  = 5,
                ProductId = 100500,
                LineTotal = 5555
            };

            var cartModel = new ShoppingCartModel
            {
                ShoppingItems = new[] { cartLineModel },
                Total         = 2345,
                CustomerGuid  = this.visitorId
            };

            this.client.GetCart(this.visitorId, Arg.Any <string>()).Returns(cartModel);

            // act
            this.processor.Process(this.args);

            // assert
            this.result.Cart.ExternalId.Should().Be(this.visitorId.ToString("B").ToUpper());
            this.result.Cart.Total.Amount.Should().Be(2345);

            var cartLine = this.result.Cart.Lines.Single();

            cartLine.ExternalCartLineId.Should().Be("CartLineId");
            cartLine.Product.ProductId.Should().Be("100500");
            cartLine.Product.Price.Amount.Should().Be(100500);
            cartLine.Quantity.Should().Be(5);
        }
        public void ShouldAddLinesToCart()
        {
            // arrange
            var inintialLineModel = new ShoppingCartItemModel();
            var initialCartModel  = new ShoppingCartModel {
                CustomerGuid = this.visitorId, ShoppingItems = new[] { inintialLineModel }
            };

            this.client.GetCart(this.visitorId, null).Returns(initialCartModel);

            var addedLineModel = new ShoppingCartItemModel {
                Id = "LineId2", LineTotal = 1010, Price = 50, ProductId = 100500, Quantity = 12
            };
            var resultingCartModel = new ShoppingCartModel {
                CustomerGuid = this.visitorId, Total = 2233, ShoppingItems = new[] { inintialLineModel, addedLineModel }
            };

            this.client.AddProduct(this.visitorId, "100500", 12).Returns(resultingCartModel);

            // act
            this.processor.Process(this.args);

            // assert
            this.result.Cart.Lines.Count.Should().Be(2);
            this.result.Cart.Total.Amount.Should().Be(2233);
            this.result.Cart.Lines.Should().Contain(cl =>
                                                    cl.ExternalCartLineId == "LineId2" &&
                                                    cl.Product.ProductId == "100500" &&
                                                    cl.Quantity == 12 &&
                                                    cl.Product.Price.Amount == 50 &&
                                                    cl.Total.Amount == 1010);
        }
예제 #3
0
        public void AddItem(BookModel book, int quantity)
        {
            ShoppingCartItemModel item = items.SingleOrDefault(b => b.Book.Id == book.Id);

            if (item == null)
            {
                items.Add(new ShoppingCartItemModel
                {
                    Book     = book,
                    Quantity = quantity
                });
                GetTotalCount();
                items[0].IsNotInStock = CheckStockQuantity(quantity, items[0]);
                if (items[0].IsNotInStock)
                {
                    items[0].Quantity = items[0].Book.QuantityInStock;
                    GetTotalCount();
                }
            }
            else
            {
                item.Quantity += quantity;
                GetTotalCount();
                item.IsNotInStock = CheckStockQuantity(quantity, item);
                if (item.IsNotInStock)
                {
                    item.Quantity = item.Book.QuantityInStock;
                    GetTotalCount();
                }
            }
        }
        public void ShouldGetWishlists()
        {
            // arrange
            var cartLineModel = new ShoppingCartItemModel
            {
                Id        = "2",
                ProductId = 41,
                Price     = 1300,
                Quantity  = 1,
                LineTotal = 1300
            };

            var cartModel = new ShoppingCartModel
            {
                CustomerGuid  = this.visitorId,
                CustomerEmail = "*****@*****.**",
                CustomerId    = 1,
                IsAnonymous   = false,
                TotalItems    = 1,
                Total         = 1300,
                ShoppingItems = new[] { cartLineModel }
            };

            this.client.GetWishlists().Returns(new[] { cartModel });

            // act
            this.processor.Process(this.args);

            // assert
            this.client.Received().GetWishlists();
            this.result.WishLists.Should().NotBeNull();
            this.result.WishLists.First().Should().NotBeNull();
            this.result.WishLists.First().CustomerId.Should().Be(cartModel.CustomerId.ToString());
            this.result.WishLists.First().ExternalId.Should().Be(cartModel.CustomerGuid.ToID().ToString().ToUpper());
        }
        public void ShouldUpdateLineOnCart()
        {
            // arrange
            var inintialLineModel = new ShoppingCartItemModel();
            var initialCartModel  = new ShoppingCartModel {
                ShoppingItems = new[] { inintialLineModel }
            };

            this.client.GetCart(this.visitorId, null).Returns(initialCartModel);

            var resultLineModel = new ShoppingCartItemModel {
                Id = "LineId2", ProductId = 100500, Price = 100, Quantity = 12
            };
            var resultCartModel = new ShoppingCartModel {
                ShoppingItems = new[] { resultLineModel }
            };

            this.client.UpdateQuantity(initialCartModel.CustomerGuid, "100500", 12).Returns(resultCartModel);

            // act
            this.processor.Process(this.args);

            // assert
            var line = this.result.Cart.Lines.Single();

            line.ExternalCartLineId.Should().Be("LineId2");
            line.Product.ProductId.Should().Be("100500");
            line.Product.Price.Amount.Should().Be(100);
            line.Quantity.Should().Be(12);
        }
예제 #6
0
        public ShoppingCartItem GetShoppingCartItem(ShoppingCartItemModel model, string vendorId)
        {
            var product = _productService.getProductById(model.ProductId);

            if (product == null)
            {
                throw new NullReferenceException(nameof(product));
            }
            var user = _userService.getIdentityUserByUserNameOrPhoneNumber(userName: vendorId);

            if (user == null)
            {
                throw new NullReferenceException(nameof(user));
            }
            var ShoppingCart = new ShoppingCartItem
            {
                AttributeXml = model.AttributeXml,
                CreatedOn    = DateTime.UtcNow,
                CustomerId   = user.Id,
                Subtotal     = model.Subtotal,
                ProductId    = model.ProductId,
                Quantity     = model.Quantity,
                UpdatedOn    = DateTime.UtcNow,
                VendorId     = user.Id,
                isSelected   = model.isSelected
            };

            return(ShoppingCart);
        }
예제 #7
0
        public async Task <IActionResult> GetCartDetails(string customerId)
        {
            var customer = await _customerService.GetCustomerById(customerId);

            var cart  = customer.ShoppingCartItems.Where(x => x.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();
            var items = new List <ShoppingCartItemModel>();

            foreach (var sci in cart)
            {
                var store = await _storeService.GetStoreById(sci.StoreId);

                var product = await _productService.GetProductById(sci.ProductId);

                var sciModel = new ShoppingCartItemModel {
                    Id            = sci.Id,
                    Store         = store != null ? store.Shortcut : "Unknown",
                    ProductId     = sci.ProductId,
                    Quantity      = sci.Quantity,
                    ProductName   = product.Name,
                    AttributeInfo = await _productAttributeFormatter.FormatAttributes(product, sci.AttributesXml, customer),
                    UnitPrice     = _priceFormatter.FormatPrice((await _taxService.GetProductPrice(product, (await _priceCalculationService.GetUnitPrice(sci, product)).unitprice)).productprice),
                    Total         = _priceFormatter.FormatPrice((await _taxService.GetProductPrice(product, (await _priceCalculationService.GetSubTotal(sci, product)).subTotal)).productprice),
                    UpdatedOn     = _dateTimeHelper.ConvertToUserTime(sci.UpdatedOnUtc, DateTimeKind.Utc)
                };
                items.Add(sciModel);
            }
            var gridModel = new DataSourceResult {
                Data  = items,
                Total = cart.Count
            };

            return(Json(gridModel));
        }
예제 #8
0
        public ActionResult GetWishlistDetails(int customerId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCurrentCarts))
            {
                return(AccessDeniedView());
            }

            var customer = _customerService.GetCustomerById(customerId);
            var cart     = customer.ShoppingCartItems.Where(x => x.ShoppingCartType == ShoppingCartType.Wishlist).ToList();

            var gridModel = new DataSourceResult
            {
                Data = cart.Select(sci =>
                {
                    decimal taxRate;
                    var store    = _storeService.GetStoreById(sci.StoreId);
                    var sciModel = new ShoppingCartItemModel
                    {
                        Id            = sci.Id,
                        Store         = store != null ? store.Name : "Unknown",
                        ProductId     = sci.ProductId,
                        Quantity      = sci.Quantity,
                        ProductName   = sci.Product.Name,
                        AttributeInfo = _productAttributeFormatter.FormatAttributes(sci.Product, sci.AttributesXml, sci.Customer),
                        UnitPrice     = _priceFormatter.FormatPrice(_taxService.GetProductPrice(sci.Product, _priceCalculationService.GetUnitPrice(sci), out taxRate)),
                        Total         = _priceFormatter.FormatPrice(_taxService.GetProductPrice(sci.Product, _priceCalculationService.GetSubTotal(sci), out taxRate)),
                        UpdatedOn     = _dateTimeHelper.ConvertToUserTime(sci.UpdatedOnUtc, DateTimeKind.Utc)
                    };
                    return(sciModel);
                }),
                Total = cart.Count
            };

            return(Json(gridModel));
        }
예제 #9
0
        private List <ShoppingCartItemModel> GetCartItemModels(ShoppingCartType cartType, Customer customer)
        {
            decimal taxRate;
            var     cart   = customer.GetCartItems(cartType);
            var     stores = Services.StoreService.GetAllStores().ToDictionary(x => x.Id, x => x);

            var result = cart.Select(sci =>
            {
                stores.TryGetValue(sci.Item.StoreId, out var store);

                var model = new ShoppingCartItemModel
                {
                    Id                   = sci.Item.Id,
                    Store                = store?.Name?.NaIfEmpty(),
                    ProductId            = sci.Item.ProductId,
                    Quantity             = sci.Item.Quantity,
                    ProductName          = sci.Item.Product.GetLocalized(x => x.Name),
                    ProductTypeName      = sci.Item.Product.GetProductTypeLabel(Services.Localization),
                    ProductTypeLabelHint = sci.Item.Product.ProductTypeLabelHint,
                    UnitPrice            = _priceFormatter.FormatPrice(_taxService.GetProductPrice(sci.Item.Product, _priceCalculationService.GetUnitPrice(sci, true), out taxRate)),
                    Total                = _priceFormatter.FormatPrice(_taxService.GetProductPrice(sci.Item.Product, _priceCalculationService.GetSubTotal(sci, true), out taxRate)),
                    UpdatedOn            = _dateTimeHelper.ConvertToUserTime(sci.Item.UpdatedOnUtc, DateTimeKind.Utc)
                };

                return(model);
            });

            return(result.ToList());
        }
예제 #10
0
        public IActionResult GetCartDetails(string customerId)
        {
            var customer = _customerService.GetCustomerById(customerId);
            var cart     = customer.ShoppingCartItems.Where(x => x.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();

            var gridModel = new DataSourceResult
            {
                Data = cart.Select(sci =>
                {
                    decimal taxRate;
                    var store    = _storeService.GetStoreById(sci.StoreId);
                    var product  = EngineContext.Current.Resolve <IProductService>().GetProductById(sci.ProductId);
                    var sciModel = new ShoppingCartItemModel
                    {
                        Id            = sci.Id,
                        Store         = store != null ? store.Name : "Unknown",
                        ProductId     = sci.ProductId,
                        Quantity      = sci.Quantity,
                        ProductName   = product.Name,
                        AttributeInfo = _productAttributeFormatter.FormatAttributes(product, sci.AttributesXml, customer),
                        UnitPrice     = _priceFormatter.FormatPrice(_taxService.GetProductPrice(product, _priceCalculationService.GetUnitPrice(sci), out taxRate)),
                        Total         = _priceFormatter.FormatPrice(_taxService.GetProductPrice(product, _priceCalculationService.GetSubTotal(sci), out taxRate)),
                        UpdatedOn     = _dateTimeHelper.ConvertToUserTime(sci.UpdatedOnUtc, DateTimeKind.Utc)
                    };
                    return(sciModel);
                }),
                Total = cart.Count
            };

            return(Json(gridModel));
        }
예제 #11
0
        public void ShouldRemoveCartLine()
        {
            // arrange
            var inintialLineModel = new ShoppingCartItemModel();
            var initialCartModel  = new ShoppingCartModel {
                CustomerGuid = this.visitorId, ShoppingItems = new[] { inintialLineModel }
            };

            this.client.GetCart(this.visitorId, null).Returns(initialCartModel);

            var resultLineModel = new ShoppingCartItemModel {
                Id = "LineId2", LineTotal = 1010, Price = 50, ProductId = 100500, Quantity = 12
            };
            var resultingCartModel = new ShoppingCartModel {
                Total = 2233, ShoppingItems = new[] { resultLineModel }
            };

            this.client.RemoveProduct(this.visitorId, "100500").Returns(resultingCartModel);

            // act
            this.processor.Process(this.args);

            // assert
            var line = this.result.Cart.Lines.Single();

            line.ExternalCartLineId.Should().Be("LineId2");
            line.Product.ProductId.Should().Be("100500");
            line.Product.Price.Amount.Should().Be(50);
            line.Quantity.Should().Be(12);
        }
예제 #12
0
        public ActionResult MobileFlyoutWrapper()
        {
            if (Session[OnlineShop.Common.CommonConstants.USER_SESSION] != null)
            {
                var customerSession  = (OnlineShop.Common.UserLogin)Session[OnlineShop.Common.CommonConstants.USER_SESSION];
                var customer         = new CustomerDao().GetCustomerById(Convert.ToInt32(customerSession.UserId));
                var listShoppingCart = new List <ShoppingCartItemModel>();

                foreach (var item in customer.ShoppingCartItems)
                {
                    if (item.ShoppingCartTypeId == 1)
                    {
                        var shoppingCartItem = new ShoppingCartItemModel();
                        shoppingCartItem.Product            = item.Product;
                        shoppingCartItem.Quantity           = item.Quantity;
                        shoppingCartItem.ShoppingCartTypeId = item.ShoppingCartTypeId;
                        listShoppingCart.Add(shoppingCartItem);
                    }
                }
                return(PartialView(listShoppingCart));
            }
            else
            {
                var shoppingCart     = Session[OnlineShop.Common.CommonConstants.ShoppingCartSession];
                var listShoppingCart = new List <ShoppingCartItemModel>();
                if (shoppingCart != null)
                {
                    listShoppingCart = (List <ShoppingCartItemModel>)shoppingCart;
                }
                return(PartialView(listShoppingCart));
            }
        }
예제 #13
0
        public IActionResult Cart(PaymentModel paymentModel = null)
        {
            var userId = HttpContext.User.Claims.FirstOrDefault(k => k.Type == ClaimTypes.Name).Value;
            var user   = _userService.GetUserById(userId);
            List <ShoppingCartItemModel> model = new List <ShoppingCartItemModel>();

            if (user.Cart.Count > 0)
            {
                var products = _productService.GetProductsById(user.Cart.Select(k => k.Id).ToList());
                foreach (var sci in user.Cart)
                {
                    ShoppingCartItemModel item = new ShoppingCartItemModel();
                    var product = products.Where(k => k.Id == sci.Id).FirstOrDefault();
                    if (product != null)
                    {
                        item.Name     = product.Name;
                        item.Quantity = sci.Quantity;
                        item.ImageUrl = product.GetPath();
                        item.Price    = product.Price;
                        model.Add(item);
                    }
                }
            }
            if (model == null)
            {
                paymentModel = new PaymentModel();
            }
            paymentModel.Items = model;
            return(View(paymentModel));
        }
예제 #14
0
        public void UpdateCart(ShoppingCartItemModel cart)
        {
            var entity  = cart.MapTo <ShoppingCartItem>();
            var product = _productService.GetProductById(entity.ProductId);

            entity.SpecialPrice              = product.SpecialPrice;
            entity.SpecialPriceEndDateTime   = product.SpecialPriceEndDateTime;
            entity.SpecialPriceStartDateTime = product.SpecialPriceStartDateTime;
            entity.Price = product.Price;
            _cartService.UpdateCart(entity);
        }
        public static ShoppingCartItem ToEntity(this ShoppingCartItemModel shoppingCartItemModel)
        {
            ShoppingCartItem shoppingCartItem = new ShoppingCartItem()
            {
                Id         = shoppingCartItemModel.Id,
                CustomerId = shoppingCartItemModel.CustomerId,
                ProductId  = shoppingCartItemModel.ProductId,
                Quantity   = shoppingCartItemModel.Quantity
            };

            return(shoppingCartItem);
        }
예제 #16
0
        public bool CheckStockQuantity(int quantity, ShoppingCartItemModel item)
        {
            int bookInCart = GetTotalBookInCart(item.Book.ISBN);

            quantity += bookInCart;

            if (item.Book.QuantityInStock < quantity)
            {
                return(true);
            }

            return(false);
        }
예제 #17
0
        public IActionResult AddItemToCart(ShoppingCartItemModel model)
        {
            var product = _productService.getProductById(model.ProductId);

            if (product == null)
            {
                throw new NullReferenceException(nameof(product));
            }
            var shoppingCart = _orderModelFactory.GetShoppingCartItem(model, User.Identity.Name);

            _orderService.InsertShoppingCartItem(shoppingCart);
            return(Json(new { result = "Product added to the cart.", url = Url.Action("index", "home") }));
        }
 public HttpStatusCode Put([FromBody] ShoppingCartItemModel shoppingCartItemModel)
 {
     try
     {
         ShoppingCartItem shoppingCartItem = shoppingCartItemModel.ToEntity();
         _shoppingCartItemService.UpdateProductQuantity(shoppingCartItem);
         return(HttpStatusCode.OK);
     }
     catch (Exception ex)
     {
         return(HttpStatusCode.InternalServerError);
     }
 }
        /// <summary>
        /// Prepare paged shopping cart item list model
        /// </summary>
        /// <param name="searchModel">Shopping cart item search model</param>
        /// <param name="customer">Customer</param>
        /// <returns>Shopping cart item list model</returns>
        public virtual ShoppingCartItemListModel PrepareShoppingCartItemListModel(ShoppingCartItemSearchModel searchModel, Customer customer)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (customer == null)
            {
                throw new ArgumentNullException(nameof(customer));
            }

            //get shopping cart items
            var items = customer.ShoppingCartItems.Where(item => item.ShoppingCartType == searchModel.ShoppingCartType).ToList();

            //prepare list model
            var model = new ShoppingCartItemListModel
            {
                Data = items.PaginationByRequestModel(searchModel).Select(item =>
                {
                    //fill in model values from the entity
                    var itemModel = new ShoppingCartItemModel
                    {
                        Id          = item.Id,
                        ProductId   = item.ProductId,
                        Quantity    = item.Quantity,
                        ProductName = item.Product?.Name
                    };

                    //convert dates to the user time
                    itemModel.UpdatedOn = _dateTimeHelper.ConvertToUserTime(item.UpdatedOnUtc, DateTimeKind.Utc);

                    //fill in additional values (not existing in the entity)
                    itemModel.Store         = _storeService.GetStoreById(item.StoreId)?.Name ?? "Deleted";
                    itemModel.AttributeInfo = _productAttributeFormatter.FormatAttributes(item.Product, item.AttributesXml, item.Customer);
                    var unitPrice           = _priceCalculationService.GetUnitPrice(item);
                    itemModel.UnitPrice     = _priceFormatter.FormatPrice(_taxService.GetProductPrice(item.Product, unitPrice, out var _));
                    var subTotal            = _priceCalculationService.GetSubTotal(item);
                    itemModel.Total         = _priceFormatter.FormatPrice(_taxService.GetProductPrice(item.Product, subTotal, out _));

                    return(itemModel);
                }),
                Total = items.Count
            };

            return(model);
        }

        #endregion
    }
        public static ShoppingCartItemList ToModels(this IEnumerable <ShoppingCartItem> shoppingCartItems)
        {
            ShoppingCartItemList shoppingCartItemList = new ShoppingCartItemList();

            foreach (ShoppingCartItem shoppingCartItem in shoppingCartItems)
            {
                ShoppingCartItemModel shoppingCartItemModel = shoppingCartItem.ToModel();
                shoppingCartItemList.ShoppingCartItems.Add(shoppingCartItemModel);
                shoppingCartItemList.TotalPrice += shoppingCartItemModel.CartItemPrice;
            }


            return(shoppingCartItemList);
        }
        public static ShoppingCartItemModel ToModel(this ShoppingCartItem shoppingCartItem)
        {
            ShoppingCartItemModel shoppingCartItemModel = new ShoppingCartItemModel()
            {
                Id           = shoppingCartItem.Id,
                Quantity     = shoppingCartItem.Quantity,
                ProductId    = shoppingCartItem.ProductId,
                ProductTitle = shoppingCartItem.Product.Title,
                ProductPrice = shoppingCartItem.Product.Price
            };

            shoppingCartItemModel.CartItemPrice = shoppingCartItem.Product.Price * shoppingCartItem.Quantity;

            return(shoppingCartItemModel);
        }
예제 #22
0
        public ActionResult AddToShoppingCart(int productId)
        {
            List <ShoppingCartItemModel> shoppingCarts = new List <ShoppingCartItemModel>();

            Product product = _productBusinessService.GetByIdWithDetails(productId);
            ShoppingCartItemModel shoppingCartItem = new ShoppingCartItemModel
            {
                Id       = product.Id,
                Name     = $"{product.BrandModel.Brand.Name} {product.BrandModel.Name}",
                Price    = product.Price,
                Quantity = 1,
            };

            if (HttpContext.Session.Get <List <ShoppingCartItemModel> >("ShoppingCart") != null)
            {
                shoppingCarts = HttpContext.Session.Get <List <ShoppingCartItemModel> >("ShoppingCart");
                if (shoppingCarts.Any(x => x.Id == productId))
                {
                    shoppingCarts.First(x => x.Id == productId).Quantity++;
                }
                else
                {
                    shoppingCarts.Add(shoppingCartItem);
                }
                HttpContext.Session.Set <List <ShoppingCartItemModel> >("ShoppingCart", shoppingCarts);
            }
            else
            {
                shoppingCarts.Add(shoppingCartItem);
                HttpContext.Session.Set <List <ShoppingCartItemModel> >("ShoppingCart", shoppingCarts);
            }

            if (HttpContext.Session.Get <UserContext>("UserContext") != default)
            {
                UserContext userContext = HttpContext.Session.Get <UserContext>("UserContext");

                List <ShoppingCart> currentShoppingCarts = shoppingCarts.Select(x => new ShoppingCart
                {
                    CustomerId = userContext.Id,
                    ProductId  = x.Id,
                    Quantity   = x.Quantity,
                    AddDate    = DateTime.Now
                }).ToList();

                _shoppingCartBusinessService.UpdateShoppingCarts(userContext.Id, currentShoppingCarts);
            }
            return(Json(new { Data = true }));
        }
        public async Task AddProductToCartAsync(ProductModel model, int quantity = 1, ShoppingCartType productType = ShoppingCartType.ShoppingCart)
        {
            var uri = $"{ApiUrlBase}/addProduct?productId={model.Id}&shoppingCartTypeId={(int)productType}&quantity={quantity}";

            await _requestProvider.PostAsync <ProductDetailsModel>(uri, null);

            await _customerService.CreateOrUpdateShoppingCartItems();

            var product = new ShoppingCartItemModel
            {
                ProductId          = model.Id,
                ShoppingCartTypeId = (int)productType,
                Quantity           = quantity
            };

            App.CurrentCostumer.ShoppingCartItems.Add(product);

            bool categoriesPageExist = _navigationService.PageExist(new CategoriesPage());

            if (categoriesPageExist)
            {
                CategoriesPage.Page.RefreshToolbarItems();
            }

            bool categoryPageExist = _navigationService.PageExist(new CategoryPage());

            if (categoryPageExist)
            {
                CategoryPage.Page.RefreshToolbarItems();
            }

            bool productPageExist = _navigationService.PageExist(new ProductPage());

            if (productPageExist)
            {
                ProductPage.Page.RefreshToolbarItems();
            }

            var mainPage = Application.Current.MainPage as NavigationPage;

            if (mainPage != null)
            {
                var viewModel = mainPage.CurrentPage.BindingContext;
                var castModel = viewModel as BaseViewModel;
                castModel?.DisplayToastNotification(TranslateExtension.Translate("Mobile.Products.Added"));
            }
        }
예제 #24
0
        public IActionResult AddItems([FromBody] ShoppingCartItemModel itemToAdd)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            AddItemToShoppingCartCommand command = new AddItemToShoppingCartCommand
            {
                ProductId = itemToAdd.Product.Id,
                Quantity  = itemToAdd.Quantity,
                UserId    = MockConstants.CurrentUserId
            };

            serviceProcessor.Process(command);
            return(CreatedAtAction(nameof(BasketController.Get), MapShoppingCartToModel(command.Result)));
        }
예제 #25
0
        public void Edit(int id, int quantity)
        {
            ShoppingCartItemModel item = items.SingleOrDefault(b => b.Book.Id == id);

            if (item != null)
            {
                item.Quantity = quantity;
                GetTotalCount();
                item.IsNotInStock = CheckStockQuantity(quantity, item);

                if (item.IsNotInStock)
                {
                    item.Quantity = item.Book.QuantityInStock;
                    GetTotalCount();
                }
            }
        }
예제 #26
0
        public IActionResult RemoveItems([FromBody] ShoppingCartItemModel itemsToRemove)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            RemoveItemFromShoppingCartCommand command = new RemoveItemFromShoppingCartCommand
            {
                ProductId = itemsToRemove.Product.Id,
                Quantity  = itemsToRemove.Quantity,
                UserId    = MockConstants.CurrentUserId
            };

            serviceProcessor.Process(command);
            return(Ok(MapShoppingCartToModel(command.Result)));
        }
 public static CartLine ToObecCartLine([NotNull] this ShoppingCartItemModel model)
 {
     Assert.ArgumentNotNull(model, "model");
     return(new CartLine
     {
         ExternalCartLineId = model.Id,
         Product = new CartProduct {
             ProductId = model.ProductId.ToString(CultureInfo.InvariantCulture), Price = new Price {
                 Amount = model.Price
             }
         },
         Quantity = model.Quantity,
         Total = new Total {
             Amount = model.LineTotal
         }
     });
 }
예제 #28
0
        public void UpdateShoppingCartItem(ShoppingCartItemModel shoppingCartItemModel)
        {
            if (shoppingCartItemModel == null)
            {
                throw new NullReferenceException(nameof(shoppingCartItemModel));
            }
            var shoppingCart = GetShoppingCartById(shoppingCartItemModel.Id);

            if (shoppingCart == null)
            {
                throw new NullReferenceException(nameof(shoppingCart));
            }
            shoppingCart.Quantity   = shoppingCartItemModel.Quantity;
            shoppingCart.isSelected = shoppingCartItemModel.isSelected;
            _appDbContext.ShoppingCartItems.Update(shoppingCart);
            _userService.save();
        }
예제 #29
0
        public ActionResult GetCartDetails(int customerId)
        {
            var gridModel = new GridModel <ShoppingCartItemModel>();

            if (Services.Permissions.Authorize(StandardPermissionProvider.ManageOrders))
            {
                decimal taxRate;
                var     customer = _customerService.GetCustomerById(customerId);
                var     cart     = customer.GetCartItems(ShoppingCartType.ShoppingCart);

                gridModel.Data = cart.Select(sci =>
                {
                    var store = Services.StoreService.GetStoreById(sci.Item.StoreId);

                    var sciModel = new ShoppingCartItemModel
                    {
                        Id                   = sci.Item.Id,
                        Store                = store != null ? store.Name : "".NaIfEmpty(),
                        ProductId            = sci.Item.ProductId,
                        Quantity             = sci.Item.Quantity,
                        ProductName          = sci.Item.Product.Name,
                        ProductTypeName      = sci.Item.Product.GetProductTypeLabel(Services.Localization),
                        ProductTypeLabelHint = sci.Item.Product.ProductTypeLabelHint,
                        UnitPrice            = _priceFormatter.FormatPrice(_taxService.GetProductPrice(sci.Item.Product, _priceCalculationService.GetUnitPrice(sci, true), out taxRate)),
                        Total                = _priceFormatter.FormatPrice(_taxService.GetProductPrice(sci.Item.Product, _priceCalculationService.GetSubTotal(sci, true), out taxRate)),
                        UpdatedOn            = _dateTimeHelper.ConvertToUserTime(sci.Item.UpdatedOnUtc, DateTimeKind.Utc)
                    };

                    return(sciModel);
                });

                gridModel.Total = cart.Count;
            }
            else
            {
                gridModel.Data = Enumerable.Empty <ShoppingCartItemModel>();

                NotifyAccessDenied();
            }

            return(new JsonResult
            {
                Data = gridModel
            });
        }
예제 #30
0
        public void ShouldUpdateLinesOnWishlist()
        {
            // arrange
            var inintialLineModel = new ShoppingCartItemModel();
            var initialCartModel  = new ShoppingCartModel {
                ShoppingItems = new[] { inintialLineModel }
            };

            this.client.GetWishlist(this.visitorId).Returns(initialCartModel);

            this.client.UpdateQuantity(this.visitorId, "100500", 2).Returns(initialCartModel);

            // act
            this.processor.Process(this.args);

            // assert
            this.result.UpdatedLines.Count.Should().Be(1);
            this.result.UpdatedLines.First().Product.ProductId.Should().Be("100500");
            this.result.UpdatedLines.First().Quantity.Should().Be(2);
        }