Cart Table Problem

Aug 18, 2011 at 7:32 AM

I have question regarding what the contents of the Cart Table should look like after an Order has been placed.

Currently, after an order is placed, the Cart Table shows up completely empty. I ran some debugging, and found that while the shopping cart is filled and you are on the CheckoutController, the Cart Table has itmes inside it. Once the transaction is complete the table has nothing in it.

Only thing I do know is that:

 

 

        public int CreateOrder(Order order)
        {
            decimal orderTotal = 0;

            var cartItems = GetCartItems();
            // Iterate over the items in the cart, 
            // adding the order details for each
            foreach (var item in cartItems)
            {
                var orderDetail = new OrderDetail
                {
                    ProductId = item.ProductId,
                    OrderId = order.OrderId,
                    UnitPrice = item.Product.ProductPrice,
                    Quantity = item.Count
                };
                // Set the order total of the shopping cart
                orderTotal += (item.Count * item.Product.ProductPrice);

                EchoJobsClassesDataContext.OrderDetails.Add(orderDetail);

            }
            // Set the order's total to the orderTotal count
            order.Total = orderTotal;

            // Save the order
            EchoJobsClassesDataContext.SaveChanges();
            // Empty the shopping cart
            EmptyCart();
            // Return the OrderId as the confirmation number
            return order.OrderId;
        }

At the EmptyCart();

This table is getting cleared of everything in it. What is wrong or right?

 

 

Aug 18, 2011 at 12:37 PM

@Casegi:

First off thanks for responding.

That is exactly what I was thinking, since in the tutorial there was a line which implicitly stated that the shopping cart would be emptied. In my thought process it was just a placeholder, but wanted to confirm, if there was any additional use, if we were to store the information. In other words how else could all that shopping cart information be used.

 

Coordinator
Sep 2, 2011 at 9:48 PM

Exactly, the cart is temporary storage until a user checks out. At that time, we clear the cart so if the user shops for new items they won't purchase the old items again.