Пример #1
0
        public CheckoutOrderInfo()
        {
            cart           = new Cart();
            appliedCoupons = new List <CheckoutCouponInfo>();

            BillingAddress = new AddressInfo();
            BillingAddress.PropertyChanged          += BillingAddress_PropertyChanged;
            BillingAddress.EnablePropertyChangeEvent = true;

            ShipToBillingAddress = null;

            ShippingAddress = new AddressInfo();
            //ShippingAddress.PropertyChanged += ShippingAddress_PropertyChanged;
            //ShippingOption = new ShippingOption();
            ShippingRate = new ShippingRate();

            CreditCard      = new CreditCardInfo();
            PaymentProvider = PaymentProviderName.UNKNOWN;
            PayPalVariables = new Dictionary <string, string>();

            SubTotal       = 0;
            DiscountAmount = 0;
            //ShippingAmount = 0;
            TaxAmount = 0;
            Total     = 0;

            OrderNotes = String.Empty;
        }
Пример #2
0
        public void AddProductToCart(int productId, int productQty, string jsonProductFieldData)
        {
            //UpdateCartItemInCart(null, productId, productQty, true, jsonProductFieldData);

            DataModel.Cart cart = null;

            using (esTransactionScope transaction = new esTransactionScope())
            {
                cart = GetCartFromDatabase(true);

                CartItemCollection cartItemCollection = cart.CartItemCollectionByCartId;
                List <CartItem>    cartItems          = cartItemCollection.ToList();
                int index = cartItems.FindIndex(ci => (ci.ProductId.Value == productId) && (ci.ProductFieldData == jsonProductFieldData));
                if (index >= 0)
                {
                    // product is in the cart
                    if (productQty <= 0)
                    {
                        // remove from cart
                        cartItemCollection[index].MarkAsDeleted();
                    }
                    else
                    {
                        // add/update quantity
                        cartItemCollection[index].Quantity += productQty;

                        // update ProductFieldData
                        if (!string.IsNullOrEmpty(jsonProductFieldData))
                        {
                            cartItemCollection[index].ProductFieldData = jsonProductFieldData;
                        }
                    }
                }
                else if (productQty > 0)
                {
                    // add to cart
                    CartItem newItem = cartItemCollection.AddNew();
                    newItem.ProductId        = productId;
                    newItem.Quantity         = productQty;
                    newItem.ProductFieldData = jsonProductFieldData;
                }

                //---- update some cart fields too...
                if (storeContext.UserId.HasValue)
                {
                    cart.UserId = storeContext.UserId.Value;
                }

                cart.Save();

                transaction.Complete();
            }

            //return cart;
        }
Пример #3
0
        public void RemoveCartItemFromCart(int cartItemId)
        {
            //UpdateCartItemInCart(cartItemId, null, 0, false, string.Empty);

            DataModel.Cart cart = GetCartFromDatabase(false);

            CartItemCollection cartItemCollection = cart.CartItemCollectionByCartId;
            CartItem           toDelete           = cartItemCollection.FindByPrimaryKey(cartItemId);

            if (toDelete != null)
            {
                toDelete.MarkAsDeleted();

                cart.Save();
            }
        }
Пример #4
0
        private DataModel.Cart GetCartFromDatabase(bool createIfNotExists)
        {
            DataModel.Cart cart = new DataModel.Cart();
            if (!cart.LoadByPrimaryKey(storeContext.CartId) && createIfNotExists)
            {
                // no cart in DB yet, create one...

                cart.Id      = storeContext.CartId;
                cart.StoreId = storeContext.CurrentStore.Id.Value;
                if (storeContext.UserId.HasValue)
                {
                    cart.UserId = storeContext.UserId.Value;
                }

                cart.Save();
            }

            return(cart);
        }
Пример #5
0
        public void UpdateCartItemQuantity(int cartItemId, int quantity)
        {
            //UpdateCartItemInCart(cartItemId, null, quantity, false, string.Empty);

            using (esTransactionScope transaction = new esTransactionScope())
            {
                DataModel.Cart cart = GetCartFromDatabase(false);

                CartItemCollection cartItems = cart.CartItemCollectionByCartId;
                cartItems.Filter = cartItems.AsQueryable().Where(x => x.Id == cartItemId);
                //cartItems.Filter = CartItemMetadata.ColumnNames.Id + " = " + cartItemId;

                if (cartItems.Count > 0)
                {
                    // item is in the cart
                    if (quantity <= 0)
                    {
                        // remove from cart
                        cartItems[0].MarkAsDeleted();
                    }
                    else
                    {
                        cartItems[0].Quantity = quantity;
                    }
                }
                //cartItems.Filter = "";
                cartItems.Filter = null;

                //---- update some cart fields too...
                if (storeContext.UserId.HasValue)
                {
                    cart.UserId = storeContext.UserId.Value;
                }

                cart.Save();

                transaction.Complete();
            }
        }