private void UserLoggedIn(User user, Guid previousSession) { var itemsToCopy = _session.QueryOver<CartItem>().Where(item => item.UserGuid == previousSession).List(); var cart = _cartBuilder.BuildCart(); _session.Transact(session => { foreach (var item in itemsToCopy) { var existingItem = cart.Items.FirstOrDefault( cartItem => cartItem.Item.SKU == item.Item.SKU); if (existingItem != null) existingItem.Quantity += item.Quantity; else { existingItem = new CartItem { Item = item.Item, Quantity = item.Quantity, UserGuid = CurrentRequestData.UserGuid }; cart.Items.Add(existingItem); } session.SaveOrUpdate(existingItem); session.Delete(item); } }); }
public void Empty_RemovesItemsFromDB() { var cartItem = new CartItem { Item = _productVariant, Quantity = 1 }; _cartModel.Items.Add(cartItem); _emptyBasket.Empty(); Session.QueryOver<CartItem>().RowCount().Should().Be(0); }
public void CartItem_Saving_ShouldBeTheResultOfGetSaving() { A.CallTo(() => _productVariant.GetSaving(2)).Returns(20); var cartItem = new CartItem { Item = _productVariant, Quantity = 2 }; var saving = cartItem.Saving; saving.Should().Be(20); }
public void CartItem_Tax_ShouldBeResultOfGetTax() { A.CallTo(() => _productVariant.GetTax(2)).Returns(4); var cartItem = new CartItem { Item = _productVariant, Quantity = 2 }; var tax = cartItem.Tax; tax.Should().Be(4); }
public void Empty_RemovesItemsFromModel() { var cartItem = new CartItem { Item = _productVariant, Quantity = 1 }; _cartModel.Items.Add(cartItem); _emptyBasket.Empty(); _cartModel.Items.Should().BeEmpty(); }
public void CartItem_Price_ShouldBeTheResultOfGetPrice() { A.CallTo(() => _productVariant.GetPrice(2)).Returns(20); var cartItem = new CartItem { Item = _productVariant, Quantity = 2 }; var price = cartItem.Price; price.Should().Be(20); }
public void CartItemManager_Delete_ShouldRemoveCartItemFromModel() { var cartItem = new CartItem { Item = _productVariant, Quantity = 1 }; _cartModel.Items.Add(cartItem); _cartItemManager.Delete(cartItem); _cartModel.Items.Should().HaveCount(0); }
public void CartItem_PricePreTax_ShouldBePriceMinusTax() { A.CallTo(() => _productVariant.GetPrice(2)).Returns(24); A.CallTo(() => _productVariant.GetTax(2)).Returns(4); var cartItem = new CartItem { Item = _productVariant, Quantity = 2 }; var pricePreTax = cartItem.PricePreTax; pricePreTax.Should().Be(20); }
public void CartItemManager_Delete_ShouldRemoveCartItemFromDb() { var cartItem = new CartItem { Item = _productVariant, Quantity = 1 }; Session.Transact(session => session.Save(cartItem)); _cartModel.Items.Add(cartItem); _cartItemManager.Delete(cartItem); Session.QueryOver<CartItem>().RowCount().Should().Be(0); }
public CanBuyStatus CanBuy(CartItem item) { var productVariant = item.Item; var quantity = item.Quantity; if (!_productStockChecker.IsInStock(productVariant)) return new OutOfStock(productVariant); var canOrderQuantityResult = _productStockChecker.CanOrderQuantity(productVariant, quantity); if (!canOrderQuantityResult.CanOrder) return new CannotOrderQuantity(productVariant, canOrderQuantityResult.StockRemaining); return new CanBuy(); }
public OrderLine GetOrderLine(CartItem item) { var options = string.Join(", ", item.Item.OptionValues.Select(value => value.FormattedValue)); var orderLine = new OrderLine { UnitPrice = item.UnitPrice, UnitPricePreTax = item.UnitPricePreTax, Weight = item.Weight, TaxRate = item.TaxRatePercentage, Tax = item.Tax, Quantity = item.Quantity, ProductVariant = item.Item, PricePreTax = item.PricePreTax, Price = item.Price, SKU = item.Item.SKU, Name = item.Item.FullName, Options = options, Discount = item.DiscountAmount, RequiresShipping = item.RequiresShipping, Data = item.Data }; if (item.IsDownloadable) { orderLine.IsDownloadable = true; orderLine.AllowedNumberOfDownloads = item.AllowedNumberOfDownloads; orderLine.DownloadExpiresOn = (item.AllowedNumberOfDaysForDownload.HasValue && item.AllowedNumberOfDaysForDownload > 0) ? CurrentRequestData.Now.AddDays( item.AllowedNumberOfDaysForDownload .GetValueOrDefault()) : (DateTime?)null; orderLine.NumberOfDownloads = 0; var fileByUrl = _fileService.GetFileByUrl(item.DownloadFileUrl); if (fileByUrl != null) { orderLine.DownloadFileUrl = fileByUrl.FileUrl; orderLine.DownloadFileContentType = fileByUrl.ContentType; orderLine.DownloadFileName = fileByUrl.FileName; } else { orderLine.DownloadFileUrl = item.DownloadFileUrl; } } return orderLine; }
public void AddToCart(AddToCartModel model) { int quantity = model.Quantity; ProductVariant productVariant = model.ProductVariant; var data = model.Data; var cart = _cartBuilder.BuildCart(); CartItem cartItem = GetExistingItem(cart, productVariant, data); if (cartItem != null) cartItem.Quantity += quantity; else { cartItem = new CartItem { Item = productVariant, Quantity = quantity, UserGuid = _getUserGuid.UserGuid, Data = data }; cart.Items.Add(cartItem); } _session.Transact(session => session.SaveOrUpdate(cartItem)); }
public void CartItem_TaxRatePercentage_ShouldReturnTheTaxRateInPercentage() { A.CallTo(() => _productVariant.TaxRatePercentage).Returns(20); var cartItem = new CartItem { Item = _productVariant, Quantity = 2 }; var taxRatePercentage = cartItem.TaxRatePercentage; taxRatePercentage.Should().Be(20); }
public void CartItem_GetDiscountAmount_IfNullDiscountIsPassedShouldBeZero() { var cartItem = new CartItem { Item = _productVariant, Quantity = 3 }; cartItem.SetDiscountInfo(0m); var discountAmount = cartItem.DiscountAmount; discountAmount.Should().Be(0); }
public void CartItem_Weight_ShouldBeWeightTimesQuantity() { A.CallTo(() => _productVariant.Weight).Returns(123); var cartItem = new CartItem { Item = _productVariant, Quantity = 3 }; var weight = cartItem.Weight; weight.Should().Be(369); }
public void UpdateQuantity(CartItem item, int quantity) { item.Quantity = quantity; _session.Transact(session => session.Update(item)); }
public void Delete(CartItem item) { var cart = _cartBuilder.BuildCart(); _session.Transact(session => session.Delete(item)); cart.Items.Remove(item); }