private void AddEventToCart(Event currentEvent)
        {
            CatalogManager catalog = new CatalogManager();
            Product        product = catalog.GetProduct(ProductId);

            HttpCookie     cookie        = HttpContext.Current.Request.Cookies.Get("shoppingCartId");
            OrdersManager  orderm        = new OrdersManager();
            OptionsDetails optionDetails = new OptionsDetails();

            // Check if shopping cart cookie exists in the current request.
            if (cookie == null)                                               //if it does not exist...
            {
                CartOrder  cartItem       = orderm.CreateCartOrder();         //create a new cart order
                var        shoppingcartid = cartItem.Id;                      // that id is equal to the cookie value
                HttpCookie Cookie         = new HttpCookie("shoppingCartId"); //create a new shopping cart cookie
                DateTime   now            = DateTime.Now;                     // Set the cookie value.
                Cookie.Value   = shoppingcartid.ToString();                   // Set the cookie expiration date.
                Cookie.Expires = now.AddYears(1);                             // Add the cookie.
                HttpContext.Current.Response.Cookies.Add(Cookie);             //give cart item currency of USD because it cannot be null
                cartItem.Currency = "USD";                                    //add the product to the cart
                orderm.AddToCart(cartItem, product, optionDetails, 1);        //save all changes
                orderm.SaveChanges();
            }
            else //if the cookie does exist
            {
                Guid      guid     = new Guid(cookie.Value.ToString()); //get the cookie value as the guid
                CartOrder cartItem = orderm.GetCartOrder(guid);        //get the cart based on the cookie value
                orderm.AddToCart(cartItem, product, optionDetails, 1); // add the item to the cart
                orderm.SaveChanges();                                  //save changes
            }
        }
示例#2
0
        public static void ProcessOrder()
        {
            CatalogManager catalogManager = CatalogManager.GetManager();
            OrdersManager  ordersManager  = OrdersManager.GetManager();

            Product product = catalogManager.GetProducts().Where(p => p.Title == ExistingProductTitle &&

                                                                 p.Status == ContentLifecycleStatus.Live).FirstOrDefault();


            CartOrder cartOrder = ordersManager.CreateCartOrder();

            cartOrder.OrderDate   = DateTime.Now;
            cartOrder.OrderStatus = OrderStatus.Pending;

            int orderNumber = ordersManager.GetOrders().LastOrDefault().OrderNumber + 1;

            cartOrder.OrderNumber   = orderNumber;
            cartOrder.OrderDate     = DateTime.Now;
            cartOrder.LastModified  = DateTime.Now;
            cartOrder.OrderAttempts = 0;

            var currency = Config.Get <EcommerceConfig>().DefaultCurrency;

            cartOrder.Currency = currency;

            Customer customer = ordersManager.GetCustomers().Where(c => c.CustomerFirstName == ExistingCustomerFirstName).FirstOrDefault();

            cartOrder.UserId = customer.Id;

            CartDetail orderDetail = new CartDetail();

            orderDetail.Id               = Guid.NewGuid();
            orderDetail.ProductId        = product.Id;
            orderDetail.Quantity         = 1;
            orderDetail.ProductAvailable = true;
            orderDetail.Price            = product.Price;
            orderDetail.IsShippable      = true;
            cartOrder.Details.Add(orderDetail);

            CheckoutState state = UpdateCheckoutState(customer, ordersManager, cartOrder);

            ordersManager.SaveChanges();

            EcommerceOrderCalculator calculator = new EcommerceOrderCalculator();

            calculator.CalculateAndSaveChanges(cartOrder);

            ordersManager.Checkout(cartOrder.Id, state, customer);
            ordersManager.SaveChanges();
            catalogManager.SaveChanges();
        }
示例#3
0
        public CartOrder GetShoppingCartForUser(OrdersManager ordersManager)
        {
            Guid      shoppingCartId = GetShoopingCartId();
            CartOrder shoppingCart   = ordersManager.TryGetCartOrder(shoppingCartId);

            if (shoppingCart == null)
            {
                shoppingCartId = Guid.NewGuid();
                shoppingCart   = ordersManager.CreateCartOrder(shoppingCartId, null);
            }

            return(shoppingCart);
        }
示例#4
0
        protected void AddToCartButton_Command(object sender, EventArgs e)
        {
            try
            {
                int quantity = 1;

                IShoppingCartAdder shoppingCartAdder   = new ShoppingCartAdder();
                string             defaultCurrencyName = Config.Get <EcommerceConfig>().DefaultCurrency;

                OptionsDetails optionsDetails = new OptionsDetails();

                decimal price = 0;
                if (!decimal.TryParse(DonationAmountDropDown.Value.ToString(), out price))
                {
                    price = Convert.ToDecimal(OtherAmountControl.Value);
                }

                this.Product.Price = price;
                shoppingCartAdder.AddItemToShoppingCart(this, this.OrdersManager, this.Product, optionsDetails, quantity, defaultCurrencyName);

                // Save the donation amount in custom field
                OrdersManager ordersManager = OrdersManager.GetManager();
                string        cookieKey     = EcommerceConstants.OrdersConstants.ShoppingCartIdCookieName;
                if (SystemManager.CurrentContext.IsMultisiteMode)
                {
                    cookieKey += SystemManager.CurrentContext.CurrentSite.Id;
                }

                HttpCookie shoppingCartCookie = HttpContext.Current.Request.Cookies[cookieKey];

                CartOrder cartOrder = null;
                if (shoppingCartCookie == null || !shoppingCartCookie.Value.IsGuid())
                {
                    // throw new ArgumentException("The shopping cart cookie does not exist or its value is not a valid string.");
                    cartOrder = ordersManager.CreateCartOrder();
                }
                else
                {
                    Guid cartOrderId = new Guid(shoppingCartCookie.Value);
                    cartOrder = ordersManager.GetCartOrder(cartOrderId);
                }

                if (cartOrder != null)
                {
                    PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(cartOrder);
                    PropertyDescriptor           property   = properties["DonationAmount"];

                    MetafieldPropertyDescriptor metaProperty = property as MetafieldPropertyDescriptor;

                    if (metaProperty != null)
                    {
                        metaProperty.SetValue(cartOrder, price);
                        ordersManager.SaveChanges();
                    }
                }

                this.AddedToCartMessage.ShowPositiveMessage("Donation added to cart");
            }
            catch (Exception ex)
            {
                this.AddedToCartMessage.ShowNegativeMessage("Failed to add donation to cart, try again");
            }
        }
        private void AddEventToCart(Event currentEvent)
        {
            CatalogManager catalog = new CatalogManager();
            Product product = catalog.GetProduct(ProductId);

            HttpCookie cookie = HttpContext.Current.Request.Cookies.Get("shoppingCartId");
            OrdersManager orderm = new OrdersManager();
            OptionsDetails optionDetails = new OptionsDetails();

            // Check if shopping cart cookie exists in the current request.
            if (cookie == null) //if it does not exist...
            {
                CartOrder cartItem = orderm.CreateCartOrder(); //create a new cart order
                var shoppingcartid = cartItem.Id;  // that id is equal to the cookie value
                HttpCookie Cookie = new HttpCookie("shoppingCartId");  //create a new shopping cart cookie
                DateTime now = DateTime.Now; // Set the cookie value.
                Cookie.Value = shoppingcartid.ToString(); // Set the cookie expiration date.
                Cookie.Expires = now.AddYears(1);// Add the cookie.
                HttpContext.Current.Response.Cookies.Add(Cookie);  //give cart item currency of USD because it cannot be null
                cartItem.Currency = "USD"; //add the product to the cart
                orderm.AddToCart(cartItem, product, optionDetails, 1); //save all changes
                orderm.SaveChanges();
            }
            else //if the cookie does exist
            {
                Guid guid = new Guid(cookie.Value.ToString()); //get the cookie value as the guid
                CartOrder cartItem = orderm.GetCartOrder(guid); //get the cart based on the cookie value
                orderm.AddToCart(cartItem, product, optionDetails, 1); // add the item to the cart
                orderm.SaveChanges(); //save changes
            }
        }