private void CleanupCart(MyHLShoppingCart cart)
        {
            if (PurchasingLimitProvider.RequirePurchasingLimits(cart.DistributorID, cart.CountryCode))
            {
                PurchasingLimitProvider.ReconcileAfterPurchase(cart, cart.DistributorID, Country);
            }

            if (null != HttpContext.Current)
            {
                var currentSession = SessionInfo.GetSessionInfo(cart.DistributorID, Locale);
                if (currentSession != null)
                {
                    if (!String.IsNullOrEmpty(currentSession.OrderNumber))
                    {
                        currentSession.OrderNumber                      = String.Empty;
                        currentSession.OrderMonthShortString            = string.Empty;
                        currentSession.OrderMonthString                 = string.Empty;
                        currentSession.ShippingMethodNameMX             = String.Empty;
                        currentSession.ShippingMethodNameUSCA           = String.Empty;
                        currentSession.ShoppingCart.CustomerOrderDetail = null;
                        // currentSession.CustomerPaymentSettlementApproved = false; Commented out for merge. Need to investigate
                        currentSession.CustomerOrderNumber = String.Empty;
                        currentSession.CustomerAddressID   = 0;
                    }
                }
                //Clear the order month session...
                HttpContext.Current.Session["OrderMonthDataSessionKey"] = null;
                SessionInfo.SetSessionInfo(cart.DistributorID, Locale, currentSession);
            }

            ShoppingCartProvider.UpdateInventory(cart, Country, Locale, true);
        }
        private void CleanupOrder(MyHLShoppingCart cart, string distributorId)
        {
            if (!IsPostBack)
            {
                if (PurchasingLimitProvider.RequirePurchasingLimits(distributorId, _country))
                {
                    PurchasingLimitProvider.ReconcileAfterPurchase(cart, distributorId, _country);
                }

                if (cart != null)
                {
                    // take out quantities from inventory
                    ShoppingCartProvider.UpdateInventory(cart, cart.CountryCode, cart.Locale, true);
                }

                cart.CloseCart();
            }
        }
Ejemplo n.º 3
0
        protected override void OnUnload(EventArgs e)
        {
            base.OnUnload(e);
            if (!IsPostBack)
            {
                try
                {
                    if (PurchasingLimitProvider.RequirePurchasingLimits(DistributorID, CountryCode))
                    {
                        PurchasingLimitProvider.ReconcileAfterPurchase(ShoppingCart, DistributorID, CountryCode);
                    }

                    var currentSession = SessionInfo.GetSessionInfo(DistributorID, Locale);
                    if (currentSession != null)
                    {
                        if (!String.IsNullOrEmpty(currentSession.OrderNumber))
                        {
                            ShoppingCart.OrderNumber              = currentSession.OrderNumber;
                            currentSession.OrderNumber            = String.Empty;
                            currentSession.OrderMonthShortString  = string.Empty;
                            currentSession.OrderMonthString       = string.Empty;
                            currentSession.ShippingMethodNameMX   = String.Empty;
                            currentSession.ShippingMethodNameUSCA = String.Empty;
                            if (currentSession.ShoppingCart != null)
                            {
                                currentSession.ShoppingCart.CustomerOrderDetail = null;
                            }
                            currentSession.CustomerOrderNumber = String.Empty;
                            currentSession.CustomerAddressID   = 0;
                            currentSession.ConfirmedAddress    = false;
                            currentSession.BRPF                  = String.Empty;
                            currentSession.OrderStatus           = SubmitOrderStatus.Unknown;
                            currentSession.HmsPricing            = false;
                            currentSession.LocalPaymentId        = string.Empty;
                            currentSession.TrackingUrl           = string.Empty;
                            currentSession.SelectedPaymentChoice = string.Empty;
                            if (null != currentSession.ShippingAddresses)
                            {
                                var customerAddress =
                                    currentSession.ShippingAddresses.Find(p => p.ID == currentSession.CustomerAddressID);
                                if (customerAddress != null)
                                {
                                    currentSession.ShippingAddresses.Remove(customerAddress);
                                }
                            }
                            currentSession.IsHAPMode = false;
                        }
                        currentSession.IsAPFOrderFromPopUp = false;
                    }
                    //Clear the order month session...
                    Session["OrderMonthDataSessionKey"] = null;
                    ResolveAPF();
                    InsertIntoMLMOverrideTable(currentSession);
                    SessionInfo.SetSessionInfo(DistributorID, Locale, currentSession);
                    RemoveDupCheckCookie();
                    closeCart();
                }
                catch (Exception ex)
                {
                    LoggerHelper.Error(
                        string.Format("Error in Confirm.aspx.cs : OnUnload error message:  {0}; \r\n Stack Info: {1}",
                                      ex.GetBaseException().Message, ex.GetBaseException().StackTrace));
                    closeCart();
                }
            }
        }
Ejemplo n.º 4
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            var _errors = new List <string>();

            if (ShoppingCart != null)
            {
                if (ShoppingCart.Totals == null)
                {
                    ShoppingCart.Calculate();
                }
                // Set the order
                var order = OrderCreationHelper.CreateOrderObject(ShoppingCart) as Order_V01;
                order.DistributorID       = DistributorID;
                order.CountryOfProcessing = CountryCode;
                order.ReceivedDate        = DateUtils.GetCurrentLocalTime(CountryCode);
                order.OrderMonth          = GetOrderMonthShortString();
                order.OrderCategory       =
                    (OrderCategoryType)
                    Enum.Parse(typeof(OrderCategoryType),
                               HLConfigManager.Configurations.DOConfiguration.HFFModalOrderType);
                order.Shipment = OrderProvider.CreateShippingInfo(CountryCode, ShoppingCart);
                var provider = (Page as ProductsBase).GetShippingProvider();
                (order.Shipment as ShippingInfo_V01).Address = ObjectMappingHelper.Instance.GetToOrder(provider.GetHFFDefaultAddress(ShoppingCart.DeliveryInfo.Address));
                order.Handling = OrderProvider.CreateHandlingInfo(CountryCode, string.Empty, ShoppingCart,
                                                                  order.Shipment as ShippingInfo_V01);
                List <Payment> payments = null;
                if (PaymentOptions != null)
                {
                    if (PaymentOptions.ValidateAndGetPayments(ObjectMappingHelper.Instance.GetToOrder(ShoppingCart.DeliveryInfo.Address.Address), out payments))
                    {
                        if (payments != null && payments.Count > 0)
                        {
                            order.Payments = new PaymentCollection();
                            order.Payments.AddRange((from p in payments select p).ToArray());
                        }

                        HLRulesManager.Manager.PerformTaxationRules(order, (Page as ProductsBase).Locale);

                        if (PurchasingLimitProvider.RequirePurchasingLimits(DistributorID, CountryCode))
                        {
                            if (order.PurchasingLimits == null)
                            {
                                var limits =
                                    PurchasingLimitProvider.GetCurrentPurchasingLimits(DistributorID);
                                if (null != limits)
                                {
                                    limits.PurchaseSubType = ShoppingCart.SelectedDSSubType;
                                    order.PurchasingLimits = limits;
                                    order.PurchaseCategory = limits.PurchaseType;
                                }
                            }
                        }

                        order = OrderProvider.PopulateLineItems(CountryCode, order, ShoppingCart) as Order_V01;
                        order.DiscountPercentage = (ShoppingCart.Totals as OrderTotals_V01).DiscountPercentage;
                        var theOrder = OrderProvider.CreateOrder(order, ShoppingCart, CountryCode);
                        List <FailedCardInfo> failedCards = null;
                        string error   = string.Empty;
                        string orderID = OrderProvider.ImportOrder(theOrder, out error, out failedCards,
                                                                   ShoppingCart.ShoppingCartID);

                        if (string.IsNullOrEmpty(error))
                        {
                            // TODO: how to get auth token
                            ShoppingCartProvider.UpdateShoppingCart(ShoppingCart,
                                                                    OrderProvider.SerializeOrder(theOrder, order,
                                                                                                 ShoppingCart,
                                                                                                 new Guid()),
                                                                    orderID, order.ReceivedDate);
                            if (string.IsNullOrEmpty(order.OrderID))
                            {
                                order.OrderID = orderID;
                                order.Pricing = ShoppingCart.Totals;
                            }
                            if (!String.IsNullOrEmpty(ShoppingCart.EmailAddress))
                            {
                                EmailHelper.SendEmail(ShoppingCart, order);
                            }

                            OrderSubmitted(order, orderID);

                            // Handling UI
                            lbOrderNumValue.Text = orderID;
                            divPayment.Attributes.Add("class",
                                                      string.Format("{0} hide", divSubmitCommand.Attributes["class"]));
                            divPaymentSummary.Attributes["class"] =
                                divEmailNotification.Attributes["class"].Replace("hide", string.Empty);

                            //hide the PaymentSummary if the Payment choice for HFF Order is Wire
                            if (SessionInfo.SelectedPaymentChoice == "WireTransfer")
                            {
                                divPaymentSummary.Attributes["class"] = "hide";
                            }
                            else
                            {
                                divPaymentSummary.Attributes["class"] =
                                    divEmailNotification.Attributes["class"].Replace("hide", string.Empty);
                            }

                            divOrderComplete.Attributes["class"] = divOrderComplete.Attributes["class"].Replace("hide",
                                                                                                                string
                                                                                                                .Empty);
                            divEmailNotification.Attributes["class"] =
                                divEmailNotification.Attributes["class"].Replace("hide", string.Empty);
                            divSubmitCommand.Attributes.Add("class",
                                                            string.Format("{0} hide",
                                                                          divSubmitCommand.Attributes["class"]));
                            divEndCommand.Attributes["class"] = divEndCommand.Attributes["class"].Replace("hide",
                                                                                                          string.Empty);

                            if (PurchasingLimitProvider.RequirePurchasingLimits(DistributorID, CountryCode))
                            {
                                PurchasingLimitProvider.ReconcileAfterPurchase(ShoppingCart, DistributorID, CountryCode);
                            }

                            var currentSession = SessionInfo.GetSessionInfo(DistributorID, Locale);
                            if (currentSession != null)
                            {
                                if (!String.IsNullOrEmpty(currentSession.OrderNumber))
                                {
                                    currentSession.OrderNumber                      = String.Empty;
                                    currentSession.OrderMonthShortString            = string.Empty;
                                    currentSession.OrderMonthString                 = string.Empty;
                                    currentSession.ShippingMethodNameMX             = String.Empty;
                                    currentSession.ShippingMethodNameUSCA           = String.Empty;
                                    currentSession.ShoppingCart.CustomerOrderDetail = null;
                                    // currentSession.CustomerPaymentSettlementApproved = false; Commented out for Merge. Need to investigate
                                    currentSession.CustomerOrderNumber = String.Empty;
                                    currentSession.CustomerAddressID   = 0;
                                    if (null != currentSession.ShippingAddresses)
                                    {
                                        var customerAddress =
                                            currentSession.ShippingAddresses.Find(
                                                p => p.ID == currentSession.CustomerAddressID);
                                        if (customerAddress != null)
                                        {
                                            currentSession.ShippingAddresses.Remove(customerAddress);
                                        }
                                    }
                                }
                            }

                            //Clear the order month session...
                            Session["OrderMonthDataSessionKey"] = null;
                            SessionInfo.SetSessionInfo(DistributorID, Locale, currentSession);

                            if (ShoppingCart != null)
                            {
                                // take out quantities from inventory
                                ShoppingCartProvider.UpdateInventory(ShoppingCart, CountryCode, Locale, true);
                            }

                            ShoppingCart.CloseCart();
                            RecoverActiveCart();
                            onHFFOrderPlaced(this, new EventArgs());
                        }
                        else
                        {
                            LoggerHelper.Error(error);
                            if (error.Contains("AUTHORIZE PAYMENT"))
                            {
                                _errors.Add(PlatformResources.GetGlobalResourceString("ErrorMessage", "PaymenyFail"));
                            }
                            else if (error.Contains("TIMEOUT"))
                            {
                                _errors.Add(PlatformResources.GetGlobalResourceString("ErrorMessage", "Resubmit"));
                            }
                            else if (error.Contains("ORDER CANNOT BE FULFILLED FOR THE DISTRIBUTOR"))
                            {
                                _errors.Add(PlatformResources.GetGlobalResourceString("ErrorMessage", "CantOrder"));
                            }
                            else
                            {
                                _errors.Add(PlatformResources.GetGlobalResourceString("ErrorMessage", "TransactionFail"));
                            }
                        }
                    }
                }
            }
        }