Esempio n. 1
0
        /// <summary>
        /// Gets the order.
        /// </summary>
        /// <param name="locale">The locale.</param>
        /// <param name="distributorID">The distributor ID.</param>
        /// <param name="shoppingCart">The shopping cart.</param>
        /// <returns></returns>
        public static Order_V01 GetOrder(string locale, string distributorID, MyHLShoppingCart shoppingCart)
        {
            var order = (Order_V01)OrderCreationHelper.CreateOrderObject(shoppingCart);

            OrderCreationHelper.FillOrderInfo(order, shoppingCart);
            return(order);
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (ShoppingCart != null)
            {
                ShoppingCart.CheckAPFShipping();

                // 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       = (CountryCode == "GR") ? OrderCategoryType.APF : OrderCategoryType.RSO;
                //** RSO is just for testing (using other countries) and will always be APF
                order.Shipment = OrderProvider.CreateShippingInfo(CountryCode, ShoppingCart);
                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());
                        }

                        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);
                            }
                            onHFFOrderPlaced(this, new EventArgs());
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the order.
        /// </summary>
        /// <param name="locale">The locale.</param>
        /// <param name="distributorID">The distributor ID.</param>
        /// <returns></returns>
        public static Order_V01 GetOrder(string locale, string distributorID)
        {
            var shoppingCart = MyHLShoppingCartGenerator.GetBasicShoppingCart(distributorID, locale);
            var order        = (Order_V01)OrderCreationHelper.CreateOrderObject(shoppingCart);

            OrderCreationHelper.FillOrderInfo(order, shoppingCart);
            return(order);
        }
        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"));
                            }
                        }
                    }
                }
            }
        }