public void AddToCart(AddToCartModel model) { int quantity = model.Quantity; ProductVariant productVariant = model.ProductVariant; var data = model.Data; var cart = _cartBuilder.BuildCart(); CartItem cartItem = _getExistingCartItem.GetExistingItem(cart, productVariant, data); if (cartItem != null) { cartItem.Quantity += quantity; _session.Transact(session => session.Update(cartItem)); } else { cartItem = new CartItem { Item = productVariant, Quantity = quantity, UserGuid = _getUserGuid.UserGuid, Data = data }; _session.Transact(session => session.Save(cartItem)); var cartItemData = cartItem.GetCartItemData(); cart.Items.Add(cartItemData); } }
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 cartItem = _getExistingCartItem.GetExistingItem(cart, item.Item, item.Data); if (cartItem != null) { cartItem.Quantity += item.Quantity; } else { cartItem = new CartItem { Item = item.Item, Quantity = item.Quantity, UserGuid = CurrentRequestData.UserGuid }; cart.Items.Add(cartItem.GetCartItemData()); } session.SaveOrUpdate(cartItem); session.Delete(item); } }); }
public List <PaypalShippingOption> Get(PaypalShippingInfo info) { CartModel cart = _paypalExpressCartLoader.GetCart(info.Token); if (cart == null) { return(new List <PaypalShippingOption>()); } _cartManager.SetShippingAddress(info.ToAddress(), cart.UserGuid); cart = _cartBuilder.BuildCart(cart.UserGuid); IOrderedEnumerable <IShippingMethod> orderedEnumerable = _shippingMethodUIService.GetEnabledMethods() .FindAll(method => method.CanBeUsed(cart)) .OrderBy(method => method.GetShippingTotal(cart)); List <PaypalShippingOption> paypalShippingOptions = orderedEnumerable.Select(x => new PaypalShippingOption { Amount = x.GetShippingTotal(cart), Default = false, InsuranceAmount = 0m, DisplayName = x.DisplayName, Label = string.Format("({0})", x.Name), TotalTax = cart.ItemTax }).ToList(); if (paypalShippingOptions.Any()) { paypalShippingOptions[0].Default = true; } return(paypalShippingOptions); }
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 EmptyBasketTests() { _cartModel = new CartModel(); Session.Transact(session => session.SaveOrUpdate(_productVariant)); _cartBuilder = A.Fake<ICartBuilder>(); A.CallTo(() => _cartBuilder.BuildCart()).Returns(_cartModel); _clearCartSessionKeys = A.Fake<IClearCartSessionKeys>(); _emptyBasket = new EmptyBasket(_cartBuilder, Session, _clearCartSessionKeys); }
public CartModel GetCart(string vendorTxCode) { var serializedTxCode = JsonConvert.SerializeObject(vendorTxCode); var sessionData = _session.QueryOver <SessionData>().Where(data => data.Key == CartManager.CurrentCartGuid && data.Data == serializedTxCode).SingleOrDefault(); return(sessionData == null ? null : _cartBuilder.BuildCart(sessionData.UserGuid)); }
public CartItemManagerTests() { _cartModel = new CartModel(); Session.Transact(session => session.SaveOrUpdate(_productVariant)); _getUserGuid = A.Fake <IGetUserGuid>(); _cartBuilder = A.Fake <ICartBuilder>(); A.CallTo(() => _cartBuilder.BuildCart()).Returns(_cartModel); _cartItemManager = new CartItemManager(_cartBuilder, Session, _getUserGuid); }
public CartItemManagerTests() { _cartModel = new CartModel(); Session.Transact(session => session.SaveOrUpdate(_productVariant)); _getUserGuid = A.Fake<IGetUserGuid>(); _cartBuilder = A.Fake<ICartBuilder>(); A.CallTo(() => _cartBuilder.BuildCart()).Returns(_cartModel); _cartItemManager = new CartItemManager(_cartBuilder, Session, _getUserGuid); }
public EmptyBasketTests() { _cartModel = new CartModel(); Session.Transact(session => session.SaveOrUpdate(_productVariant)); _cartBuilder = A.Fake <ICartBuilder>(); A.CallTo(() => _cartBuilder.BuildCart()).Returns(_cartModel); _clearCartSessionKeys = A.Fake <IClearCartSessionKeys>(); _emptyBasket = new EmptyBasket(_cartBuilder, Session, _clearCartSessionKeys); }
public CartModel GetCart(string token) { string serializedTxCode = JsonConvert.SerializeObject(token); SessionData sessionData = _session.QueryOver <SessionData>() .Where(data => data.Key == CartManager.CurrentPayPalExpressToken && data.Data == serializedTxCode) .SingleOrDefault(); return(sessionData == null ? null : _cartBuilder.BuildCart(sessionData.UserGuid)); }
public BasePaymentMethod SetPaymentMethod(string methodName) { _cartSessionManager.SetSessionValue(CurrentPaymentMethodKey, _getUserGuid.UserGuid, methodName, SessionDataTimeoutDefaults.PaymentInfo); var cart = _cartBuilder.BuildCart(); if (cart.CanShowPaymentMethod()) { return(cart.PaymentMethod); } return(null); }
public void Empty() { var cart = _cartBuilder.BuildCart(); foreach (CartItem item in cart.Items) { CartItem item1 = item; _session.Transact(session => session.Delete(item1)); } cart.Items.Clear(); _clearCartSessionKeys.Clear(); }
private CartModel GetCart(string orderId) { string serializedTxCode = JsonConvert.SerializeObject(orderId); SessionData sessionData = _session.QueryOver <SessionData>() .Where(data => data.Key == CartManager.CurrentCartGuid && data.Data == serializedTxCode) .SingleOrDefault(); if (sessionData != null) { CurrentRequestData.UserGuid = sessionData.UserGuid; return(_cartBuilder.BuildCart(sessionData.UserGuid)); } return(null); }
public void Empty() { var cart = _cartBuilder.BuildCart(); foreach (var item in cart.Items) { var item1 = _session.Get <CartItem>(item.Id); if (item1 != null) { _session.Transact(session => session.Delete(item1)); } } cart.Items.Clear(); _clearCartSessionKeys.Clear(); }