/// <summary>
        /// Gets the shipment information to import into HMS.
        /// </summary>
        /// <param name="shoppingCart">The shopping cart.</param>
        /// <param name="shippment">The order shipment.</param>
        /// <returns></returns>
        public override bool GetDistributorShippingInfoForHMS(MyHLShoppingCart shoppingCart, MyHerbalife3.Ordering.ServiceProvider.SubmitOrderBTSvc.Shipment shippment)
        {
            if (shoppingCart != null && shoppingCart.DeliveryInfo != null)
            {
                string freightCodeInCart = shoppingCart.DeliveryInfo.FreightCode;
                var    session           = SessionInfo.GetSessionInfo(shoppingCart.DistributorID, shoppingCart.Locale);
                if (session.IsEventTicketMode || APFDueProvider.hasOnlyAPFSku(shoppingCart.CartItems, shoppingCart.Locale))
                {
                    return(true);
                }

                if (shoppingCart.FreightCode == "NOF")
                {
                    shippment.ShippingMethodID = shoppingCart.FreightCode = shoppingCart.DeliveryInfo.FreightCode = shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Shipping ? "UAF" : "PU";
                }
                if (shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Shipping)
                {
                    shoppingCart.DeliveryInfo.WarehouseCode = HLConfigManager.Configurations.ShoppingCartConfiguration.DefaultWarehouse;
                }
                if (!freightCodeInCart.Equals(shoppingCart.FreightCode))
                {
                    shoppingCart.Calculate();
                    ShoppingCartProvider.UpdateShoppingCart(shoppingCart);
                }
            }
            return(true);
        }
 /// <summary>
 /// Gets the shipment information to import into HMS.
 /// </summary>
 /// <param name="shoppingCart">The shopping cart.</param>
 /// <param name="shippment">The order shipment.</param>
 /// <returns></returns>
 public override bool GetDistributorShippingInfoForHMS(MyHLShoppingCart shoppingCart, Shipment shippment)
 {
     if (shoppingCart != null && shoppingCart.DeliveryInfo != null)
     {
         string freightCodeInCart = shoppingCart.DeliveryInfo.FreightCode;
         var    session           = SessionInfo.GetSessionInfo(shoppingCart.DistributorID, shoppingCart.Locale);
         if (session.IsEventTicketMode)
         {
             shippment.ShippingMethodID = shoppingCart.FreightCode = shoppingCart.DeliveryInfo.FreightCode = HLConfigManager.Configurations.CheckoutConfiguration.EventTicketFreightCode;
         }
         else if (APFDueProvider.hasOnlyAPFSku(shoppingCart.CartItems, shoppingCart.Locale))
         {
             shippment.ShippingMethodID = shoppingCart.FreightCode = shoppingCart.DeliveryInfo.FreightCode = HLConfigManager.Configurations.APFConfiguration.APFFreightCode;
         }
         else
         {
             string defaultFreight = HLConfigManager.Configurations.ShoppingCartConfiguration.DefaultFreightCode;
             shippment.WarehouseCode = shoppingCart.DeliveryInfo.WarehouseCode = HLConfigManager.Configurations.ShoppingCartConfiguration.DefaultWarehouse;
             if (shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Shipping)
             {
                 shippment.ShippingMethodID = shoppingCart.FreightCode = shoppingCart.DeliveryInfo.FreightCode = defaultFreight;
             }
             else
             {
                 shippment.ShippingMethodID = shoppingCart.FreightCode = shoppingCart.DeliveryInfo.FreightCode = "PU";
             }
         }
         if (!freightCodeInCart.Equals(shoppingCart.FreightCode))
         {
             shoppingCart.Calculate();
             ShoppingCartProvider.UpdateShoppingCart(shoppingCart);
         }
     }
     return(true);
 }
 /// <summary>
 /// GetDistributorShippingInfoForHMS
 /// </summary>
 /// <param name="shoppingCart"></param>
 /// <param name="address"></param>
 public override void GetDistributorShippingInfoForHMS(MyHLShoppingCart shoppingCart, ShippingInfo_V01 address)
 {
     if (shoppingCart != null && shoppingCart.DeliveryInfo != null)
     {
         string freightCodeInCart = shoppingCart.DeliveryInfo.FreightCode;
         var    session           = SessionInfo.GetSessionInfo(shoppingCart.DistributorID, shoppingCart.Locale);
         if (session.IsEventTicketMode)
         {
             shoppingCart.FreightCode = shoppingCart.DeliveryInfo.FreightCode = HLConfigManager.Configurations.CheckoutConfiguration.EventTicketFreightCode;
         }
         else if (APFDueProvider.hasOnlyAPFSku(shoppingCart.CartItems, shoppingCart.Locale))
         {
             shoppingCart.FreightCode = shoppingCart.DeliveryInfo.FreightCode = HLConfigManager.Configurations.APFConfiguration.APFFreightCode;
         }
         else
         {
             string defaultFreight = HLConfigManager.Configurations.ShoppingCartConfiguration.DefaultFreightCode;
             if (shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Shipping)
             {
                 shoppingCart.FreightCode = shoppingCart.DeliveryInfo.FreightCode = defaultFreight;
             }
             else
             {
                 shoppingCart.FreightCode = shoppingCart.DeliveryInfo.FreightCode = "PU";
             }
         }
         if (!freightCodeInCart.Equals(shoppingCart.FreightCode))
         {
             ShoppingCartProvider.UpdateShoppingCart(shoppingCart);
         }
     }
 }
예제 #4
0
        /// <summary>
        /// Gets the shipment information to import into HMS.
        /// </summary>
        /// <param name="shoppingCart">The shopping cart.</param>
        /// <param name="shippment">The order shipment.</param>
        /// <returns></returns>
        public override bool GetDistributorShippingInfoForHMS(MyHLShoppingCart shoppingCart, Shipment shippment)
        {
            var session = SessionInfo.GetSessionInfo(shoppingCart.DistributorID, shoppingCart.Locale);

            if (session.IsEventTicketMode)
            {
                return(true);
            }

            if (APFDueProvider.hasOnlyAPFSku(shoppingCart.CartItems, shoppingCart.Locale))
            {
                return(true);
            }

            if (shoppingCart.DeliveryInfo != null && shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Shipping &&
                !shoppingCart.DeliveryInfo.FreightCode.Equals(HLConfigManager.Configurations.ShoppingCartConfiguration.DefaultFreightCode))
            {
                shoppingCart.DeliveryInfo.FreightCode =
                    HLConfigManager.Configurations.ShoppingCartConfiguration.DefaultFreightCode;
                shoppingCart.DeliveryInfo.WarehouseCode =
                    HLConfigManager.Configurations.ShoppingCartConfiguration.DefaultWarehouse;
                shippment.ShippingMethodID = shoppingCart.DeliveryInfo.FreightCode;
                shippment.WarehouseCode    = shoppingCart.DeliveryInfo.WarehouseCode;
            }
            return(true);
        }
 /// <summary>
 /// called before pricing
 /// </summary>
 /// <param name="shoppingCart"></param>
 /// <param name="address"></param>
 public override void GetDistributorShippingInfoForHMS(MyHLShoppingCart shoppingCart, MyHerbalife3.Ordering.ServiceProvider.OrderSvc.ShippingInfo_V01 address)
 {
     if (shoppingCart != null && shoppingCart.DeliveryInfo != null)
     {
         string freightCodeInCart = shoppingCart.DeliveryInfo.FreightCode;
         var    session           = SessionInfo.GetSessionInfo(shoppingCart.DistributorID, shoppingCart.Locale);
         if (session.IsEventTicketMode || APFDueProvider.hasOnlyAPFSku(shoppingCart.CartItems, shoppingCart.Locale))
         {
             shoppingCart.FreightCode = shoppingCart.DeliveryInfo.FreightCode = "NOF";
         }
         else
         {
             if (shoppingCart.FreightCode == "NOF")
             {
                 shoppingCart.FreightCode = shoppingCart.DeliveryInfo.FreightCode = shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Shipping ? "UAF" : "PU";
             }
             if (shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Shipping)
             {
                 shoppingCart.DeliveryInfo.WarehouseCode = HLConfigManager.Configurations.ShoppingCartConfiguration.DefaultWarehouse;
             }
         }
         if (!freightCodeInCart.Equals(shoppingCart.FreightCode))
         {
             ShoppingCartProvider.UpdateShoppingCart(shoppingCart);
         }
     }
 }
예제 #6
0
 public override void GetDistributorShippingInfoForHMS(MyHLShoppingCart shoppingCart, MyHerbalife3.Ordering.ServiceProvider.OrderSvc.ShippingInfo_V01 address)
 {
     if (shoppingCart != null && shoppingCart.DeliveryInfo != null && shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Pickup)
     {
         ShippingInfo shippingInfo = base.GetShippingInfoFromID(shoppingCart.DistributorID, shoppingCart.Locale, shoppingCart.DeliveryInfo.Option, shoppingCart.DeliveryOptionID, shoppingCart.ShippingAddressID);
         SessionInfo  sessionInfo  = SessionInfo.GetSessionInfo(shoppingCart.DistributorID, shoppingCart.Locale);
         if (shippingInfo != null)
         {
             if (sessionInfo.IsEventTicketMode)
             {
                 shoppingCart.DeliveryInfo.FreightCode   = HLConfigManager.Configurations.CheckoutConfiguration.EventTicketFreightCode;
                 shoppingCart.DeliveryInfo.WarehouseCode = shippingInfo.WarehouseCode;
                 address.ShippingMethodID = HLConfigManager.Configurations.APFConfiguration.APFFreightCode;
                 address.WarehouseCode    = shippingInfo.WarehouseCode;
             }
             if (APFDueProvider.hasOnlyAPFSku(shoppingCart.CartItems, shoppingCart.Locale))
             {
                 shoppingCart.DeliveryInfo.FreightCode   = HLConfigManager.Configurations.CheckoutConfiguration.EventTicketFreightCode;
                 shoppingCart.DeliveryInfo.WarehouseCode = shippingInfo.WarehouseCode;
                 address.ShippingMethodID = HLConfigManager.Configurations.APFConfiguration.APFFreightCode;
                 address.WarehouseCode    = shippingInfo.WarehouseCode;
             }
         }
     }
 }
예제 #7
0
 private void retrieveFreightCode(MyHLShoppingCart shoppingCart, MyHerbalife3.Ordering.ServiceProvider.OrderSvc.ShippingInfo_V01 address)
 {
     if (APFDueProvider.hasOnlyAPFSku(shoppingCart.CartItems, shoppingCart.Locale))
     {
         shoppingCart.FreightCode = HLConfigManager.Configurations.APFConfiguration.APFFreightCode;
         if (shoppingCart.DeliveryInfo != null)
         {
             shoppingCart.DeliveryInfo.FreightCode   = HLConfigManager.Configurations.APFConfiguration.APFFreightCode;
             shoppingCart.DeliveryInfo.WarehouseCode = HLConfigManager.Configurations.APFConfiguration.APFwarehouse;
         }
     }
 }
예제 #8
0
        private void retrieveFreightCode(MyHLShoppingCart shoppingCart, MyHerbalife3.Ordering.ServiceProvider.ShoppingCartSvc.ShippingInfo_V01 address)
        {
            // to correct prod issue where wrong freight code is set
            if (shoppingCart != null && shoppingCart.DeliveryInfo != null && shoppingCart.DeliveryInfo.Address != null &&
                shoppingCart.DeliveryInfo.Address.Address != null &&
                (shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Shipping || shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Pickup) &&
                shoppingCart.OrderCategory == MyHerbalife3.Ordering.ServiceProvider.CatalogSvc.OrderCategoryType.RSO && shoppingCart.DeliveryInfo.FreightCode == "NOF")
            {
                // Let the ETO and APF preserve the freight
                SessionInfo sessionInfo = SessionInfo.GetSessionInfo(shoppingCart.DistributorID, shoppingCart.Locale);
                var         isAPF       = APFDueProvider.hasOnlyAPFSku(shoppingCart.CartItems, shoppingCart.Locale);

                if (!sessionInfo.IsEventTicketMode && !isAPF)
                {
                    if (shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Shipping)
                    {
                        List <DeliveryOption> deliveryOptions = GetDeliveryOptions(DeliveryOptionType.Shipping,
                                                                                   shoppingCart.DeliveryInfo.Address);
                        if (deliveryOptions != null)
                        {
                            DeliveryOption op =
                                deliveryOptions.Find(
                                    d =>
                                    d.WarehouseCode == shoppingCart.DeliveryInfo.WarehouseCode &&
                                    d.State.Equals(shoppingCart.DeliveryInfo.Address.Address.StateProvinceTerritory));
                            if (op != null)
                            {
                                shoppingCart.DeliveryInfo.FreightCode = op.FreightCode;
                            }
                        }
                    }
                    else if (shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Pickup)
                    {
                        var pickupLocation = GetShippingInfoFromID(shoppingCart.DistributorID, shoppingCart.Locale,
                                                                   DeliveryOptionType.Pickup,
                                                                   shoppingCart.DeliveryInfo.Id, shoppingCart.DeliveryInfo.Address.ID);
                        if (pickupLocation != null)
                        {
                            shoppingCart.DeliveryInfo.FreightCode   = pickupLocation.FreightCode;
                            shoppingCart.DeliveryInfo.WarehouseCode = pickupLocation.WarehouseCode;
                        }
                    }
                }
            }
        }
        public override void GetDistributorShippingInfoForHMS(MyHLShoppingCart shoppingCart, ServiceProvider.OrderSvc.ShippingInfo_V01 address)
        {
            if (shoppingCart != null)
            {
                if (APFDueProvider.hasOnlyAPFSku(shoppingCart.CartItems, shoppingCart.Locale))
                {
                    address.WarehouseCode    = HLConfigManager.Configurations.APFConfiguration.APFwarehouse;
                    address.ShippingMethodID = HLConfigManager.Configurations.APFConfiguration.APFFreightCode;
                }
                else
                {
                    shoppingCart.CheckShippingForNonStandAloneAPF();

                    SessionInfo sessionInfo = SessionInfo.GetSessionInfo(shoppingCart.DistributorID, shoppingCart.Locale);
                    if (sessionInfo.IsEventTicketMode && shoppingCart.DeliveryInfo != null)
                    {
                        shoppingCart.DeliveryInfo.WarehouseCode = HLConfigManager.Configurations.CheckoutConfiguration.EventTicketWarehouseCode;
                        shoppingCart.DeliveryInfo.FreightCode   = HLConfigManager.Configurations.CheckoutConfiguration.EventTicketFreightCode;

                        // Take address from DB
                        var deliveryOptions = base.GetDeliveryOptions(shoppingCart.Locale);
                        var addressETO      = deliveryOptions.Find(d =>
                                                                   d.Option == ServiceProvider.ShippingSvc.DeliveryOptionType.Shipping &&
                                                                   d.OrderCategory == ServiceProvider.ShippingSvc.OrderCategoryType.ETO);

                        if (addressETO != null)
                        {
                            shoppingCart.DeliveryInfo.Address.Address = addressETO.Address;
                        }

                        // Set MB's Name in the Recipient name
                        var loader      = new Core.DistributorProvider.DistributorLoader();
                        var distributor = loader.Load(shoppingCart.DistributorID, shoppingCart.CountryCode);

                        if (distributor != null && distributor.EnglishName != null)
                        {
                            shoppingCart.DeliveryInfo.Address.Recipient = string.Format("{0} {1}{2}",
                                                                                        distributor.EnglishName.First,
                                                                                        !string.IsNullOrEmpty(distributor.EnglishName.Middle) ? distributor.EnglishName.Middle + " " : string.Empty,
                                                                                        distributor.EnglishName.Last);
                        }
                    }
                }
            }
        }
        private void CheckingFreightCode(MyHLShoppingCart shoppingCart)
        {
            // To prevent prod issue where wrong freight code is set (NOF)
            if (shoppingCart != null && shoppingCart.DeliveryInfo != null && shoppingCart.DeliveryInfo.Address != null &&
                shoppingCart.DeliveryInfo.Address.Address != null && shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Shipping &&
                shoppingCart.OrderCategory == ServiceProvider.CatalogSvc.OrderCategoryType.RSO && shoppingCart.DeliveryInfo.FreightCode == "NOF")
            {
                var sessionInfo = SessionInfo.GetSessionInfo(shoppingCart.DistributorID, shoppingCart.Locale);
                var isAPF       = APFDueProvider.hasOnlyAPFSku(shoppingCart.CartItems, shoppingCart.Locale);

                // If order is standalone APF or ETO we leave the freight
                if (!sessionInfo.IsEventTicketMode && !isAPF)
                {
                    var freightAndWarehouse = GetFreightCodeAndWarehouse(shoppingCart.DeliveryInfo.Address);
                    shoppingCart.DeliveryInfo.FreightCode = freightAndWarehouse[0];
                }
            }
        }
        public override void GetDistributorShippingInfoForHMS(MyHLShoppingCart shoppingCart, MyHerbalife3.Ordering.ServiceProvider.OrderSvc.ShippingInfo_V01 address)
        {
            DeliveryOption deliveryOptionForAddress = null;

            if (shoppingCart.DeliveryInfo != null && shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Shipping)
            {
                var currentAddress = shoppingCart.DeliveryInfo.Address;
                var stateCode      = this.GetStateCodeGivenStateName(currentAddress.Address.StateProvinceTerritory.Trim());
                var srchCity       = currentAddress.Address.City.Trim().ToLower();
                if (currentAddress != null)
                {
                    //1)get cart total & compare with CAP
                    var listDeliveryOptions =
                        base.GetDeliveryOptions(
                            DeliveryOptionType.Shipping, currentAddress as ShippingAddress_V02);

                    var availableOptions =
                        listDeliveryOptions.FindAll(p => p.State.ToLower().Trim() == stateCode.ToLower().Trim());
                    if (availableOptions.Count > 0)
                    {
                        var optionForMajorCity =
                            availableOptions.FirstOrDefault(
                                i =>
                                !string.IsNullOrEmpty(i.Address.City) &&
                                i.Address.City.Trim().ToLower() == srchCity.Trim().ToLower());
                        deliveryOptionForAddress = optionForMajorCity
                                                   ?? availableOptions.FindAll(p => p.Address.City == null).FirstOrDefault();

                        if (deliveryOptionForAddress != null)
                        {
                            if (APFDueProvider.hasOnlyAPFSku(shoppingCart.CartItems, shoppingCart.Locale))
                            {
                                address.WarehouseCode = HLConfigManager.Configurations.APFConfiguration.APFwarehouse;
                            }
                            else
                            {
                                shoppingCart.DeliveryInfo.WarehouseCode = deliveryOptionForAddress.WarehouseCode;
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Gets the shipment information to import into HMS.
        /// </summary>
        /// <param name="shoppingCart">The shopping cart.</param>
        /// <param name="shippment">The order shipment.</param>
        /// <returns></returns>
        public override bool GetDistributorShippingInfoForHMS(MyHLShoppingCart shoppingCart, Shipment shippment)
        {
            var session = SessionInfo.GetSessionInfo(shoppingCart.DistributorID, shoppingCart.Locale);

            if (session.IsEventTicketMode)
            {
                if (shoppingCart.DeliveryInfo != null)
                {
                    shoppingCart.DeliveryInfo.FreightCode = HLConfigManager.Configurations.CheckoutConfiguration.EventTicketFreightCode;
                }
                return(true);
            }

            if (APFDueProvider.hasOnlyAPFSku(shoppingCart.CartItems, shoppingCart.Locale))
            {
                return(true);
            }

            if (ShoppingCartProvider.IsStandaloneHFF(shoppingCart.ShoppingCartItems))
            {
                if (shoppingCart.DeliveryInfo != null)
                {
                    var freightCodeAndWarehouse = GetFreightCodeAndWarehouse(shoppingCart.DeliveryInfo.Address);
                    shoppingCart.DeliveryInfo.FreightCode   = shippment.ShippingMethodID = HLConfigManager.Configurations.APFConfiguration.APFFreightCode;
                    shoppingCart.DeliveryInfo.WarehouseCode = shippment.WarehouseCode = freightCodeAndWarehouse[1];
                }
                return(true);
            }

            if (shoppingCart.DeliveryInfo != null && shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Shipping &&
                (shoppingCart.DeliveryInfo.FreightCode.Equals(HLConfigManager.Configurations.APFConfiguration.APFFreightCode) ||
                 shoppingCart.DeliveryInfo.FreightCode.Equals(HLConfigManager.Configurations.CheckoutConfiguration.EventTicketFreightCode)))
            {
                var freightCodeAndWarehouse = GetFreightCodeAndWarehouse(shoppingCart.DeliveryInfo.Address);
                shoppingCart.DeliveryInfo.FreightCode   = shippment.ShippingMethodID = freightCodeAndWarehouse[0];
                shoppingCart.DeliveryInfo.WarehouseCode = shippment.WarehouseCode = freightCodeAndWarehouse[1];
            }
            return(true);
        }
        /// <summary>
        /// Validates if the promo should be in cart.
        /// </summary>
        /// <param name="shoppingCart">The shopping cart.</param>
        /// <param name="cart">The MyHL shopping cart.</param>
        /// <param name="result">The promo rule result.</param>
        /// <returns></returns>
        private ShoppingCartRuleResult CheckPromoInCart(ShoppingCart_V02 shoppingCart,
                                                        MyHLShoppingCart cart,
                                                        ShoppingCartRuleResult result)
        {
            // Check the order type
            var session = SessionInfo.GetSessionInfo(cart.DistributorID, cart.Locale);

            if (session.IsEventTicketMode)
            {
                return(result);
            }

            // Check if promo sku should be in cart
            var promoInCart   = cart.CartItems != null && cart.CartItems.Any(i => i.SKU.Equals(PromoSKU));
            var apfSkus       = APFDueProvider.GetAPFSkuList();
            var applyForPromo = cart.CartItems != null &&
                                cart.CartItems.Any(
                i =>
                !apfSkus.Contains(i.SKU) &&
                !i.SKU.Equals(HLConfigManager.Configurations.DOConfiguration.HFFHerbalifeSku) &&
                !i.SKU.Equals(PromoSKU));

            // Check if APF standalone order
            if (APFDueProvider.hasOnlyAPFSku(cart.CartItems, cart.Locale))
            {
                return(result);
            }

            // Check HFF standalone
            if (ShoppingCartProvider.IsStandaloneHFF(cart.ShoppingCartItems))
            {
                return(result);
            }

            if (!applyForPromo)
            {
                if (promoInCart)
                {
                    cart.DeleteItemsFromCart(new List <string> {
                        PromoSKU
                    }, true);
                }

                // Nothing to do
                result.Result = RulesResult.Success;
                cart.RuleResults.Add(result);
                return(result);
            }

            //Check promo sku catalog info
            var allSkus = CatalogProvider.GetAllSKU(Locale);

            if (!allSkus.Keys.Contains(PromoSKU))
            {
                if (Environment.MachineName.IndexOf("PROD", StringComparison.Ordinal) < 0)
                {
                    var    country = new RegionInfo(new CultureInfo(Locale, false).LCID);
                    string message = "NoPromoSku";
                    var    globalResourceObject =
                        HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform),
                                                            "NoPromoSku");
                    if (globalResourceObject != null)
                    {
                        message = string.Format(globalResourceObject.ToString(), country.DisplayName, PromoSKU);
                    }
                    result.Result = RulesResult.Feedback;
                    result.Messages.Add(message);
                    cart.RuleResults.Add(result);
                    return(result);
                }
                return(result);
            }

            // Adding promo sku if possible
            var isRuleTime = IsRuleTime();

            if (!promoInCart && isRuleTime && !string.IsNullOrEmpty(cart.DeliveryInfo.WarehouseCode))
            {
                WarehouseInventory warehouseInventory;
                var catItemPromo = CatalogProvider.GetCatalogItem(PromoSKU, Country);
                if (catItemPromo.InventoryList.TryGetValue(cart.DeliveryInfo.WarehouseCode, out warehouseInventory))
                {
                    if (warehouseInventory != null)
                    {
                        var warehouseInventory01 = warehouseInventory as WarehouseInventory_V01;
                        if (warehouseInventory01 != null && warehouseInventory01.QuantityAvailable > 0)
                        {
                            cart.AddItemsToCart(
                                new List <ShoppingCartItem_V01>(new[]
                                                                { new ShoppingCartItem_V01(0, PromoSKU, 1, DateTime.Now) }), true);
                            result.Result = RulesResult.Success;
                            cart.RuleResults.Add(result);
                        }
                    }
                }
            }
            else if (promoInCart && !isRuleTime)
            {
                // Remove the promo sku
                cart.DeleteItemsFromCart(new List <string> {
                    PromoSKU
                }, true);
                result.Result = RulesResult.Success;
                cart.RuleResults.Add(result);
            }
            return(result);
        }
        public override bool GetDistributorShippingInfoForHMS(MyHLShoppingCart shoppingCart, Shipment shippment)
        {
            if (shoppingCart.DeliveryInfo != null && shoppingCart.DeliveryInfo.Address != null &&
                shoppingCart.DeliveryInfo.Address.Address != null &&
                shoppingCart.DeliveryOption == ServiceProvider.CatalogSvc.DeliveryOptionType.Shipping)
            {
                if (APFDueProvider.hasOnlyAPFSku(shoppingCart.CartItems, shoppingCart.Locale))
                {
                    shippment.WarehouseCode    = HLConfigManager.Configurations.APFConfiguration.APFwarehouse;
                    shippment.ShippingMethodID = HLConfigManager.Configurations.APFConfiguration.APFFreightCode;
                }
                else
                {
                    shoppingCart.CheckShippingForNonStandAloneAPF();

                    SessionInfo sessionInfo = SessionInfo.GetSessionInfo(shoppingCart.DistributorID, shoppingCart.Locale);
                    if (sessionInfo.IsEventTicketMode && shoppingCart.DeliveryInfo != null)
                    {
                        shoppingCart.DeliveryInfo.WarehouseCode = HLConfigManager.Configurations.CheckoutConfiguration.EventTicketWarehouseCode;
                        shoppingCart.DeliveryInfo.FreightCode   = HLConfigManager.Configurations.CheckoutConfiguration.EventTicketFreightCode;
                        shippment.WarehouseCode    = shoppingCart.DeliveryInfo.WarehouseCode;
                        shippment.ShippingMethodID = shoppingCart.DeliveryInfo.FreightCode;

                        // Take address from DB in the ShoppingCart.
                        var deliveryOptions = base.GetDeliveryOptions(shoppingCart.Locale);
                        var addressETO      = deliveryOptions.Find(d =>
                                                                   d.Option == ServiceProvider.ShippingSvc.DeliveryOptionType.Shipping &&
                                                                   d.OrderCategory == ServiceProvider.ShippingSvc.OrderCategoryType.ETO);

                        if (addressETO != null)
                        {
                            shoppingCart.DeliveryInfo.Address.Address = addressETO.Address;
                        }

                        // Take mailing address for HMS
                        var mailingAddress = DistributorOrderingProfileProvider.GetAddress(
                            ServiceProvider.OrderSvc.AddressType.Mailing, shoppingCart.DistributorID,
                            shoppingCart.CountryCode);

                        if (mailingAddress != null)
                        {
                            shippment.Address.Line1 = mailingAddress.Line1;
                            shippment.Address.Line2 = mailingAddress.Line2;
                            shippment.Address.Line3 = mailingAddress.Line3;
                            shippment.Address.Line4 = mailingAddress.Line4;
                            shippment.Address.City  = mailingAddress.City;
                            shippment.Address.StateProvinceTerritory = mailingAddress.StateProvinceTerritory;
                            shippment.Address.PostalCode             = mailingAddress.PostalCode;
                            shippment.Address.CountyDistrict         = mailingAddress.CountyDistrict;
                            shippment.Address.Country = mailingAddress.Country;
                        }

                        // Set MB's Name in the Recipient name
                        var loader      = new Core.DistributorProvider.DistributorLoader();
                        var distributor = loader.Load(shoppingCart.DistributorID, shoppingCart.CountryCode);

                        if (distributor != null && distributor.EnglishName != null)
                        {
                            shoppingCart.DeliveryInfo.Address.Recipient = string.Format("{0} {1}{2}",
                                                                                        distributor.EnglishName.First,
                                                                                        !string.IsNullOrEmpty(distributor.EnglishName.Middle) ? distributor.EnglishName.Middle + " " : string.Empty,
                                                                                        distributor.EnglishName.Last);
                        }
                    }
                }
            }
            return(true);
        }
예제 #15
0
        private ShoppingCartRuleResult CartItemBeingDeletedRuleHandler(ShoppingCart_V01 cart,
                                                                       ShoppingCartRuleResult result,
                                                                       string level)
        {
            if (APFDueProvider.IsAPFDueAndNotPaid(cart.DistributorID, Locale) &&
                HLConfigManager.Configurations.APFConfiguration.StandaloneAPFOnlyAllowed)
            {
                result.Result = RulesResult.Failure;
                result.AddMessage(
                    HttpContext.GetGlobalResourceObject(string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                                        "CompleteAPFPurchase") as string);
                var sku = APFDueProvider.GetAPFSku();
                SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.StandaloneAPFOnlyAllowed,
                                   "CompleteAPFPurchase");

                cart.RuleResults.Add(result);
                return(result);
            }

            //Deleting is a little different than Inserting, because delete handles multiple skus while insert only does one
            //so we can use the cart.CurrentItems to control this. Anything the rule says to not delete, we remove from the CurrentItems
            //Delete post-rule will only delete what is left in there
            bool isStandaloneAPF = APFDueProvider.hasOnlyAPFSku(cart.CartItems, Locale);
            var  toRemove        = new List <ShoppingCartItem_V01>();
            var  hlCart          = cart as MyHLShoppingCart;

            if (null != hlCart)
            {
                foreach (ShoppingCartItem_V01 item in cart.CurrentItems)
                {
                    if (APFDueProvider.IsAPFSku(item.SKU))
                    {
                        if (
                            !APFDueProvider.CanRemoveAPF(cart.DistributorID, Thread.CurrentThread.CurrentCulture.Name,
                                                         level))
                        {
                            result.Result = RulesResult.Failure;
                            result.AddMessage(
                                HttpContext.GetGlobalResourceObject(
                                    string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "CannotRemoveAPFSku")
                                as string);
                            var sku = APFDueProvider.GetAPFSku();
                            SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.StandaloneAPFOnlyAllowed,
                                               "CannotRemoveAPFSku");

                            cart.RuleResults.Add(result);
                        }
                        else
                        {
                            if (APFDueProvider.IsAPFDueAndNotPaid(cart.DistributorID, Locale))
                            {
                                var originalItem =
                                    (from c in cart.CartItems where c.SKU == cart.CurrentItems[0].SKU select c).ToList();
                                int requiredQuantity = APFDueProvider.APFQuantityDue(cart.DistributorID, Locale);
                                if (level == "SP")
                                {
                                    item.Quantity = requiredQuantity;
                                    result.Result = RulesResult.Recalc;
                                    result.AddMessage(
                                        HttpContext.GetGlobalResourceObject(
                                            string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                            "RequiredAPFLeftInCart") as string);
                                    var sku = APFDueProvider.GetAPFSku();
                                    SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.StandaloneAPFOnlyAllowed,
                                                       "RequiredAPFLeftInCart");
                                    cart.RuleResults.Add(result);
                                    //toRemove.Add(item);
                                    cart.APFEdited = false;
                                    return(result);
                                }

                                //Add for ChinaDO
                                if (HLConfigManager.Configurations.APFConfiguration.CantDSRemoveAPF)
                                {
                                    result.Result = RulesResult.Recalc;
                                    result.AddMessage(
                                        HttpContext.GetGlobalResourceObject(
                                            string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                            "RequiredAPFLeftInCart") as string);
                                    var sku = APFDueProvider.GetAPFSku();
                                    SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.StandaloneAPFOnlyAllowed,
                                                       "RequiredAPFLeftInCart");
                                    cart.RuleResults.Add(result);
                                    //toRemove.Add(item);
                                    cart.APFEdited = false;
                                    return(result);
                                }
                            }
                            cart.APFEdited = true;
                            toRemove.Add(item); // added
                        }
                    }
                    else
                    {
                        toRemove.Add(item); // added
                    }
                }
                //if (toRemove.Count > 0)
                //{
                //    cart.CurrentItems.Remove(toRemove[0]);
                //}
                var remainingItems = (from c in cart.CartItems
                                      where !toRemove.Any(x => x.SKU == c.SKU)
                                      select c).ToList();

                //List<ShoppingCartItem_V01> remainingItems = (from c in cart.CartItems where c.SKU != cart.CurrentItems[0].SKU select c).ToList();
                var mags = CartHasOnlyTodaysMagazine(remainingItems);
                if (mags.Count > 0)
                {
                    foreach (ShoppingCartItem_V01 item in mags)
                    {
                        (cart as MyHLShoppingCart).DeleteTodayMagazine(item.SKU);
                        remainingItems.Remove(item);
                        if (!cart.CurrentItems.Exists(c => c.SKU == item.SKU))
                        {
                            cart.CurrentItems.Add(item);
                        }
                    }
                    result.Result = RulesResult.Failure;
                    result.AddMessage(
                        HttpContext.GetGlobalResourceObject(
                            string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                            "NoTodayMagazineWithStandalonAPF") as string);
                    var sku = APFDueProvider.GetAPFSku();
                    SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.StandaloneAPFOnlyAllowed,
                                       "NoTodayMagazineWithStandalonAPF");
                    cart.RuleResults.Add(result);
                }

                // added
                if (remainingItems.Count > 0)
                {
                    var list = new ShoppingCartItemList();
                    list.AddRange(remainingItems);
                    isStandaloneAPF = APFDueProvider.hasOnlyAPFSku(list, Locale);
                    if (isStandaloneAPF)
                    {
                        SetAPFDeliveryOption(hlCart);
                    }
                    else
                    {
                        if (APFDueProvider.IsAPFSkuPresent(cart.CurrentItems))
                        {
                            SetNonStandAloneAPFDeliveryOption(hlCart);
                        }
                    }
                }
                else
                {
                    SetNonStandAloneAPFDeliveryOption(hlCart);
                }
            }
            //if((from c in cart.CurrentItems where APFDueProvider.IsAPFSku(c.SKU) select c).Count() >0)
            //{
            //    if (isStandaloneAPF)
            //    {
            //        SetAPFDeliveryOption(hlCart);
            //    }
            //}

            return(result);
        }
        /// <summary>
        /// Validates if the promo should be in cart.
        /// </summary>
        /// <param name="shoppingCart">The shopping cart.</param>
        /// <param name="cart">The MyHL shopping cart.</param>
        /// <param name="result">The promo rule result.</param>
        /// <returns></returns>
        private ShoppingCartRuleResult CheckPromoInCart(ShoppingCart_V02 shoppingCart, MyHLShoppingCart cart, ShoppingCartRuleResult result, bool removed)
        {
            // Check the order type
            var session = SessionInfo.GetSessionInfo(cart.DistributorID, cart.Locale);

            if (session.IsEventTicketMode)
            {
                return(result);
            }

            // Check if APF standalone order
            if (APFDueProvider.hasOnlyAPFSku(cart.CartItems, cart.Locale))
            {
                return(result);
            }

            // Check HFF standalone
            if (ShoppingCartProvider.IsStandaloneHFF(cart.ShoppingCartItems))
            {
                return(result);
            }

            // Check if promo sku has been removed
            if (removed && (cart.CartItems.Count == 0 || (!string.IsNullOrEmpty(cart.PromoSkuDiscarted) && cart.PromoSkuDiscarted.Contains(PromoSku.Sku))))
            {
                result.Result = RulesResult.Success;
                return(result);
            }

            // Check if promo sku should be in cart
            var isRuleTime    = IsRuleTime();
            var isPromoInCart = cart.CartItems != null && cart.CartItems.Any(i => i.SKU.Equals(PromoSku.Sku));
            var promoInCart   = isPromoInCart ? cart.CartItems.FirstOrDefault(i => i.SKU.Equals(PromoSku.Sku)) : null;
            var applyForPromo = cart.CartItems != null && cart.CartItems.Any(i => i.SKU.Equals(RequiredSku.Sku) && i.Quantity >= RequiredSku.Quantity);

            // Define the quantity to add
            var requiredSkuQuantityInCart = cart.CartItems == null ? 0 : cart.CartItems.Where(i => i.SKU == RequiredSku.Sku).Sum(i => i.Quantity);
            var remainder       = 0;
            var allowedQuantity = Math.DivRem(requiredSkuQuantityInCart, RequiredSku.Quantity, out remainder);

            if (!applyForPromo || !isRuleTime)
            {
                if (isPromoInCart)
                {
                    cart.DeleteItemsFromCart(new List <string> {
                        PromoSku.Sku
                    }, true);
                    var message = "HTML|PromotionalSKU087PRemoved.html";
                    result.AddMessage(message);
                    result.Result = RulesResult.Feedback;
                }

                // Nothing to do
                cart.RuleResults.Add(result);
                return(result);
            }

            if (promoInCart != null)
            {
                if (promoInCart.Quantity == allowedQuantity)
                {
                    // Nothing to do
                    result.Result = RulesResult.Success;
                    cart.RuleResults.Add(result);
                    return(result);
                }
                if (promoInCart.Quantity > allowedQuantity)
                {
                    // Remove the promo sku if quantity to add is minor than the quantity in cart
                    cart.DeleteItemsFromCart(new List <string> {
                        PromoSku.Sku
                    }, true);
                    var message = "HTML|PromotionalSKU087PRemoved.html";
                    result.AddMessage(message);
                    result.Result = RulesResult.Feedback;
                    isPromoInCart = false;
                }
                else
                {
                    if (cart.CurrentItems != null && cart.CurrentItems.Count > 0 && cart.CurrentItems[0].SKU.Equals(PromoSku.Sku))
                    {
                        allowedQuantity      = promoInCart.Quantity;
                        cart.IsPromoNotified = false;
                    }
                    cart.DeleteItemsFromCart(new List <string> {
                        PromoSku.Sku
                    }, true);
                    isPromoInCart        = false;
                    cart.IsPromoNotified = true;
                }
            }
            else
            {
                cart.IsPromoNotified = true;
            }

            // Check promo sku  in catalog info
            var allSkus = CatalogProvider.GetAllSKU(Locale);

            if (!allSkus.Keys.Contains(PromoSku.Sku))
            {
                if (Environment.MachineName.IndexOf("PROD", StringComparison.Ordinal) < 0)
                {
                    var    country = new RegionInfo(new CultureInfo(Locale, false).LCID);
                    string message = "NoPromoSku";
                    var    globalResourceObject = HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform), "NoPromoSku");
                    if (globalResourceObject != null)
                    {
                        message = string.Format(globalResourceObject.ToString(), country.DisplayName, PromoSku.Sku);
                    }
                    result.Result = RulesResult.Feedback;
                    result.AddMessage(message);
                    cart.RuleResults.Add(result);
                    return(result);
                }
                return(result);
            }

            // Adding promo sku if possible
            if (!isPromoInCart && !string.IsNullOrEmpty(cart.DeliveryInfo.WarehouseCode))
            {
                WarehouseInventory warehouseInventory;
                var catItemPromo = CatalogProvider.GetCatalogItem(PromoSku.Sku, Country);
                if (catItemPromo.InventoryList.TryGetValue(cart.DeliveryInfo.WarehouseCode, out warehouseInventory))
                {
                    if (warehouseInventory != null)
                    {
                        var warehouseInventory01 = warehouseInventory as WarehouseInventory_V01;
                        if (warehouseInventory01 != null && warehouseInventory01.QuantityAvailable > allowedQuantity)
                        {
                            if (cart.IsPromoNotified)
                            {
                                var message = "HTML|PromotionalSku087PAdded.html";
                                result.AddMessage(message);
                                result.Result        = RulesResult.Feedback;
                                cart.IsPromoNotified = false;
                            }
                            else
                            {
                                result.Result = RulesResult.Success;
                            }
                            cart.AddItemsToCart(new List <ShoppingCartItem_V01>(new[] { new ShoppingCartItem_V01(0, PromoSku.Sku, allowedQuantity, DateTime.Now) }), true);
                            cart.RuleResults.Add(result);
                        }
                    }
                }
            }

            return(result);
        }
예제 #17
0
        private void displayBadgePromo()
        {
            divPromo.Visible = false;
            List <CatalogItem>           badgePromoList = new List <CatalogItem>();
            Dictionary <string, SKU_V01> allsku         = null;

            if (ShoppingCart != null && ShoppingCart.CartItems.Any())
            {
                if (ShoppingCart.DeliveryInfo == null || string.IsNullOrEmpty(ShoppingCart.DeliveryInfo.WarehouseCode))
                {
                    return;
                }
                if (CatalogProvider.IsPreordering(ShoppingCart.CartItems, ShoppingCart.DeliveryInfo.WarehouseCode))
                {
                    return;
                }
                if (!(ShoppingCart.OrderCategory == ServiceProvider.CatalogSvc.OrderCategoryType.RSO))
                {
                    return;
                }
                if (APFDueProvider.hasOnlyAPFSku(ShoppingCart.CartItems, Locale))
                {
                    return;
                }
            }
            else
            {
                divPromo.Visible = false;
                promotionPanel.Update();
                return;
            }

            //var profile = DistributorOrderingProfileProvider.GetProfile(ShoppingCart.DistributorID, ShoppingCart.DeliveryInfo.Address.Address.Country);
            var memberId = String.IsNullOrEmpty(ShoppingCart.SrPlacingForPcOriginalMemberId) ?
                           ShoppingCart.DistributorID :
                           ShoppingCart.SrPlacingForPcOriginalMemberId;

            if (ChinaPromotionProvider.IsEligibleForBadgePromotion(ShoppingCart, HLConfigManager.Platform, memberId))
            {
                var cacheKey = string.Format("GetBadgePromoDetail_{0}", memberId);
                var results  = HttpRuntime.Cache[cacheKey] as GetBadgePinResponse_V01;

                if (results != null)
                {
                    var badgeList = results.BadgeDetails;
                    if (results != null && badgeList.Length > 0)
                    {
                        if (ShoppingCart != null && ShoppingCart.CartItems.Count > 0)
                        {
                            if (cblFreeGiftlist.Items.Count > 0)
                            {
                                cblFreeGiftlist.Items.Clear();
                            }

                            allsku = ProductsBase.ProductInfoCatalog.AllSKUs;

                            foreach (var badge in badgeList)
                            {
                                if (allsku.ContainsKey(badge.BadgeCode))
                                {
                                    var sku = allsku[badge.BadgeCode];
                                    if (ShoppingCartProvider.CheckInventory(sku.CatalogItem, badge.Quantity, ProductsBase.CurrentWarehouse) > 0 &&
                                        CatalogProvider.GetProductAvailability(sku, ProductsBase.CurrentWarehouse) == ProductAvailabilityType.Available)
                                    {
                                        cblFreeGiftlist.Items.Add(
                                            new ListItem
                                        {
                                            Selected = true,
                                            Text     = String.Format(s_promotionItemDisplayFormat, badge.BadegName, badge.Quantity),
                                            Value    = sku.SKU
                                        });
                                        //divPromo.Visible = true;
                                        badgePromoList.Add(sku.CatalogItem);
                                    }
                                }
                            }

                            //var myShoppingCart = ProductsBase.ShoppingCart;

                            var promoInCart = ShoppingCart.CartItems.Select(c => c.SKU).Intersect(badgePromoList.Select(f => f.SKU));
                            if (promoInCart.Any())
                            {
                                foreach (var x in promoInCart)
                                {
                                    var foundItems = new List <ListItem>();
                                    foreach (ListItem item in cblFreeGiftlist.Items)
                                    {
                                        if (item.Value == x)
                                        {
                                            foundItems.Add(item);
                                        }
                                    }

                                    foundItems.ForEach(f => cblFreeGiftlist.Items.Remove(f));
                                }
                            }
                            else
                            {
                                btnAddToCart.Enabled = true;
                                //  ShoppingCart.HastakenSrPromotion = false;
                                lblFreeGift.Text = GetLocalResourceObject("lblFreeGiftResource1.Text") as string;
                            }
                            if (ShoppingCart.CartItems.Count >= 1)
                            {
                                var others = ShoppingCart.CartItems.Where(s => !s.IsPromo)
                                             .Select(c => c.SKU)
                                             .Except(APFDueProvider.GetAPFSkuList());
                                if (!others.Any())
                                {
                                    if (promoInCart.Any())
                                    {
                                        ShoppingCart.DeleteItemsFromCart(promoInCart.ToList(), true);
                                    }
                                }
                            }

                            divPromo.Visible = cblFreeGiftlist.Items.Count > 0;
                        }
                    }
                    else
                    {
                        var itemsInBoth = ShoppingCart.CartItems
                                          .Where(x => x.IsPromo)
                                          .Select(c => c.SKU)
                                          .Intersect(badgeList.Select(b => b.BadgeCode), StringComparer.OrdinalIgnoreCase);

                        if (itemsInBoth.Any())
                        {
                            ShoppingCart.DeleteItemsFromCart(itemsInBoth.ToList(), true);
                        }
                    }
                }
            }
            promotionPanel.Update();
        }