Exemplo n.º 1
0
        public Order PlaceOrder(Shop shop, string cardNumber, string cardVerificationCode,
			ShoppingBasket shoppingBasket)
        {
            List<OrderItem> items = new List<OrderItem>();
            foreach (IShoppingBasketItem shoppingBasketItem in items)
            {
                ProductOrderItem orderItem = new ProductOrderItem
                {
                    WeakProductLink = shoppingBasketItem.Product.ID,
                    ProductTitle = shoppingBasketItem.Product.Title,
                    Quantity = shoppingBasketItem.Quantity,
                    Price = shoppingBasketItem.Product.CurrentPrice,
                    VATable = !(shoppingBasketItem.Product.VatZeroRated)
                };
                if (shoppingBasketItem.Variations != null)
                    foreach (Variation variation in shoppingBasketItem.Variations)
                        orderItem.Variations.Add(variation.VariationSet.Title + ": " + variation.Title);
                items.Add(orderItem);
            }

            Order order = PlaceOrder(shop, cardNumber, cardVerificationCode, shoppingBasket.DeliveryMethod,
                shoppingBasket.DeliveryMethod.Price, (Address) shoppingBasket.BillingAddress.Clone(true),
                (Address) (shoppingBasket.ShippingAddress ?? shoppingBasket.BillingAddress).Clone(true),
                (PaymentCard) shoppingBasket.PaymentCard.Clone(true), shoppingBasket.EmailAddress,
                shoppingBasket.TelephoneNumber, shoppingBasket.MobileTelephoneNumber,
                items, shoppingBasket.TotalDeliveryPrice, shoppingBasket.TotalPrice);

            // Clear shopping basket.
            _persister.Delete(shoppingBasket);

            return order;
        }
Exemplo n.º 2
0
        private ShoppingBasket GetCurrentShoppingBasketInternal(Shop shop, bool createBasket)
        {
            ShoppingBasket shoppingBasket = GetShoppingBasketFromCookie(shop);

            if (shoppingBasket != null)
            {
                // Check that products in shopping cart still exist, and if not remove those shopping cart items.
                List<ShoppingBasketItem> itemsToRemove = new List<ShoppingBasketItem>();
                foreach (ShoppingBasketItem item in shoppingBasket.GetChildren<ShoppingBasketItem>())
                    if (item.Product == null)
                        itemsToRemove.Add(item);
                foreach (ShoppingBasketItem item in itemsToRemove)
                    shoppingBasket.Children.Remove(item);
                _persister.Save(shoppingBasket);
            }
            else
            {
                shoppingBasket = new ShoppingBasket { Name = Guid.NewGuid().ToString() };
                if (shop.DeliveryMethods != null)
                    shoppingBasket.DeliveryMethod = shop.DeliveryMethods.GetChildren<DeliveryMethod>().FirstOrDefault();

                // don't always save basket to database
                // this will only happen when we add items to it
                if (createBasket)
                {
                    shoppingBasket.AddTo(shop.ShoppingBaskets);
                    _persister.Save(shoppingBasket);

                    HttpCookie cookie = new HttpCookie(GetCookieKey(shop), shoppingBasket.Name);
                    if (shop.PersistentShoppingBaskets)
                        cookie.Expires = DateTime.Now.AddYears(1);
                    _webContext.Response.Cookies.Add(cookie);
                }
            }

            return shoppingBasket;
        }