예제 #1
0
        private static void Main(string[] args)
        {
            string       zoneName;
            ShippingInfo shippingInfo = new ShippingInfo();

            do
            {
                Console.WriteLine();
                Console.WriteLine("What is the destination zone?");
                Console.WriteLine(" *type 'exit' for exit");
                zoneName = Console.ReadLine();
                if ("exit" == zoneName || !shippingInfo.IsZoneNameCorrect(zoneName))
                {
                    continue;
                }
                Console.WriteLine("What is the item price?");
                int.TryParse(Console.ReadLine(), out int price);
                if (0 == price)
                {
                    Console.WriteLine("Invalid item price");
                    continue;
                }
                shippingInfo.CalculateFee(zoneName, price);
            } while (zoneName != "exit");
            Console.WriteLine("  exit..");
        }
        /// <summary>
        /// The setup customer order data.
        /// </summary>
        /// <param name="customerOrderId">
        /// The customer order id.
        /// </param>
        /// <param name="distributorId"></param>
        /// <param name="countryCode"></param>
        /// <param name="locale"></param>
        /// <param name="isAddressValid"></param>
        /// <param name="customerAddressId"></param>
        public static void SetupCustomerOrderData(string customerOrderId, string distributorId, string countryCode, string locale, out bool isAddressValid, out int customerAddressId)
        {
            isAddressValid = false;
            var customerOrderV01 = CustomerOrderingProvider.GetCustomerOrderByOrderID(customerOrderId);

            // Close all carts for provided Customer Order ID
            if (customerOrderV01.OrderStatus == CustomerOrderStatusType.Cancelled)
            {
                ShoppingCartProvider.DeleteOldShoppingCartForCustomerOrder(
                    distributorId, customerOrderV01.OrderID);
            }

            var  existingCart                  = ShoppingCartProvider.GetShoppingCart(distributorId, locale);
            bool useAddressValidation          = ShippingProvider.GetShippingProvider(customerOrderV01.ProcessingCountry).AddressValidationRequired();
            bool useDsAddressAsShippingAddress = ShippingProvider.GetShippingProvider(customerOrderV01.ProcessingCountry).DSAddressAsShippingAddress();
            var  DShippingAddressForCustomer   = new List <DeliveryOption>();

            if (HLConfigManager.Configurations.PickupOrDeliveryConfiguration.SetDSAddressforCashOnDelivery && customerOrderV01.PaymentMethodChoice == CustomerPaymentMethodChoice.CashOnDelivery) // Mappinf object error CustomerPaymentMethodChoice.CashOnDelivery)
            {
                var dsProfile = DistributorOrderingProfileProvider.GetProfile(distributorId,
                                                                              customerOrderV01.ProcessingCountry);

                var mailingAddress = DistributorOrderingProfileProvider.GetAddress(ServiceProvider.OrderSvc.AddressType.Mailing, distributorId, customerOrderV01.ProcessingCountry);
                if (string.IsNullOrWhiteSpace(mailingAddress.PostalCode) || string.IsNullOrWhiteSpace(mailingAddress.City) || string.IsNullOrWhiteSpace(mailingAddress.Line1) || string.IsNullOrWhiteSpace(mailingAddress.StateProvinceTerritory) || dsProfile.PhoneNumbers == null)
                {
                    HttpContext.Current.Response.Redirect("~/dswebadmin/customerorders.aspx?error=2", false);
                }
                useDsAddressAsShippingAddress = true;
                DShippingAddressForCustomer.Add(

                    new DeliveryOption
                {
                    Address     = ObjectMappingHelper.Instance.GetToShipping(mailingAddress),
                    Id          = -4,
                    AddressId   = new Guid(),
                    AddressType = "Shipping",
                    Alias       = "",
                    AltAreaCode = string.Empty,
                    AltPhone    = string.Empty,
                    AreaCode    = mailingAddress.PostalCode,
                    Recipient   = string.Empty,
                    PostalCode  = mailingAddress.PostalCode,
                    Phone       = dsProfile.PhoneNumbers != null
                                    ? dsProfile.PhoneNumbers.Find(x => x.IsPrimary) != null
                                          ? dsProfile.PhoneNumbers.FirstOrDefault(x => x.IsPrimary).CountryPrefix + dsProfile.PhoneNumbers.FirstOrDefault(x => x.IsPrimary).AreaCode + dsProfile.PhoneNumbers.FirstOrDefault(x => x.IsPrimary).Number
                                          : dsProfile.PhoneNumbers.FirstOrDefault().CountryPrefix + dsProfile.PhoneNumbers.FirstOrDefault().AreaCode + dsProfile.PhoneNumbers.FirstOrDefault().Number
                                    : string.Empty,
                    State       = mailingAddress.StateProvinceTerritory,
                    FreightCode = "NOF",         // DEFAULT FREIGHTCODE TO CALL retrieveFreightCode,
                    Name        = DistributorProfileModel.DistributorName(),
                }
                    );
            }
            int            temporaryEnteredAddressId = 0;
            DeliveryOption option           = null;
            var            custOrderAddress = GetCustomerAddress(customerOrderV01, useAddressValidation);

            if ((custOrderAddress != null) && (!useDsAddressAsShippingAddress))
            {
                ShippingProvider.GetShippingProvider(countryCode).GetShippingAddresses(
                    distributorId, customerOrderV01.ProcessingLocale);
                temporaryEnteredAddressId =
                    ShippingProvider.GetShippingProvider(countryCode).SaveShippingAddress(
                        distributorId, customerOrderV01.ProcessingLocale, custOrderAddress, true, true, false);

                isAddressValid = true;

                // Add address To Temporary Address and Insert customer order cart
                custOrderAddress.ID = temporaryEnteredAddressId;
                option = new DeliveryOption(custOrderAddress);
            }
            else
            {
                ShippingAddress_V02 shippingAddress = null;
                if (useDsAddressAsShippingAddress)
                {
                    List <DeliveryOption> shippingAddresses = DShippingAddressForCustomer.Count > 0 ? DShippingAddressForCustomer:
                                                              ShippingProvider.GetShippingProvider(countryCode).GetShippingAddresses(
                        distributorId, customerOrderV01.ProcessingLocale);
                    if (shippingAddresses != null && shippingAddresses.Count > 0)
                    {
                        if ((shippingAddress = shippingAddresses.Find(s => s.IsPrimary)) == null)
                        {
                            shippingAddress = shippingAddresses.First();
                        }
                    }
                }
                if (shippingAddress != null)
                {
                    ShippingAddress_V02 shippingAddressV2 = null;
                    if (DShippingAddressForCustomer.Count > 0)
                    {
                        shippingAddressV2           = DShippingAddressForCustomer[0];
                        shippingAddressV2.ID        = -4;
                        shippingAddressV2.Recipient = DistributorProfileModel.DistributorName();
                    }

                    option = new DeliveryOption(shippingAddress);
                    temporaryEnteredAddressId = DShippingAddressForCustomer.Count > 0 ?  ShippingProvider.GetShippingProvider(countryCode).SaveShippingAddress(
                        distributorId, customerOrderV01.ProcessingLocale, shippingAddressV2, true, true, false) : shippingAddress.ID;
                    if (DShippingAddressForCustomer.Count > 0)
                    {
                        DShippingAddressForCustomer[0].ID = temporaryEnteredAddressId;
                    }
                }
                else
                {
                    option = new DeliveryOption();
                }
            }

            customerAddressId = temporaryEnteredAddressId;

            if (existingCart != null)
            {
                if (existingCart.DeliveryInfo != null)
                {
                    existingCart.DeliveryInfo.Address.ID = temporaryEnteredAddressId;
                }
                ShoppingCartProvider.UpdateShoppingCart(existingCart);
            }
            else
            {
                var shippingInfo = new Shipping.ShippingInfo(ServiceProvider.ShippingSvc.DeliveryOptionType.Shipping, option);

                MyHLShoppingCart customerCart = ShoppingCartProvider.InsertShoppingCart(
                    distributorId,
                    customerOrderV01.ProcessingLocale,
                    ServiceProvider.CatalogSvc.OrderCategoryType.RSO,
                    shippingInfo,
                    getCustomerOrderDetails(customerOrderV01), false, string.Empty);

                if (customerCart != null)
                {
                    foreach (ShoppingCartItem_V01 item in
                             GetCustomerCartItems(customerCart.ShoppingCartID, customerOrderV01.OrderItems))
                    {
                        ShoppingCartProvider.InsertShoppingCartItem(
                            distributorId, item, customerCart.ShoppingCartID);
                    }

                    // Update Status of Order To In Progress In Azure
                    CustomerOrderingProvider.UpdateCustomerOrderStatus(
                        customerOrderV01.OrderID, customerOrderV01.OrderStatus, CustomerOrderStatusType.InProgress);
                }
                else
                {
                    throw new Exception("Unable to Convert Customer Order To DO Order");
                }
            }
        }