Ejemplo n.º 1
0
        public void LoadCart()
        {
            this.Cart = new ShoppingCart(this.UserName);


            //load up the cart
            //a cart is just an Order, marked with "NotCheckedOut"
            //the following factory method will retrieve the current Order
            //or create a new one
            var existingOrder = Order.FindCurrentOrCreateNew(this.UserName);

            if (existingOrder != null)
            {
                //get the items
                //pull the products first
                var skus = from items in existingOrder.OrderItems
                           select items.SKU;

                var products = from p in Product.All()
                               join o in OrderItem.All() on p.SKU equals o.SKU
                               where o.OrderID == existingOrder.OrderID
                               select p;

                foreach (var item in existingOrder.OrderItems)
                {
                    this.Cart.AddItem(products.SingleOrDefault(x => x.SKU == item.SKU), item.Quantity, item.DateAdded);
                }

                this.Cart.ShippingAddress = existingOrder.ShippingAddress;
                this.Cart.BillingAddress  = existingOrder.BillingAddress;
            }
        }
Ejemplo n.º 2
0
        public void Save()
        {
            bool shouldSave = false;
            //get the user's current, unchecked out order
            var order = Order.FindCurrentOrCreateNew(UserName);


            //save any address or shipping changes
            if (this.ShippingAddress != null)
            {
                order.ShippingAddressID = this.ShippingAddress.AddressID;
            }

            if (this.BillingAddress != null)
            {
                order.BillingAddressID = this.BillingAddress.AddressID;
                shouldSave             = true;
            }

            if (this.ShippingMethodID > 0)
            {
                order.ShippingAmount  = this.ShippingAmount;
                order.ShippingService = this.ShippingService;
            }

            //if any changes made... save
            if (order.IsDirty())
            {
                order.Save(order.UserName);
            }

            //save the items
            order.SaveItems(this.Items);
        }