public JsonNetResult CalculateAutoOrder(ManageAutoOrderViewModel model)
        {
            try
            {
                var calculateOrderResponse = Exigo.CalculateOrder(new OrderCalculationRequest
                {
                    Address           = model.AutoOrder.ShippingAddress,
                    ShipMethodID      = model.AutoOrder.ShipMethodID,
                    ReturnShipMethods = true,
                    Configuration     = Identity.Customer.Market.Configuration.AutoOrders,
                    CustomerID        = Identity.Customer.CustomerID,
                    Items             = model.AutoOrder.Details.Select(i => new ShoppingCartItem {
                        ItemCode = i.ItemCode, Quantity = i.Quantity
                    })
                });

                return(new JsonNetResult(new
                {
                    success = true,
                    shipmethods = calculateOrderResponse.ShipMethods.ToList()
                }));
            }
            catch (Exception ex)
            {
                return(new JsonNetResult(new
                {
                    success = false,
                    message = ex.Message
                }));
            }
        }
示例#2
0
        public ActionResult Index()
        {
            var model = new BackofficeSubscriptionsViewModel();

            // Get the customer's subscriptions
            model.Subscriptions = Exigo.GetCustomerSubscriptions(CurrentCustomerID).ToList();


            // If we have any expired subscriptions, we need to calculate how much they are going to cost to catch them up today
            if (model.Subscriptions.Where(c => c.SubscriptionID == Subscriptions.BackofficeFeatures).FirstOrDefault() == null || model.Subscriptions.Where(c => c.SubscriptionID == Subscriptions.BackofficeFeatures).Any(s => s.IsExpired))
            {
                var customer = Exigo.GetCustomer(Identity.Current.CustomerID);
                if (customer.CreatedDate >= DateTimeExtensions.ToCST(DateTime.Now.AddMinutes(-30)) && customer.CustomerTypeID == CustomerTypes.Associate)
                {
                    var cookie = new HttpCookie(GlobalSettings.Backoffices.MonthlySubscriptionCookieName);
                    cookie.Value   = "true";
                    cookie.Expires = DateTime.Now.AddMinutes(15);
                    HttpContext.Response.Cookies.Add(cookie);

                    return(RedirectToAction("Index", "Dashboard"));
                }
                // Set up our request to get the order totals on the subscriptions that are required
                var request = new OrderCalculationRequest();

                // We pull the customer's addresses first, if there are none we calculate with the corp address
                var customerAddresses = Exigo.GetCustomerAddresses(CurrentCustomerID);
                var address           = (customerAddresses.Count() > 0 && customerAddresses.Where(c => c.IsComplete == true).Count() > 0) ? customerAddresses.Where(c => c.IsComplete == true).FirstOrDefault() : GlobalSettings.Company.Address;

                // Find which subscriptions are expired and add the appropriate items to those where needed
                var itemsToCalculate = new List <ShoppingCartItem>();


                itemsToCalculate.Add(new ShoppingCartItem {
                    ItemCode = GlobalSettings.Backoffices.MonthlySubscriptionItemCode, Quantity = 1
                });


                model.PaymentMethods = Exigo.GetCustomerPaymentMethods(new GetCustomerPaymentMethodsRequest
                {
                    CustomerID = CurrentCustomerID,
                    ExcludeIncompleteMethods = true,
                    ExcludeInvalidMethods    = true
                });
                request.Configuration = OrderConfiguration;
                request.Address       = address;
                request.Items         = itemsToCalculate;

                request.ShipMethodID = OrderConfiguration.DefaultShipMethodID;
                //82774 Ivan S. 11/24/2016
                //The Commissions page was displaying an OOPS error when clicking on it, because
                //we were not passing in the CustomerID, and it was generating a null exception
                //Therefore I added this line of code:
                request.CustomerID      = Identity.Current.CustomerID;
                model.OrderCalcResponse = Exigo.CalculateOrder(request);
            }

            return(View(model));
        }
        public ActionResult FetchAutoOrderShipMethodModule(int autoorderid)
        {
            var autoorder = Exigo.OData().AutoOrders.Expand("Details")
                            .Where(a => a.CustomerID == Identity.Current.CustomerID)
                            .Where(a => a.AutoOrderID == autoorderid)
                            .First();

            var model = new AutoOrderShipMethodViewModel();

            model.AutoorderID = autoorderid;

            var address = new Address()
            {
                Address1 = autoorder.Address1,
                Address2 = autoorder.Address2,
                City     = autoorder.City,
                State    = autoorder.State,
                Zip      = autoorder.Zip,
                Country  = autoorder.Country
            };

            var shipmethods = Exigo.CalculateOrder(new OrderCalculationRequest
            {
                CustomerID    = Identity.Current.CustomerID, //20161129 #82854 DV. For BO there is not likely ever a reason to not have the customerID available to pass to the CalculateOrder method
                Address       = address,
                Configuration = Identity.Current.Market.Configuration.AutoOrders,
                Items         = autoorder.Details.Where(c => c.PriceTotal > 0).Select(c => new Item {
                    ItemCode = c.ItemCode, Quantity = c.Quantity, Price = c.PriceEach
                }).ToList(),
                ReturnShipMethods = true,
                ShipMethodID      = autoorder.ShipMethodID
            }).ShipMethods;

            if (shipmethods.Count() > 0)
            {
                foreach (var shipmethod in shipmethods)
                {
                    if (autoorder.ShipMethodID == shipmethod.ShipMethodID)
                    {
                        shipmethod.Selected = true;
                    }
                }

                model.ShipMethods = shipmethods;
            }
            else
            {
                model.Error = "We are having trouble calculating shipping for this order. Please double-check your shipping address or contact [email protected] for assistance";
            }

            string html = RenderPartialViewToString("displaytemplates/autoordershipmethod", model);

            return(new JsonNetResult(new
            {
                success = true,
                module = html
            }));
        }
示例#4
0
        public JsonNetResult UpdateItemSummary()
        {
            try
            {
                var model = new EnrollmentSummaryViewModel();
                var order = new OrderCalculationResponse();
                var hasShippingAddress = (PropertyBag.ShippingAddress != null && PropertyBag.ShippingAddress.IsComplete);
                var orderItems         = ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.Order || c.Type == ShoppingCartItemType.EnrollmentPack).ToList();
                var languageID         = Exigo.GetSelectedLanguageID();

                if (hasShippingAddress)
                {
                    model.IsCalculated = true;
                    order = Exigo.CalculateOrder(new OrderCalculationRequest
                    {
                        Configuration     = OrderConfiguration,
                        Items             = orderItems,
                        Address           = PropertyBag.ShippingAddress,
                        ShipMethodID      = PropertyBag.ShipMethodID,
                        ReturnShipMethods = true
                    });

                    model.Total    = order.Total;
                    model.Shipping = order.Shipping;
                    model.Tax      = order.Tax;
                }

                model.OrderItems               = Exigo.GetItems(ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.Order), OrderConfiguration, languageID);
                model.AutoOrderItems           = Exigo.GetItems(ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.AutoOrder), AutoOrderConfiguration, languageID);
                model.OrderEnrollmentPacks     = Exigo.GetItems(ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.EnrollmentPack), OrderPacksConfiguration, languageID);
                model.AutoOrderEnrollmentPacks = Exigo.GetItems(ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.EnrollmentAutoOrderPack), AutoOrderConfiguration, languageID);

                var autoOrderSubtotal     = model.AutoOrderItems.Sum(c => c.Price * c.Quantity);
                var autoOrderPackSubtotal = model.AutoOrderEnrollmentPacks.Sum(c => c.Price * c.Quantity);
                var orderSubtotal         = model.OrderItems.Sum(c => c.Price * c.Quantity);
                var orderPackSubtotal     = model.OrderEnrollmentPacks.Sum(c => c.Price * c.Quantity);
                model.OrderSubtotal     = (hasShippingAddress) ? order.Subtotal : (orderSubtotal + orderPackSubtotal);
                model.AutoOrderSubtotal = autoOrderPackSubtotal + autoOrderSubtotal;

                return(new JsonNetResult(new
                {
                    success = true,
                    orderitems = ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.Order),
                    autoorderitems = ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.AutoOrder),
                    html = this.RenderPartialViewToString("_EnrollmentSummary", model)
                }));
            }
            catch (Exception ex)
            {
                return(new JsonNetResult(new
                {
                    success = false,
                    error = ex.Message
                }));
            }
        }
        public JsonNetResult CalculateOrder(ShippingAddress shippingAddress, List <ShoppingCartItem> items, int shipMethodID = 0)
        {
            var configuration = OrderConfiguration;

            var response = Exigo.CalculateOrder(new OrderCalculationRequest
            {
                Address           = shippingAddress,
                Configuration     = configuration,
                Items             = items,
                ShipMethodID      = shipMethodID,
                ReturnShipMethods = true
            });

            return(new JsonNetResult(response));
        }
        public ActionResult ManageAutoOrder(int id)
        {
            var viewModel           = new ManageAutoOrderViewModel();
            var customerID          = Identity.Customer.CustomerID;
            var customer            = Exigo.GetCustomer(customerID);
            var autoOrder           = Exigo.GetCustomerAutoOrders(customerID, id).FirstOrDefault();
            var market              = GlobalSettings.Markets.AvailableMarkets.Where(c => c.Countries.Contains(Identity.Customer.Country)).FirstOrDefault();
            var configuration       = market.GetConfiguration().AutoOrders;
            var isExistingAutoOrder = id != 0;

            if (isExistingAutoOrder)
            {
                viewModel.AutoOrder           = autoOrder;
                viewModel.AutoOrder.StartDate = Exigo.GetNextAvailableAutoOrderStartDate(viewModel.AutoOrder.NextRunDate ?? DateTime.Now);

                // Fill in any blanks in the recipient
                viewModel.AutoOrder.ShippingAddress.FirstName  = GlobalUtilities.Coalesce(viewModel.AutoOrder.ShippingAddress.FirstName, customer.FirstName);
                viewModel.AutoOrder.ShippingAddress.MiddleName = GlobalUtilities.Coalesce(viewModel.AutoOrder.ShippingAddress.MiddleName, customer.MiddleName);
                viewModel.AutoOrder.ShippingAddress.LastName   = GlobalUtilities.Coalesce(viewModel.AutoOrder.ShippingAddress.LastName, customer.LastName);
                viewModel.AutoOrder.ShippingAddress.Company    = GlobalUtilities.Coalesce(viewModel.AutoOrder.ShippingAddress.Company, customer.Company);
                viewModel.AutoOrder.ShippingAddress.Email      = GlobalUtilities.Coalesce(viewModel.AutoOrder.ShippingAddress.Email, customer.Email);
                viewModel.AutoOrder.ShippingAddress.Phone      = GlobalUtilities.Coalesce(viewModel.AutoOrder.ShippingAddress.Phone, customer.PrimaryPhone, customer.SecondaryPhone, customer.MobilePhone);
            }
            else
            {
                var customerShippingAddress = customer.ShippingAddresses.Where(a => a.IsComplete && a.Country == Identity.Customer.Country).FirstOrDefault();

                viewModel.AutoOrder = new AutoOrder()
                {
                    FrequencyTypeID        = FrequencyTypes.Monthly,
                    CurrencyCode           = configuration.CurrencyCode,
                    AutoOrderPaymentTypeID = AutoOrderPaymentTypes.PrimaryCreditCardOnFile,
                    StartDate       = Exigo.GetNextAvailableAutoOrderStartDate(DateTime.Now),
                    ShippingAddress = (customerShippingAddress != null) ? customerShippingAddress : new ShippingAddress()
                    {
                        Country = Identity.Customer.Country
                    },
                    ShipMethodID = configuration.DefaultShipMethodID
                };

                viewModel.AutoOrder.ShippingAddress.Phone = GlobalUtilities.Coalesce(viewModel.AutoOrder.ShippingAddress.Phone, customer.PrimaryPhone, customer.SecondaryPhone, customer.MobilePhone);
                viewModel.UsePointAccount = false;
            }

            // Get Available Ship Methods, if we are managing an existing auto order
            if (isExistingAutoOrder)
            {
                var calculateOrderResponse = Exigo.CalculateOrder(new OrderCalculationRequest
                {
                    Address           = viewModel.AutoOrder.ShippingAddress,
                    ShipMethodID      = viewModel.AutoOrder.ShipMethodID,
                    ReturnShipMethods = true,
                    Configuration     = Identity.Customer.Market.Configuration.AutoOrders,
                    CustomerID        = Identity.Customer.CustomerID,
                    Items             = viewModel.AutoOrder.Details.Select(i => new ShoppingCartItem {
                        ItemCode = i.ItemCode, Quantity = i.Quantity
                    })
                });
                viewModel.AvailableShipMethods = calculateOrderResponse.ShipMethods.ToList();
            }
            else
            {
                // Give the View a default ship method for display only
                viewModel.AvailableShipMethods = new List <ShipMethod> {
                    new ShipMethod {
                        Price = 0, Selected = true, ShipMethodDescription = "---", ShipMethodID = 0
                    }
                };
            }

            InflateManageAutoOrderViewModel(customerID, market, configuration, ref viewModel);

            return(View(viewModel));
        }
示例#7
0
        public ActionResult Review()
        {
            var model      = EnrollmentViewModelFactory.Create <EnrollmentReviewViewModel>(PropertyBag);
            var languageID = Exigo.GetSelectedLanguageID();

            // Get the cart items
            var cartItems = ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.Order || c.Type == ShoppingCartItemType.EnrollmentPack).ToList();

            model.Items = Exigo.GetItems(ShoppingCart.Items, OrderConfiguration, languageID).ToList();

            var calculationResult = Exigo.CalculateOrder(new OrderCalculationRequest
            {
                Configuration     = OrderConfiguration,
                Items             = cartItems,
                Address           = PropertyBag.ShippingAddress,
                ShipMethodID      = PropertyBag.ShipMethodID,
                ReturnShipMethods = true
            });

            model.Totals      = calculationResult;
            model.ShipMethods = calculationResult.ShipMethods;


            // Set the default ship method
            var shipMethodID = 0;

            if (PropertyBag.ShipMethodID != 0)
            {
                shipMethodID = PropertyBag.ShipMethodID;
            }
            else
            {
                shipMethodID             = OrderConfiguration.DefaultShipMethodID;
                PropertyBag.ShipMethodID = OrderConfiguration.DefaultShipMethodID;
                Exigo.PropertyBags.Update(PropertyBag);
            }

            if (model.ShipMethods != null)
            {
                if (model.ShipMethods.Any(c => c.ShipMethodID == shipMethodID))
                {
                    model.ShipMethods.First(c => c.ShipMethodID == shipMethodID).Selected = true;
                }
                else
                {
                    // If we don't have the ship method we're supposed to select,
                    // check the first one, save the selection and recalculate
                    model.ShipMethods.First().Selected = true;

                    PropertyBag.ShipMethodID = model.ShipMethods.First().ShipMethodID;
                    Exigo.PropertyBags.Update(PropertyBag);

                    var newCalculationResult = Exigo.CalculateOrder(new OrderCalculationRequest
                    {
                        Configuration     = OrderConfiguration,
                        Items             = cartItems,
                        Address           = PropertyBag.ShippingAddress,
                        ShipMethodID      = PropertyBag.ShipMethodID,
                        ReturnShipMethods = false
                    });

                    model.Totals = newCalculationResult;
                }
            }
            else
            {
            }


            return(View(model));
        }
示例#8
0
        public ActionResult Review()
        {
            var logicResult = LogicProvider.CheckLogic();

            if (!logicResult.IsValid)
            {
                return(logicResult.NextAction);
            }

            var model      = ShoppingViewModelFactory.Create <OrderReviewViewModel>(PropertyBag);
            var languageID = Exigo.GetSelectedLanguageID();


            #region Order Totals
            var beginningShipMethodID = PropertyBag.ShipMethodID;

            // If this is the first time coming to the page, and the property bag's ship method has not been set, then set it to the default for the configuration
            if (PropertyBag.ShipMethodID == 0)
            {
                PropertyBag.ShipMethodID = OrderConfiguration.DefaultShipMethodID;
                beginningShipMethodID    = PropertyBag.ShipMethodID;
                Exigo.PropertyBags.Update(PropertyBag);
            }


            // Get the cart items
            var cartItems = ShoppingCart.Items.ToList();
            model.Items = Exigo.GetItems(cartItems, OrderConfiguration, languageID).ToList();

            model.OrderTotals = Exigo.CalculateOrder(new OrderCalculationRequest
            {
                Configuration     = OrderConfiguration,
                Items             = cartItems,
                Address           = PropertyBag.ShippingAddress,
                ShipMethodID      = PropertyBag.ShipMethodID,
                ReturnShipMethods = true
            });
            model.ShipMethods = model.OrderTotals.ShipMethods;

            // Set the default ship method
            if (model.ShipMethods.Count() > 0)
            {
                if (model.ShipMethods.Any(c => c.ShipMethodID == PropertyBag.ShipMethodID))
                {
                    // If the property bag ship method ID exists in the results from order calc, set the correct result as selected
                    model.ShipMethods.First(c => c.ShipMethodID == PropertyBag.ShipMethodID).Selected = true;
                }
                else
                {
                    // If we don't have the ship method we're supposed to select, check the first one, save the selection and recalculate
                    model.ShipMethods.First().Selected = true;

                    // If for some reason the property bag is outdated and the ship method stored in it is not in the list, set the first result as selected and re-set the property bag's value
                    PropertyBag.ShipMethodID = model.ShipMethods.FirstOrDefault().ShipMethodID;
                    Exigo.PropertyBags.Update(PropertyBag);
                }
            }

            // If the original property bag value has changed from the beginning of the call, re-calculate the values
            if (beginningShipMethodID != PropertyBag.ShipMethodID)
            {
                var newCalculationResult = Exigo.CalculateOrder(new OrderCalculationRequest
                {
                    Configuration     = OrderConfiguration,
                    Items             = cartItems,
                    Address           = PropertyBag.ShippingAddress,
                    ShipMethodID      = PropertyBag.ShipMethodID,
                    ReturnShipMethods = false,
                    CustomerID        = Identity.Current.CustomerID
                });

                model.OrderTotals = newCalculationResult;
            }
            #endregion

            return(View(model));
        }