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);
                }
            });
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
                }
            });
        }
Exemple #5
0
 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);
 }
Exemple #6
0
        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));
        }
Exemple #7
0
 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);
 }
Exemple #9
0
 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));
        }
Exemple #11
0
        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);
        }
Exemple #12
0
        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();
        }
Exemple #13
0
        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);
        }
Exemple #14
0
        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();
        }