private bool CanBuy_eLearningRule(MyHLShoppingCart hlCart)
        {
            bool   retVal       = true;
            var    session      = SessionInfo.GetSessionInfo(hlCart.DistributorID, hlCart.Locale);
            string trainingCode = HLConfigManager.Configurations.ShoppingCartConfiguration.TrainingCode;

            if (session.DsTrainings == null)
            {
                session.DsTrainings = DistributorOrderingProfileProvider.GetTrainingList(hlCart.DistributorID, hlCart.CountryCode);
            }

            if (session.DsTrainings != null && session.DsTrainings.Count > 0 && session.DsTrainings.Exists(t => t.TrainingCode == trainingCode && !t.TrainingFlag))
            {
                var     currentLimits       = PurchasingLimitProvider.GetCurrentPurchasingLimits(hlCart.DistributorID);
                decimal currentVolumePoints = hlCart.VolumeInCart;

                var currentItem = CatalogProvider.GetCatalogItem(hlCart.CurrentItems[0].SKU, Country);
                currentVolumePoints += currentItem.VolumePoints * hlCart.CurrentItems[0].Quantity;
                if (currentLimits.PurchaseLimitType == PurchaseLimitType.Volume)
                {
                    currentVolumePoints += (currentLimits.maxVolumeLimit - currentLimits.RemainingVolume);
                }

                if (currentVolumePoints > HLConfigManager.Configurations.ShoppingCartConfiguration.eLearningMaxPPV)
                {
                    retVal = false;
                }
            }


            return(retVal);
        }
Example #2
0
        private bool CanBuy_eLearningRule(MyHLShoppingCart hlCart)
        {
            bool retVal = true;

            if (PurchaseRestrictionProvider.RequireTraining(hlCart.DistributorID, hlCart.Locale, hlCart.CountryCode))
            {
                //var currentLimits = PurchasingLimitProvider.GetCurrentPurchasingLimits(hlCart.DistributorID);
                var currentLimits = GetCurrentPurchasingLimits(hlCart.DistributorID, GetCurrentOrderMonth());

                decimal currentVolumePoints = hlCart.VolumeInCart;
                if (hlCart.ItemsBeingAdded != null && hlCart.ItemsBeingAdded.Any())
                {
                    foreach (var i in hlCart.ItemsBeingAdded)
                    {
                        var currentItem = CatalogProvider.GetCatalogItem(i.SKU, Country);
                        currentVolumePoints += currentItem.VolumePoints * i.Quantity;
                    }
                }

                currentVolumePoints += (currentLimits.maxVolumeLimit - currentLimits.RemainingVolume);

                if (currentVolumePoints > HLConfigManager.Configurations.ShoppingCartConfiguration.eLearningMaxPPV)
                {
                    if (hlCart.ItemsBeingAdded != null)
                    {
                        hlCart.ItemsBeingAdded.Clear();
                    }
                    retVal = false;
                }
            }
            return(retVal);
        }
Example #3
0
        public static DistributorShoppingCartItem GetCatalogItems(int id, int qty, string sku, string countrylocal)
        {
            CatalogItem_V01 catalog = CatalogProvider.GetCatalogItem(sku, countrylocal.Substring(3));

            if (catalog == null)
            {
                return(new DistributorShoppingCartItem
                {
                    ID = id,
                    MinQuantity = 1,
                    PartialBackordered = false,
                    Quantity = qty,
                    SKU = sku,
                    Updated = DateTime.Now,
                });
            }
            else
            {
                return(new DistributorShoppingCartItem
                {
                    ID = id,
                    MinQuantity = 1,
                    PartialBackordered = false,
                    Quantity = qty,
                    SKU = sku,
                    Updated = DateTime.Now,
                    CatalogItem = catalog,
                    Description = catalog.Description
                });
            }
        }
Example #4
0
        public void PerformDiscountRules(ShoppingCart_V02 cart, Order_V01 order, string locale)
        {
            MyHLShoppingCart shoppingCart = cart as MyHLShoppingCart;
            var member = (MembershipUser <DistributorProfileModel>)Membership.GetUser();

            decimal CartVolume = 0.0M;

            foreach (ShoppingCartItem_V01 CartItem in shoppingCart.CartItems)
            {
                var item = CatalogProvider.GetCatalogItem(CartItem.SKU, shoppingCart.CountryCode);
                if (item != null)
                {
                    CartVolume += (item.VolumePoints) * CartItem.Quantity;
                }
            }

            List <string> codes = new List <string>(CountryType.VE.HmsCountryCodes);

            if (order != null && shoppingCart != null && CartVolume >= 500 &&
                member.Value.TypeCode != "SP" && codes.Contains(member.Value.ProcessingCountryCode))
            {
                order.UseSlidingScale    = false;
                order.DiscountPercentage = 42;
            }
        }
Example #5
0
        public void PerformBackorderRules_Inventory_pt_BR()
        {
            var testSettings = new OrderingTestSettings("pt-BR", "webtest1");
            var target       = new Ordering.Rules.Inventory.pt_BR.InventoryRules();

            var cart = MyHLShoppingCartGenerator.GetBasicShoppingCart(
                testSettings.Distributor, testSettings.Locale, "RSP", "BM", false, null, new List <DistributorShoppingCartItem>
            {
                ShoppingCartItemHelper.GetShoppingCartItem(1, 1, "0141")
            }, OrderCategoryType.RSO);
            CatalogItem item = CatalogProvider.GetCatalogItem("0141", "BR");
            int         PreviousItemsCount = cart.CartItems.Count();

            target.PerformBackorderRules(cart, item);
            int NowItemsCount = cart.CartItems.Count();

            if (!cart.RuleResults.Any())
            {
                Assert.AreEqual(PreviousItemsCount, NowItemsCount);
            }
            else if (cart.RuleResults.Any() && cart.RuleResults[0].Messages.Count > 0)
            {
                Assert.AreEqual(RulesResult.Failure, cart.RuleResults[0].Result);
            }
        }
        private bool CheckInventory(string skuToCheck, int quantity)
        {
            int inventoryQty = 0;

            if (!string.IsNullOrEmpty(skuToCheck))
            {
                CatalogItem_V01 catItem = CatalogProvider.GetCatalogItem(skuToCheck, this.ProductsBase.CountryCode);
                if (catItem != null)
                {
                    WarehouseInventory warehouseInventory;
                    if (catItem.InventoryList != null && catItem.InventoryList.TryGetValue(ProductsBase.CurrentWarehouse, out warehouseInventory))
                    {
                        var warehouseInventory01 = warehouseInventory as WarehouseInventory_V01;
                        if (warehouseInventory01 != null && !warehouseInventory01.IsBlocked)
                        {
                            inventoryQty = ShoppingCartProvider.CheckInventory(catItem, quantity,
                                                                               this.ProductsBase.CurrentWarehouse);
                        }
                    }
                }
            }

            lblError.Text = inventoryQty > 0 ? string.Empty :
                            string.Format(MyHL_ErrorMessage.OutOfInventory, skuToCheck);

            return(inventoryQty > 0);
        }
        private void displayLocaleSpecificRadioButtons()
        {
            string primarySku   = HLConfigManager.Configurations.DOConfiguration.TodayMagazineSku;
            string secondarySku = HLConfigManager.Configurations.DOConfiguration.TodayMagazineSecondarySku;

            MyHLShoppingCart cart = (ProductsBase).ShoppingCart;

            //checks if primary sku is present in the catalog.
            CatalogItem_V01 catItem = CatalogProvider.GetCatalogItem(primarySku,
                                                                     (this.Page as ProductsBase).CountryCode);

            if (catItem != null && !IsBlocked(catItem))
            {
                this.divTodaysMagazine.Visible = true;
                displayTodaysMagazine(true);
                //SetlocaleDescription(Locale.Substring(3));
                //this.rbSecondaryLanguage.Visible = false;
            }
            else //Primary sku not present, do not display both primary and secondary.
            {
                this.rbPrimaryLanguage.Visible   = false;
                this.rbSecondaryLanguage.Visible = false;
                this.divTodaysMagazine.Visible   = false;
                this.divTodaysMagazine.Style.Add(System.Web.UI.HtmlTextWriterStyle.Display, "none");
                displayTodaysMagazine(false);
                return;
            }

            //if secondary sku is not present, then do not show the radio buttons.
            if (secondarySku.Equals(string.Empty))
            {
                this.rbPrimaryLanguage.Visible   = false;
                this.rbSecondaryLanguage.Visible = false;
                return;
            }

            //if primary sku is present, check for secondary sku in the catalog.
            CatalogItem_V01 catSecItem = CatalogProvider.GetCatalogItem(secondarySku, (this.Page as ProductsBase).CountryCode);

            if (catSecItem != null && !IsBlocked(catSecItem))
            {
                //SetlocaleDescription(Locale.Substring(3));
                this.rbSecondaryLanguage.Visible = true;
            }
            else
            {
                this.rbPrimaryLanguage.Visible       =
                    this.rbSecondaryLanguage.Visible = false;
            }

            //Set the default selection to primary...
            if ((this.rbPrimaryLanguage != null) && (this.rbSecondaryLanguage != null))
            {
                this.rbPrimaryLanguage.Checked   = true;
                this.rbSecondaryLanguage.Checked = false;
            }
        }
Example #8
0
            private static decimal GetRetailPrice(string sku, int quantity, decimal unitPrice)
            {
                var SkuPrice = CatalogProvider.GetCatalogItem(sku, "CN");

                if (SkuPrice != null)
                {
                    return(SkuPrice.ListPrice * quantity);
                }

                return(unitPrice);
            }
Example #9
0
        private bool IsElegibleForPromo(ShoppingCart_V02 cart, MyHLShoppingCart hlCart, out decimal volume)
        {
            var isElegible = false;

            volume = 0;

            LoggerHelper.Info(
                string.Format("CheckPromoInCart.ShoppingCart V02 items {0}",
                              string.Concat(cart.CartItems.Select(i => string.Format("{0},", i.SKU)))));
            LoggerHelper.Info(
                string.Format("CheckPromoInCart.MyHLShoppingCart items {0}",
                              string.Concat(hlCart.CartItems.Select(i => string.Format("{0},", i.SKU)))));
            LoggerHelper.Info(
                string.Format("AllowedSKUToAddPromoSKU {0}",
                              string.Concat(AllowedSKUToAddPromoSKU.Select(i => string.Format("{0},", i)))));

            var cartItemsV02 = (from a in AllowedSKUToAddPromoSKU
                                join b in cart.CartItems on a equals b.SKU
                                select
                                new
            {
                Sku = b.SKU,
                Qty = b.Quantity,
                Volume = CatalogProvider.GetCatalogItem(b.SKU, "IT").VolumePoints
            }).ToList();

            if (cartItemsV02.Any())
            {
                isElegible = true;
                volume     = cartItemsV02.Sum(oi => oi.Qty * oi.Volume);
            }
            else
            {
                var shoppingcartItemsV02 = (from a in AllowedSKUToAddPromoSKU
                                            join b in hlCart.ShoppingCartItems on a equals b.SKU
                                            select
                                            new { Sku = b.SKU, Qty = b.Quantity, Volume = b.CatalogItem.VolumePoints })
                                           .ToList();

                if (shoppingcartItemsV02.Any())
                {
                    isElegible = true;
                    volume     = shoppingcartItemsV02.Sum(oi => oi.Qty * oi.Volume);
                }
                else
                {
                    LoggerHelper.Info("No Items in Cart or MyHLCart. Rule fails");
                }
            }

            return(isElegible);
        }
Example #10
0
        private ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart, ShoppingCartRuleReason reason, ShoppingCartRuleResult Result)
        {
            if (reason == ShoppingCartRuleReason.CartItemsBeingAdded)
            {
                CatalogItem_V01 currentItem = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU, Country);

                try
                {
                    List <string> codes = new List <string>(CountryType.TH.HmsCountryCodes);
                    codes.Add(CountryType.TH.Key);
                    bool isCOPThai        = codes.Contains(DistributorProfileModel.ProcessingCountryCode);
                    TaxIdentification tid = null;

                    var tins = DistributorOrderingProfileProvider.GetTinList(cart.DistributorID, true);
                    tid = tins.Find(t => t.IDType.Key == "THID");
                    //Simulate the dummy tin with an foreign DS
                    //TaxIdentification ti = new TaxIdentification() { CountryCode = "TH", ID = "dummy", IDType = new TaxIdentificationType(dummyTin) };
                    //ods.Value.TinList.Add(ti);

                    if (CanPurchase(cart.DistributorID, Country))
                    {
                        //Additional Check to allow DS COP = Thai Tin = No TIN, Can place only L and A items
                        if (IsWithOutTinCode)
                        {
                            if (currentItem.ProductType == ProductType.Product)
                            {
                                Result.Result = RulesResult.Failure;
                                Result.AddMessage(HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform), "CantPurchase").ToString());
                                cart.RuleResults.Add(Result);
                            }
                        }
                    }
                    else
                    {
                        if (IsWithOutTinCode)
                        {
                            if (currentItem.ProductType == ProductType.Product)
                            {
                                Result.Result = RulesResult.Failure;
                                Result.AddMessage(HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform), "CantPurchase").ToString());
                                cart.RuleResults.Add(Result);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LoggerHelper.Error(string.Format("Error while performing Add to Cart Rule for Singapore distributor: {0}, Cart Id:{1}, \r\n{2}", cart.DistributorID, cart.ShoppingCartID, ex.ToString()));
                }
            }
            return(Result);
        }
Example #11
0
        private ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart,
                                                    ShoppingCartRuleReason reason,
                                                    ShoppingCartRuleResult Result)
        {
            if (reason == ShoppingCartRuleReason.CartItemsBeingAdded)
            {
                List <string> codes = new List <string>(CountryType.KZ.HmsCountryCodes);
                codes.Add(CountryType.KZ.Key);
                bool isCOPKZ = codes.Contains(DistributorProfileModel.ProcessingCountryCode);
                if (!isCOPKZ)
                {
                    return(Result);
                }

                if (!HasActiveAppTinCode(cart.DistributorID))
                {
                    try
                    {
                        var cartVolume  = 0m;
                        var currentItem = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU, Country);
                        var myCart      = cart as MyHLShoppingCart;
                        if (myCart != null && !string.IsNullOrEmpty(myCart.VolumeInCart.ToString()))
                        {
                            cartVolume = myCart.VolumeInCart;
                        }
                        var newVolumePoints = currentItem.VolumePoints * cart.CurrentItems[0].Quantity;

                        if (cartVolume + newVolumePoints > MaxVolPoints)
                        {
                            Result.AddMessage(
                                string.Format(
                                    HttpContext.GetGlobalResourceObject(
                                        string.Format("{0}_Rules", HLConfigManager.Platform), "VolumePointExceeds")
                                    .ToString(), cart.CurrentItems[0].SKU));
                            Result.Result = RulesResult.Failure;
                            cart.RuleResults.Add(Result);
                            return(Result);
                        }
                    }
                    catch (Exception ex)
                    {
                        LoggerHelper.Error(
                            string.Format(
                                "Error while performing Add to Cart Rule for Belarus distributor: {0}, Cart Id:{1}, \r\n{2}",
                                cart.DistributorID, cart.ShoppingCartID, ex.ToString()));
                    }
                }
            }


            return(Result);
        }
        private ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart,
                                                    ShoppingCartRuleReason reason,
                                                    ShoppingCartRuleResult Result)
        {
            if (reason == ShoppingCartRuleReason.CartItemsBeingAdded)
            {
                bool bEventTicket = isEventTicket(cart.DistributorID, Locale);
                var  thisCart     = cart as MyHLShoppingCart;
                if (null != thisCart)
                {
                    //Kiosk items must have inventory
                    string             sku                = thisCart.CurrentItems[0].SKU;
                    var                catItem            = CatalogProvider.GetCatalogItem(sku, Country);
                    WarehouseInventory warehouseInventory = null;

                    var isSplitted = false;

                    if (thisCart.DeliveryInfo != null && thisCart.DeliveryInfo.Option == ServiceProvider.ShippingSvc.DeliveryOptionType.Shipping &&
                        HLConfigManager.Configurations.DOConfiguration.WhCodesForSplit.Contains(thisCart.DeliveryInfo.WarehouseCode))
                    {
                        //split order scenario
                        ShoppingCartProvider.CheckInventory(catItem, thisCart.CurrentItems[0].Quantity, thisCart.DeliveryInfo.WarehouseCode, thisCart.DeliveryInfo.FreightCode, ref isSplitted);
                    }


                    if (!isSplitted && null != thisCart.DeliveryInfo && !string.IsNullOrEmpty(thisCart.DeliveryInfo.WarehouseCode) && !bEventTicket && !isNonInventoryItem(sku))
                    {
                        catItem.InventoryList.TryGetValue(thisCart.DeliveryInfo.WarehouseCode, out warehouseInventory);
                        if ((warehouseInventory != null && (warehouseInventory as WarehouseInventory_V01).QuantityAvailable <= 0) || warehouseInventory == null)
                        {
                            Result.AddMessage(string.Format(HttpContext.GetGlobalResourceObject(string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "BackOrderItem").ToString(), sku));
                            Result.Result = RulesResult.Failure;
                            cart.RuleResults.Add(Result);
                        }
                        else
                        {
                            int availQuantity = InventoryHelper.CheckInventory(thisCart, thisCart.CurrentItems[0].Quantity, catItem, thisCart.DeliveryInfo.WarehouseCode);
                            if (availQuantity - thisCart.CurrentItems[0].Quantity < 0)
                            {
                                Result.AddMessage(string.Format(HttpContext.GetGlobalResourceObject(string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "OutOfInventory").ToString(), sku));
                                Result.Result = RulesResult.Failure;
                                cart.RuleResults.Add(Result);
                            }
                        }
                    }
                }
            }

            return(Result);
        }
        protected override ShoppingCartRuleResult PerformRules(MyHLShoppingCart cart,
                                                               ShoppingCartRuleReason reason,
                                                               ShoppingCartRuleResult Result)
        {
            base.PerformRules(cart, reason, Result);
            if (cart.ItemsBeingAdded != null && cart.ItemsBeingAdded.Count > 0)
            {
                var currentlimits = GetCurrentPurchasingLimits(cart.DistributorID, GetCurrentOrderMonth());
                if (currentlimits.PurchaseLimitType == PurchaseLimitType.DiscountedRetail)
                {
                    var itemsToCalc = new List <ShoppingCartItem_V01>();
                    itemsToCalc.AddRange(cart.CartItems);

                    bool          bExceed  = false;
                    List <string> skuToAdd = new List <string>();

                    foreach (var item in cart.ItemsBeingAdded)
                    {
                        if (bExceed == true)
                        {
                            Result = reportError(cart, item, Result);
                            continue;
                        }
                        itemsToCalc.Add(item);
                        OrderTotals_V01 orderTotals = cart.Calculate(itemsToCalc, false) as OrderTotals_V01;
                        if (orderTotals != null)
                        {
                            decimal discountedRetailInCart = orderTotals.ItemTotalsList.Sum(x => (x as ItemTotal_V01).DiscountedPrice);
                            var     currentItem            = CatalogProvider.GetCatalogItem(item.SKU, Country);
                            if ((currentlimits.RemainingVolume - discountedRetailInCart < 0) && currentItem.ProductType == MyHerbalife3.Ordering.ServiceProvider.CatalogSvc.ProductType.Product)
                            {
                                Result.Result = RulesResult.Failure;
                                bExceed       = true;
                                Result        = reportError(cart, item, Result);
                                continue;
                            }
                            else
                            {
                                skuToAdd.Add(item.SKU);
                            }
                        }
                    }

                    cart.ItemsBeingAdded.RemoveAll(s => !skuToAdd.Contains(s.SKU));
                }
            }

            return(Result);
        }
Example #14
0
        /// <summary>
        /// Validate if the RequiredSKU and PromoSkU is available in Inventory.
        /// </summary>
        /// <returns></returns>
        private bool ApplyForPromo(ref ShoppingCart_V02 cart, ref MyHLShoppingCart hlCart)
        {
            var allSkus = CatalogProvider.GetAllSKU(Locale);

            // Validate if SKUs are available
            if (!allSkus.ContainsKey(RequiredSKU) || !allSkus.ContainsKey(PromoSKU))
            {
                return(false); // No requiredSKU and/or PromoSKU available in catalog
            }
            // Validatation - Recalculate PromoSKU if the RequiredSKU has been recalculate (remove items)
            if (hlCart.CartItems.Any(i => i.SKU.Equals(PromoSKU)) && hlCart.PromoQtyToAdd > 0)
            {
                var sciRequiredSKU = hlCart.CartItems.FirstOrDefault(i => i.SKU.Equals(RequiredSKU));
                var sciPromoSKU    = hlCart.CartItems.FirstOrDefault(i => i.SKU.Equals(PromoSKU));

                if (sciPromoSKU.Quantity > sciRequiredSKU.Quantity)
                {
                    // Recalculate - Remove PromoSKU
                    hlCart.DeleteItemsFromCart(new List <string>(new[] { PromoSKU }), true);
                    hlCart.AddItemsToCart(
                        new List <ShoppingCartItem_V01>(new[] { new ShoppingCartItem_V01(0, PromoSKU, sciRequiredSKU.Quantity, DateTime.Now) }), true);
                    hlCart.IsPromoDiscarted = true;
                }

                hlCart.PromoQtyToAdd = 0;
                return(false);
            }

            // Validate if PromoSKU Qty is available in inventory
            WarehouseInventory warehouseInventory;
            var catItemPromo = CatalogProvider.GetCatalogItem(PromoSKU, Country);

            if (catItemPromo.InventoryList.TryGetValue(hlCart.DeliveryInfo.WarehouseCode, out warehouseInventory))
            {
                if (warehouseInventory != null)
                {
                    var warehouseInventory01 = warehouseInventory as WarehouseInventory_V01;
                    if (warehouseInventory01 != null && warehouseInventory01.QuantityAvailable > 0)
                    {
                        hlCart.PromoQtyToAdd = cart.CurrentItems.FirstOrDefault(i => i.SKU.Equals(RequiredSKU)).Quantity;
                        hlCart.PromoQtyToAdd = warehouseInventory01.QuantityAvailable >= hlCart.PromoQtyToAdd ? hlCart.PromoQtyToAdd : warehouseInventory01.QuantityAvailable;
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #15
0
        private ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart,
                                                    ShoppingCartRuleReason reason,
                                                    ShoppingCartRuleResult Result)
        {
            if (reason == ShoppingCartRuleReason.CartItemsBeingAdded)
            {
                try
                {
                    bool bCheckProductType = false;
                    {
                        var tins = DistributorOrderingProfileProvider.GetTinList(cart.DistributorID, true);

                        if (tins.Count > 0)
                        {
                            if (tins.Find(t => t.IDType.Key == "IDID") == null) // DS has no national ID
                            {
                                bCheckProductType = true;
                            }
                        }
                        else
                        {
                            bCheckProductType = true;
                        }
                        if (bCheckProductType)
                        {
                            var currentItem = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU,
                                                                             Country);
                            if (currentItem.ProductType == ServiceProvider.CatalogSvc.ProductType.Product)
                            {
                                Result.Result = RulesResult.Failure;
                                Result.AddMessage(
                                    HttpContext.GetGlobalResourceObject(
                                        string.Format("{0}_Rules", HLConfigManager.Platform), "CantPurchase").ToString());
                                cart.RuleResults.Add(Result);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LoggerHelper.Error(
                        string.Format(
                            "Error while performing Add to Cart Rule for Indonesia distributor: {0}, Cart Id:{1}, \r\n{2}",
                            cart.DistributorID, cart.ShoppingCartID, ex));
                }
            }
            return(Result);
        }
        private ShoppingCartRuleResult AddToCart(MyHLShoppingCart cart,
                                                 ShoppingCartRuleResult Result,
                                                 string SkuToBeAdded)
        {
            var allSkus = CatalogProvider.GetAllSKU(Locale);

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

                return(Result);
            }

            //Promo items must have inventory
            var catItem = CatalogProvider.GetCatalogItem(SkuToBeAdded, Country);
            WarehouseInventory warehouseInventory = null;

            if (null != cart.DeliveryInfo && !string.IsNullOrEmpty(cart.DeliveryInfo.WarehouseCode))
            {
                if (catItem.InventoryList.TryGetValue(cart.DeliveryInfo.WarehouseCode, out warehouseInventory))
                {
                    if ((warehouseInventory as WarehouseInventory_V01).QuantityAvailable > 0)
                    {
                        cart.AddItemsToCart(
                            new List <ShoppingCartItem_V01>(new[]
                                                            { new ShoppingCartItem_V01(0, SkuToBeAdded, quantity, DateTime.Now) }), true);
                        Result.Result = RulesResult.Success;
                        cart.RuleResults.Add(Result);
                    }
                }
            }

            return(Result);
        }
        private ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart,
                                                    ShoppingCartRuleReason reason,
                                                    ShoppingCartRuleResult Result)
        {
            if (reason == ShoppingCartRuleReason.CartFreightCodeChanging)
            {
                if (cart.CurrentItems[0].SKU == _restrictedFreightCode)
                {
                    if ((_restrictedDeliverySkus.AsQueryable()
                         .Intersect(from c in cart.CartItems select c.SKU)
                         .Count()) > 0)
                    {
                        Result.Result = RulesResult.Failure;
                        Result.AddMessage(
                            HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform),
                                                                "RestrictedShippingMethodForSku").ToString());
                        cart.RuleResults.Add(Result);
                        return(Result);
                    }
                }
            }

            if (reason == ShoppingCartRuleReason.CartItemsBeingAdded)
            {
                if (_restrictedDeliverySkus.Contains(cart.CurrentItems[0].SKU))
                {
                    if (cart.FreightCode == _restrictedFreightCode)
                    {
                        CatalogItem catItem = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU, Country);
                        if (catItem != null)
                        {
                            Result.Result = RulesResult.Failure;
                            Result.AddMessage(
                                string.Format(
                                    HttpContext.GetGlobalResourceObject(
                                        string.Format("{0}_Rules", HLConfigManager.Platform),
                                        "RestrictedSkuForShippingMethod").ToString(), cart.CurrentItems[0].SKU));
                            cart.RuleResults.Add(Result);
                            return(Result);
                        }
                    }
                }
            }

            return(Result);
        }
        public static bool checkVolumeLimits(MyHLShoppingCart cart, ref decimal previousVolumePoints, ShoppingCartRuleResult Result, PurchasingLimits_V01 currentLimits, string Locale, string Country, ShoppingCartItem_V01 currentItem)
        {
            decimal DistributorRemainingVolumePoints = 0;
            decimal NewVolumePoints = 0;

            if (currentLimits.PurchaseLimitType == PurchaseLimitType.None || currentLimits.LimitsRestrictionType != LimitsRestrictionType.PurchasingLimits)
            {
                return(true);
            }
            if (null == currentLimits)
            {
                return(false);
            }

            DistributorRemainingVolumePoints = currentLimits.RemainingVolume;

            var current = CatalogProvider.GetCatalogItem(currentItem.SKU, Country);

            if (current != null)
            {
                NewVolumePoints = current.VolumePoints * currentItem.Quantity;
            }

            if (NewVolumePoints > 0)
            {
                if (currentLimits.maxVolumeLimit == -1)
                {
                    return(true);
                }
                decimal cartVolume = cart.VolumeInCart + previousVolumePoints;
                previousVolumePoints += NewVolumePoints;

                if (DistributorRemainingVolumePoints - (cartVolume + NewVolumePoints) < 0)
                {
                    Result.Result = RulesResult.Failure;
                    var orderMonth = new OrderMonth(Country);
                    var msg        = HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform) ?? string.Empty, "VolumePointExceedsOnOrderMonth") as string;
                    msg = string.Format(msg, orderMonth.CurrentOrderMonth.ToString("MM-yyyy"), DistributorRemainingVolumePoints);
                    Result.AddMessage(msg);
                    cart.RuleResults.Add(Result);
                    return(false);
                }
            }
            return(true);
        }
        private decimal ProductEarningsInCart(List <ShoppingCartItem_V01> items, decimal discountPercentage)
        {
            decimal CartEarnings = 0.0M;

            foreach (ShoppingCartItem_V01 CartItem in items)
            {
                var item = CatalogProvider.GetCatalogItem(CartItem.SKU, this.Country);
                if (item.ProductType == ServiceProvider.CatalogSvc.ProductType.Product)
                {
                    if (item != null)
                    {
                        CartEarnings += (item.EarnBase) * CartItem.Quantity * discountPercentage / 100;
                    }
                }
            }

            return(CartEarnings);
        }
Example #20
0
        private ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart,
                                                    ShoppingCartRuleReason reason,
                                                    ShoppingCartRuleResult Result)
        {
            if (reason == ShoppingCartRuleReason.CartItemsBeingAdded)
            {
                if (HasActiveAppTinCode(cart.DistributorID) && IsShippingWithInRomania(cart))
                {
                    try
                    {
                        var cartVolume  = 0m;
                        var currentItem = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU, Country);
                        var myCart      = cart as MyHLShoppingCart;
                        if (myCart != null && !string.IsNullOrEmpty(myCart.VolumeInCart.ToString()))
                        {
                            cartVolume = myCart.VolumeInCart;
                        }
                        var newVolumePoints = currentItem.VolumePoints * cart.CurrentItems[0].Quantity;

                        if (cartVolume + newVolumePoints > MaxVolPoints)
                        {
                            Result.AddMessage(
                                string.Format(
                                    HttpContext.GetGlobalResourceObject(
                                        string.Format("{0}_Rules", HLConfigManager.Platform), "VolumePointExceeds")
                                    .ToString(), cart.CurrentItems[0].SKU));
                            Result.Result = RulesResult.Failure;
                            cart.RuleResults.Add(Result);
                            return(Result);
                        }
                    }
                    catch (Exception ex)
                    {
                        LoggerHelper.Error(
                            string.Format(
                                "Error while performing Add to Cart Rule for Venezuala distributor: {0}, Cart Id:{1}, \r\n{2}",
                                cart.DistributorID, cart.ShoppingCartID, ex.ToString()));
                    }
                }
            }


            return(Result);
        }
Example #21
0
        private void ShowAddApf()
        {
            pnlAPFIsDueWithinYear.Visible = true;
            SetPanelsVisibility();
            pnlAPFPaid.Visible = false;
            // Removing the condition, in order to get the lblAPFMessage text even if the _apfIsDue field is true.
            // Defect 42710.
            //if (!_apfIsDue)
            //{
            string dueDateFormat = HLConfigManager.Configurations.APFConfiguration.DueDateDisplayFormat;

            lblAPFMessage.Text =
                string.Format(PlatformResources.GetGlobalResourceString("ErrorMessage", "APFDueDateNotification"),
                              _apfDueDate.ToString(dueDateFormat, Thread.CurrentThread.CurrentCulture));
            //}
            if (_apfDueGreaterThanOneYear)
            {
                tblEditable.Style.Add(HtmlTextWriterStyle.Display, "none");
            }
            else
            {
                tblEditable.Style.Remove(HtmlTextWriterStyle.Display);
            }
            lblAPFType.Text = GetLocalResourceObject("APFSKU_" + _apfSku) as string;
            CatalogItem item = CatalogProvider.GetCatalogItem(_apfSku, CountryCode);

            if (null != item)
            {
                lblAPFAmount.Text = string.Concat(HLConfigManager.Configurations.CheckoutConfiguration.CurrencySymbol,
                                                  " ", item.ListPrice);
            }
            int numApfs = (_apfIsDue) ? (_apfsDue - _apfsInCart) : 1;

            txtQuantity.Text = numApfs.ToString();

            txtQuantity.ReadOnly = numApfs == 1 || !APFDueProvider.CanRemoveAPF(_distributorId, Locale, _level);

            if (_apfIsDue && _level == "SP")
            {
                txtQuantity.ReadOnly = true;
            }

            btnAddToCart.Visible = true;
        }
Example #22
0
        private decimal getTotalvolumePoints(MyHLShoppingCart cart, string countryCode)
        {
            decimal vp = 0.0M;

            vp = cart.VolumeInCart;
            if (cart.ItemsBeingAdded != null && cart.ItemsBeingAdded.Count > 0)
            {
                foreach (ShoppingCartItem_V01 CartItem in cart.ItemsBeingAdded)
                {
                    var item = CatalogProvider.GetCatalogItem(CartItem.SKU, countryCode);
                    if (item != null)
                    {
                        vp += (item.VolumePoints) * CartItem.Quantity;
                    }
                }
            }

            return(vp);
        }
        private ShoppingCartRuleResult performRules(ShoppingCart_V02 cart, ShoppingCartRuleReason reason, ShoppingCartRuleResult Result)
        {
            if (reason == ShoppingCartRuleReason.CartItemsBeingAdded)
            {
                if (!DistributorIsExemptFromPurchasingLimits(cart.DistributorID))
                {
                    var cartVolume  = 0m;
                    var currentItem = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU, Country);
                    var myCart      = cart as MyHLShoppingCart;

                    if (myCart != null && !string.IsNullOrEmpty(myCart.VolumeInCart.ToString()))
                    {
                        cartVolume = myCart.VolumeInCart;
                    }

                    var newVolumePoints = currentItem.VolumePoints * cart.CurrentItems[0].Quantity;

                    if (cartVolume + newVolumePoints > MaxVolPoints)
                    {
                        Result.AddMessage(
                            string.Format(
                                HttpContext.GetGlobalResourceObject(
                                    string.Format("{0}_Rules", HLConfigManager.Platform), "VolumePointExceeds")
                                .ToString(), cart.CurrentItems[0].SKU));
                        Result.Result = RulesResult.Failure;
                        cart.RuleResults.Add(Result);
                        return(Result);
                    }

                    var codes = new List <string>(CountryType.VN.HmsCountryCodes);
                    codes.Add(CountryType.VN.Key);
                    //if (codes.Contains(DistributorProfileModel.ProcessingCountryCode) && !HasMandatoryNotes(cart.DistributorID))
                    if (codes.Contains(DistributorProfileModel.ProcessingCountryCode))
                    {
                        Result.Result = RulesResult.Feedback;
                        Result.AddMessage(HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform), "NoDistributorNotes").ToString());
                        cart.RuleResults.Add(Result);
                    }
                }
            }
            return(Result);
        }
        private ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart,
                                                    ShoppingCartRuleReason reason,
                                                    ShoppingCartRuleResult Result)
        {
            if (reason == ShoppingCartRuleReason.CartItemsBeingAdded)
            {
                var currentItem = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU, Country);

                try
                {
                    if (!CanPurchase(cart.DistributorID, Country))
                    {
                        Result.Result = RulesResult.Failure;
                        Result.AddMessage(HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform), "CantPurchase").ToString());
                        cart.RuleResults.Add(Result);
                    }
                    else
                    {
                        //Additional Check to allow Foreign DS without TinCode to purchase L and A products
                        if (!IsLocalDS && IsWithOutTinCode && currentItem.ProductType == ServiceProvider.CatalogSvc.ProductType.Product)
                        {
                            Result.Result = RulesResult.Failure;
                            Result.AddMessage(
                                string.Format(
                                    HttpContext.GetGlobalResourceObject(
                                        string.Format("{0}_Rules", HLConfigManager.Platform),
                                        "PurchaseLimitTypeProductCategory").ToString(), cart.CurrentItems[0].SKU));
                            cart.RuleResults.Add(Result);
                        }
                    }
                }
                catch (Exception ex)
                {
                    LoggerHelper.Error(
                        string.Format(
                            "Error while performing Add to Cart Rule for Singapore distributor: {0}, Cart Id:{1}, \r\n{2}",
                            cart.DistributorID, cart.ShoppingCartID, ex));
                }
            }
            return(Result);
        }
Example #25
0
        protected override ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart, ShoppingCartRuleReason reason,
                                                               ShoppingCartRuleResult Result)
        {
            if (reason == ShoppingCartRuleReason.CartItemsBeingAdded)
            {
                var currentLimits = base.GetPurchasingLimits(cart.DistributorID, string.Empty);
                var theLimits     = currentLimits[PurchasingLimitProvider.GetOrderMonth()];
                // If it's threshold volume point for all product types is counted
                if (PurchasingLimitProvider.IsOrderThresholdMaxVolume(theLimits))
                {
                    Result = base.PerformRules(cart, reason, Result);
                }
                else if (!DistributorIsExemptFromPurchasingLimits(cart.DistributorID))
                {
                    CatalogItem_V01 currentItem = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU, Country);
                    Result = base.PerformRules(cart, reason, Result);
                }
            }

            return(Result);
        }
Example #26
0
        private void ShowAddApf()
        {
            pnlAPFIsDueWithinThreeMonth.Visible = true;
            pnlAPFPaid.Visible = false;
            string dueDateFormat = HLConfigManager.Configurations.APFConfiguration.DueDateDisplayFormat;

            tblEditable.Style.Remove(HtmlTextWriterStyle.Display);
            lblAPFType.Text = GetLocalResourceObject("APFSKU_" + _apfSku) as string;
            CatalogItem item = CatalogProvider.GetCatalogItem(_apfSku, CountryCode);

            if (null != item)
            {
                lblAPFAmount.Text = string.Concat(HLConfigManager.Configurations.CheckoutConfiguration.CurrencySymbol,
                                                  " ", Math.Round(item.ListPrice, 2));
            }
            int numApfs = (_apfIsDue) ? (_apfsDue - _apfsInCart) : 1;

            txtQuantity.Text = numApfs.ToString();

            //txtQuantity.ReadOnly = numApfs == 1 || !APFDueProvider.CanRemoveAPF(_distributorId, Locale, _level);

            txtQuantity.ReadOnly = true;
            btnAddToCart.Visible = true;
            if (CatalogProvider.IsPreordering(ShoppingCart.CartItems, (ShoppingCart.DeliveryInfo != null ? ShoppingCart.DeliveryInfo.WarehouseCode : string.Empty)))
            {
                lblAPFMessage.Text = String.Format(
                    PlatformResources.GetGlobalResourceString("ErrorMessage",
                                                              "PreOrderingSku"));
                lblAPFMessage.ForeColor = Color.FromArgb(240, 56, 56);
                btnAddToCart.Visible    = false;
            }
            else
            {
                lblAPFMessage.Text =
                    string.Format(
                        PlatformResources.GetGlobalResourceString("ErrorMessage", "APFDueDateNotification"),
                        _apfDueDate.ToLongDateString());     // this will produce correct format because by defaut
                lblAPFMessage.ForeColor = Color.FromArgb(240, 56, 56);
            }
        }
Example #27
0
        protected override ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart, ShoppingCartRuleReason reason, ShoppingCartRuleResult Result)
        {
            decimal NewVolumePoints = 0m;
            decimal cartVolume      = 0m;

            if (reason == ShoppingCartRuleReason.CartItemsBeingAdded)
            {
                CatalogItem_V01 currentItem = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU, Country);

                List <string> codes = new List <string>(CountryType.PH.HmsCountryCodes);
                codes.Add(CountryType.PH.Key);

                if (!codes.Contains(DistributorProfileModel.ProcessingCountryCode))
                {
                    MyHLShoppingCart myCart = cart as MyHLShoppingCart;

                    if (!string.IsNullOrEmpty(myCart.VolumeInCart.ToString()))
                    {
                        cartVolume = myCart.VolumeInCart;
                    }

                    NewVolumePoints = currentItem.VolumePoints * cart.CurrentItems[0].Quantity;

                    if (cartVolume + NewVolumePoints > MaxVolPoints)
                    {
                        var errorMessage =
                            HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform),
                                                                "VolumePointExceeds") ??
                            "Item SKU:{0} has not been added to the cart since by adding that into the cart, you exceeded your volume points  limit.";
                        Result.AddMessage(string.Format(errorMessage.ToString(), cart.CurrentItems[0].SKU.ToString()));
                        Result.Result = RulesResult.Failure;
                        cart.RuleResults.Add(Result);
                    }
                }
            }

            return(Result);
        }
        public static decimal getDistributorPrice(ItemTotal_V01 lineItem, decimal discount, string locale)
        {
            var prodType    = ProductType.Product;
            var catalogItem = CatalogProvider.GetCatalogItem(lineItem.SKU, locale.Substring(3));

            if (catalogItem != null)
            {
                prodType = catalogItem.ProductType;
            }
            int     marketingFundPercent = discount == 31 ? 10 : 5;
            var     roundMode            = MidpointRounding.AwayFromZero;
            decimal PH            = prodType == ProductType.Literature ? 0 : Math.Round(lineItem.LinePrice * 7 / 100.0M, roundMode);
            decimal marketingFund = (lineItem.SKU == "4115" || lineItem.SKU == "4116")
                                        ? 0
                                        : Math.Round(lineItem.LinePrice * marketingFundPercent / 1000.0M, roundMode);
            decimal discountAmt = prodType == ProductType.Product
                                      ? Math.Round(lineItem.LinePrice * discount / 100.0M, roundMode)
                                      : 0;
            decimal discountedPrice = lineItem.LinePrice - discountAmt;
            decimal tax             = Math.Round(((discountedPrice + PH + marketingFund) * 10) / 100.0M, roundMode);

            return(discountedPrice + tax + marketingFund + PH);
        }
Example #29
0
        private bool verifyProducttypes(MyHLShoppingCart cart, string countryCode)
        {
            //check all the skus in cart
            foreach (ShoppingCartItem_V01 CartItem in cart.CartItems)
            {
                var item = CatalogProvider.GetCatalogItem(CartItem.SKU, countryCode);
                if (item.ProductType != ServiceProvider.CatalogSvc.ProductType.Product)
                {
                    return(false);
                }
            }
            //checking the sku to be added
            foreach (ShoppingCartItem_V01 CartItem in cart.ItemsBeingAdded)
            {
                string sku  = CartItem.SKU;
                var    item = CatalogProvider.GetCatalogItem(sku, countryCode);
                if (item.ProductType != ServiceProvider.CatalogSvc.ProductType.Product)
                {
                    return(false);
                }
            }

            return(true);
        }
        protected override ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart, ShoppingCartRuleReason reason, ShoppingCartRuleResult Result)
        {
            decimal NewVolumePoints = 0m;
            decimal cartVolume      = 0m;

            if (reason == ShoppingCartRuleReason.CartItemsBeingAdded)
            {
                CatalogItem_V01 currentItem = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU, Country);
                if (currentItem == null)
                {
                    return(Result);
                }

                List <string> codes = new List <string>(CountryType.SG.HmsCountryCodes);
                codes.Add(CountryType.SG.Key);

                var tins = DistributorOrderingProfileProvider.GetTinList(cart.DistributorID, true);
                IPurchasingLimitManager manager = new PurchasingLimitManagerFactory().GetPurchasingLimitManager(cart.DistributorID);

                if (!codes.Contains(DistributorProfileModel.ProcessingCountryCode)) // foreign DS
                {
                    //Foreign DS without local National ID they cannot purchase "P" type products.
                    if (tins != null && tins.Find(t => t.IDType.Key == "SNID") == null)
                    {
                        if (currentItem.ProductType == ServiceProvider.CatalogSvc.ProductType.Product)
                        {
                            Result.Result = RulesResult.Failure;
                            Result.AddMessage(HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform), "CantPurchase").ToString());
                            cart.RuleResults.Add(Result);
                            return(Result);
                        }
                    }
                    //Foreign DS with local National ID they can purchase P L and A type items.
                }
                if (PurchasingLimitProvider.IsRestrictedByMarketingPlan(cart.DistributorID))
                {
                    return(base.PerformRules(cart, reason, Result));
                }

                // DS with Dummy TIN No "S0000000S", can purchase any category of products up to 1100 vp per order
                if (tins != null && tins.Find(t => t.ID == "S0000000S") != null)
                {
                    MyHLShoppingCart myCart = cart as MyHLShoppingCart;
                    if (!string.IsNullOrEmpty(myCart.VolumeInCart.ToString()))
                    {
                        cartVolume = myCart.VolumeInCart;
                    }

                    NewVolumePoints = currentItem.VolumePoints * cart.CurrentItems[0].Quantity;

                    if (cartVolume + NewVolumePoints > MaxVolPoints)
                    {
                        Result.AddMessage(
                            string.Format(
                                HttpContext.GetGlobalResourceObject(
                                    string.Format("{0}_Rules", HLConfigManager.Platform), "VolumePointExceeds")
                                .ToString(), cart.CurrentItems[0].SKU));
                        Result.Result = RulesResult.Failure;
                        cart.RuleResults.Add(Result);
                        return(Result);
                    }
                    else
                    {
                        return(Result);
                    }
                }
            }

            return(Result);
        }