private ShoppingCartRuleResult CheckForInvalidSKU(ShoppingCart_V01 shoppingCart,
                                                          ShoppingCartRuleResult ruleResult)
        {
            var cart = shoppingCart as MyHLShoppingCart;

            if (cart != null)
            {
                bool    isValid      = false;
                SKU_V01 testThisItem = null;
                var     validSKUList = CatalogProvider.GetAllSKU(Locale);
                if (null != validSKUList)
                {
                    isValid = validSKUList.TryGetValue(cart.CurrentItems[0].SKU, out testThisItem);
                    if (isValid)
                    {
                        isValid = (null != testThisItem.CatalogItem);
                    }
                }

                if (!isValid)
                {
                    ruleResult.Result = RulesResult.Failure;
                    var errorMessage =
                        HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform),
                                                            "SkuIsInvalid") ??
                        "SKU {0} is not available.";
                    ruleResult.AddMessage(string.Format(errorMessage.ToString(), cart.CurrentItems[0].SKU));
                }
            }
            return(ruleResult);
        }
        private int getPTypeSKUCount(ShoppingCartItemList cartItems, ShoppingCartItem_V01 currentItem)
        {
            int     count = 0;
            SKU_V01 skuV01;

            Dictionary <string, SKU_V01> allSKUs = CatalogProvider.GetAllSKU(this.Locale);

            foreach (ShoppingCartItem_V01 item in cartItems)
            {
                if (allSKUs.TryGetValue(item.SKU, out skuV01))
                {
                    if (skuV01.CatalogItem != null &&
                        skuV01.CatalogItem.ProductType == ProductType.Product)
                    {
                        count += item.Quantity;
                    }
                }
            }
            if (currentItem != null) // include current item being added
            {
                if (allSKUs.TryGetValue(currentItem.SKU, out skuV01))
                {
                    if (skuV01.CatalogItem != null &&
                        skuV01.CatalogItem.ProductType == ProductType.Product)
                    {
                        count += currentItem.Quantity;
                    }
                }
            }
            return(count);
        }
        public InvoiceLineModel GetInvoiceLineFromSku(string sku, string locale, string countryCode, int quantity, bool isCustomer)
        {
            SKU_V01 skuItem;

            CatalogProvider.GetAllSKU(locale).TryGetValue(sku, out skuItem);
            if (null == skuItem || skuItem.CatalogItem.IsEventTicket == true)
            {
                return(null);
            }
            var retailPrice = isCustomer && (locale == "en-GB" || locale == "ko-KR")
                ? GetCustomerRetailPrice(skuItem.SKU, locale)
                : skuItem.CatalogItem.ListPrice;

            var invoiceLineModel = new InvoiceLineModel
            {
                Sku = skuItem.SKU,
                DisplayCurrencySymbol = HLConfigManager.Configurations.CheckoutConfiguration.CurrencySymbol,
                RetailPrice           = retailPrice,
                ProductCategory       = skuItem.CatalogItem.TaxCategory,
                ProductName           = string.Format("{0}{1}", skuItem.Product.DisplayName, skuItem.Description),
                ProductType           = skuItem.Product.TypeOfProduct.ToString(),
                StockingSku           = skuItem.CatalogItem.StockingSKU,
                EarnBase                = skuItem.CatalogItem.EarnBase,
                VolumePoint             = skuItem.CatalogItem.VolumePoints,
                Quantity                = quantity,
                TotalEarnBase           = quantity * skuItem.CatalogItem.EarnBase,
                TotalVolumePoint        = quantity * skuItem.CatalogItem.VolumePoints,
                TotalRetailPrice        = quantity * retailPrice,
                DisplayRetailPrice      = retailPrice.FormatPrice(),
                DisplayTotalRetailPrice = (quantity * retailPrice).FormatPrice(),
                DisplayTotalVp          = (quantity * skuItem.CatalogItem.VolumePoints).FormatPrice()
            };

            return(invoiceLineModel);
        }
Exemple #4
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);
        }
        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);
        }
Exemple #6
0
        protected void btnSubmit_OnClick(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(ddlMemberID.SelectedValue))
            {
                //Need to display user friendly mesage, will take up in the next iteration
                return;
            }
            ILoader <DistributorProfileModel, GetDistributorProfileById> distributorProfileLoader = new DistributorProfileLoader();
            var distributorProfileModel = distributorProfileLoader.Load(new GetDistributorProfileById {
                Id = ddlMemberID.SelectedValue
            });
            var pcDistInfo     = DistributorOrderingProfileProvider.GetProfile(ddlMemberID.SelectedValue, CountryCode);
            var currentSession = Providers.SessionInfo.GetSessionInfo(DistributorID, Locale);

            currentSession.ReplacedPcDistributorProfileModel    = distributorProfileModel;
            currentSession.ReplacedPcDistributorOrderingProfile = pcDistInfo;
            currentSession.IsReplacedPcOrder = true;
            base.ShoppingCart.SrPlacingForPcOriginalMemberId = currentSession.ReplacedPcDistributorOrderingProfile.Id;
            Providers.SessionInfo.SetSessionInfo(DistributorID, Locale, currentSession);
            var allSKU       = CatalogProvider.GetAllSKU(Locale);
            var SKUsToRemove = new List <string>();

            foreach (var cartitem in ShoppingCart.CartItems)
            {
                SKU_V01 PrmoSku;

                allSKU.TryGetValue(cartitem.SKU, out PrmoSku);
                if (PrmoSku != null)
                {
                    if (!PrmoSku.IsPurchasable)
                    {
                        SKUsToRemove.Add(PrmoSku.SKU.Trim());
                    }
                }
            }
            Array.ForEach(SKUsToRemove.ToArray(),
                          a => ShoppingCart.CartItems.Remove(ShoppingCart.CartItems.Find(x => x.SKU == a)));
            Array.ForEach(SKUsToRemove.ToArray(),
                          a => ShoppingCart.ShoppingCartItems.Remove(ShoppingCart.ShoppingCartItems.Find(x => x.SKU == a)));

            Response.Redirect("PriceList.aspx?ETO=False");
        }
        private List <InvoiceCategoryModel> ConvertToInvoiceCategoryModel(
            IEnumerable <CategoryProductModel> productList, int rootCategoryId, string locale, bool isCustomer)
        {
            var categoryModels = new List <InvoiceCategoryModel>();
            var allSKUS        = CatalogProvider.GetAllSKU(locale);

            foreach (var categoryProductModel in productList)
            {
                var categoryModel = new InvoiceCategoryModel
                {
                    RootCategoryId = rootCategoryId,
                    Id             = categoryProductModel.Category.ID,
                    Name           = Regex.Replace(CatalogHelper.getBreadCrumbText(categoryProductModel.Category,
                                                                                   categoryProductModel.RootCategory, categoryProductModel.Product), "<.*?>", string.Empty)
                };

                var products = from p in categoryProductModel.Product.SKUs
                               from a in allSKUS.Keys
                               where a == p.SKU && p.SKU != "9909"
                               select allSKUS[a];

                var invoiceLineModels = products.Select(product => new InvoiceLineModel
                {
                    Sku                = product.SKU,
                    StockingSku        = product.CatalogItem.StockingSKU,
                    ProductType        = product.CatalogItem.ProductType.ToString(),
                    ProductCategory    = product.CatalogItem.TaxCategory,
                    RetailPrice        = isCustomer && (locale == "en-GB" || locale == "ko-KR") ? GetCustomerRetailPrice(product.SKU, locale): product.CatalogItem.ListPrice,
                    DisplayRetailPrice = isCustomer && (locale == "en-GB" || locale == "ko-KR") ? GetCustomerRetailPrice(product.SKU, locale).FormatPrice() : product.CatalogItem.ListPrice.FormatPrice(),
                    ProductName        =
                        WebUtility.HtmlDecode(string.Format("{0} {1}",
                                                            Regex.Replace(categoryProductModel.Product.DisplayName, "<.*?>", string.Empty),
                                                            Regex.Replace(product.Description, "<.*?>", string.Empty)))
                }).ToList();

                categoryModel.Products = invoiceLineModels;
                categoryModels.Add(categoryModel);
            }
            return(categoryModels);
        }
        private Dictionary <int, SKU_V01> GetEventTicketList(ShoppingCart_V01 cart)
        {
            var eventItemList = new Dictionary <int, SKU_V01>();

            if (Helper.Instance.HasData(cart.CurrentItems))
            {
                foreach (var currentitem in cart.CurrentItems)
                {
                    var     AllSKUS = CatalogProvider.GetAllSKU(cart.Locale);
                    SKU_V01 sku_v01 = null;
                    AllSKUS.TryGetValue(currentitem.SKU, out sku_v01);
                    if (sku_v01 == null)
                    {
                        continue;
                    }
                    if (sku_v01.Product.TypeOfProduct == ProductType.EventTicket)
                    {
                        var result = cart.CartItems.FirstOrDefault(x => x.SKU == sku_v01.SKU);
                        if (result != null)
                        {
                            eventItemList.Add(currentitem.Quantity + result.Quantity, sku_v01);
                            var shoppingCart = cart as MyHLShoppingCart;
                            var listitem     = new List <string> {
                                sku_v01.SKU
                            };
                            if (shoppingCart != null)
                            {
                                shoppingCart.DeleteItemsFromCart(listitem, true);
                            }
                        }
                        else
                        {
                            eventItemList.Add(currentitem.Quantity, sku_v01);
                        }
                    }
                }
            }
            return(eventItemList);
        }
Exemple #9
0
        private ShoppingCartRuleResult CheckPromoInCart(ShoppingCart_V02 shoppingCart,
                                                        MyHLShoppingCart cart,
                                                        ShoppingCartRuleResult result)
        {
            LoggerHelper.Info(string.Format("Entered CheckPromoInCart."));
            // Define the promo quantity to add
            decimal volumeInCartForPromo = 0;
            var     applyForPromo        = IsElegibleForPromo(shoppingCart, cart, out volumeInCartForPromo);

            var allSkus = CatalogProvider.GetAllSKU(Locale);

            if (applyForPromo && !allSkus.Keys.Contains(PromotionalSku))
            {
                LoggerHelper.Info("No promo sku in catalog");
                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, PromotionalSku);
                    }
                    LoggerHelper.Error(message);
                    result.Result = RulesResult.Feedback;
                    result.AddMessage(message);
                    cart.RuleResults.Add(result);
                    return(result);
                }
                return(result);
            }

            // Define the promo quantity to add
            var elegibleQuantity = Convert.ToInt32(Math.Truncate(volumeInCartForPromo / PromotionalRequiredVolumePoints)) *
                                   PromoQuantity;
            var promoSkuInCart = (from c in cart.CartItems where c.SKU.Equals(PromotionalSku) select c).FirstOrDefault();

            if (elegibleQuantity == 0 && promoSkuInCart == null)
            {
                // Nothing to do
                LoggerHelper.Info("Not elegible for promo and not promo sku in cart");
                result.Result = RulesResult.Success;
                cart.RuleResults.Add(result);
                return(result);
            }

            if (promoSkuInCart != null)
            {
                if (promoSkuInCart.Quantity == elegibleQuantity)
                {
                    // Check if nothing to do
                    LoggerHelper.Info("Not quantity change to do in promo sku");
                    result.Result = RulesResult.Success;
                    cart.RuleResults.Add(result);
                    return(result);
                }
                if (promoSkuInCart.Quantity > elegibleQuantity)
                {
                    // Remove the promo sku if quantity to add is minor than the quantity in cart
                    LoggerHelper.Info("Removing promo sku from cart");
                    cart.DeleteItemsFromCart(new List <string> {
                        PromotionalSku
                    }, true);
                    if (elegibleQuantity == 0)
                    {
                        result.Result = RulesResult.Success;
                        cart.RuleResults.Add(result);
                        return(result);
                    }
                }
                else
                {
                    // Change item quantity adding the excess to the existent sku
                    elegibleQuantity -= promoSkuInCart.Quantity;
                }
            }

            // Adding promo if it has inventory and if it is allowed
            if (applyForPromo && cart.DeliveryInfo != null && !string.IsNullOrEmpty(cart.DeliveryInfo.WarehouseCode))
            {
                LoggerHelper.Info("Checking Inventory");
                WarehouseInventory warehouseInventory;
                var catItemPromo = CatalogProvider.GetCatalogItem(PromotionalSku, Country);
                if (catItemPromo.InventoryList.TryGetValue(cart.DeliveryInfo.WarehouseCode, out warehouseInventory))
                {
                    if (warehouseInventory != null)
                    {
                        var warehouseInventory01 = warehouseInventory as WarehouseInventory_V01;
                        if (warehouseInventory01 != null && warehouseInventory01.QuantityAvailable > elegibleQuantity)
                        {
                            cart.AddItemsToCart(
                                new List <ShoppingCartItem_V01>(new[]
                                                                { new ShoppingCartItem_V01(0, PromotionalSku, elegibleQuantity, DateTime.Now) }), true);
                            result.Result = RulesResult.Success;
                            cart.RuleResults.Add(result);
                        }
                        else
                        {
                            LoggerHelper.Info("Warehouse information is null or not enough quantity is available");
                        }
                    }
                }
                else
                {
                    LoggerHelper.Info("Not inventory list was gotten for promo sku");
                }
            }
            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);
        }
        /// <summary>
        /// The get all input.
        /// </summary>
        /// <returns>
        /// </returns>
        ///
        private List <ShoppingCartItem_V01> getAllInput(List <string> friendlyMessages)
        {
            Dictionary <string, SKU_V01> allSKUs = CatalogProvider.GetAllSKU(Locale, base.CurrentWarehouse);
            SKU_V01 skuV01 = null;

            friendlyMessages.Clear();
            errSKU.Clear();

            var      products         = new List <ShoppingCartItem_V01>();
            setError setErrorDelegate = delegate(SkuQty sku, string error, List <string> errors)
            {
                sku.Image.Visible = true;
                sku.HasError      = true;
                if (!errors.Contains(error))
                {
                    errors.Add(error);
                }
            };

            bool bNoItemSelected = true;

            for (int i = 1; i < NUMITEMS + 1; i++)
            {
                string controlID = "SKUBox" + i;
                var    ctrlSKU   = tblSKU.FindControl(controlID) as TextBox;
                var    ctrlQty   = tblSKU.FindControl("QuantityBox" + i) as TextBox;
                var    ctrlError = tblSKU.FindControl("imgError" + i) as Image;

                string strSKU = ctrlSKU.Text.Trim();
                string strQty = ctrlQty.Text;
                int    qty;
                int.TryParse(strQty, out qty);

                if (!string.IsNullOrEmpty(strSKU) && qty != 0)
                {
                    strSKU = strSKU.ToUpper();

                    // If the str has a product.
                    strSKU = strSKU.Split(new char[] { ' ' })[0];

                    AllSKUS.TryGetValue(strSKU, out skuV01);
                    if (skuV01 == null)
                    {
                        // if not valid setup error
                        setErrorDelegate(new SkuQty(controlID, strSKU, qty, ctrlError, true, true), string.Format((GetLocalResourceObject("NoSKUFound") as string), strSKU), errSKU);
                    }
                    else
                    {
                        if (CheckMaxQuantity(ShoppingCart.CartItems, qty, skuV01, errSKU))
                        {
                            if (skuList.Any(s => s.SKU == strSKU))
                            {
                                var skuQty = new SkuQty(controlID, strSKU, qty, ctrlError, true, true);
                                skuList.Add(skuQty);
                                setErrorDelegate(skuQty, string.Format((GetLocalResourceObject("DuplicateSKU") as string), strSKU), errSKU);
                                SkuQty skuToFind = skuList.Find(s => s.SKU == strSKU);
                                if (skuToFind != null)
                                {
                                    // this is to prevent dupe one to NOT be added to cart
                                    skuToFind.HasError      = true;
                                    skuToFind.Image.Visible = true;
                                }
                            }
                            else
                            {
                                skuList.Add(new SkuQty(controlID, strSKU, qty, ctrlError, false, false));
                            }
                        }
                        else
                        {
                            ctrlError.CssClass = ctrlError.CssClass.Replace("hide", string.Empty);
                        }
                    }
                }
                else if (!string.IsNullOrEmpty(strSKU) && qty <= 0)
                {
                    setErrorDelegate(new SkuQty(controlID, strSKU, qty, ctrlError, true, false), String.Format(PlatformResources.GetGlobalResourceString("ErrorMessage", "QuantityIncorrect"), strSKU), errSKU);
                }
                else
                {
                    if (strSKU.Length + strQty.Length != 0)
                    {
                        setErrorDelegate(new SkuQty(controlID, strSKU, qty, ctrlError, true, false), GetLocalResourceObject("SKUOrQtyMissing") as string, errSKU);
                    }
                }

                if (!string.IsNullOrEmpty(strSKU) || !string.IsNullOrEmpty(strQty))
                {
                    bNoItemSelected = false;
                }
            }

            if (bNoItemSelected)
            {
                errSKU.Add(PlatformResources.GetGlobalResourceString("ErrorMessage", "NoItemsSelected"));
            }
            else
            {
                try
                {
                    foreach (SkuQty s in skuList)
                    {
                        // do not need to check at this point
                        if (APFDueProvider.IsAPFSku(s.SKU))
                        {
                            setErrorDelegate(s, string.Format(PlatformResources.GetGlobalResourceString("ErrorMessage", "SKUNotAvailable"), s.SKU), errSKU);
                            continue;
                        }

                        AllSKUS.TryGetValue(s.SKU, out skuV01);
                        if (skuV01 != null)
                        {
                            HLRulesManager.Manager.ProcessCatalogItemsForInventory(Locale, this.ShoppingCart, new List <SKU_V01> {
                                skuV01
                            });
                            CatalogProvider.GetProductAvailability(skuV01, CurrentWarehouse);

                            int availQty;

                            // check isBlocked first
                            if (IsBlocked(skuV01))
                            {
                                setErrorDelegate(s, string.Format(PlatformResources.GetGlobalResourceString("ErrorMessage", "SKUNotAvailable"), s.SKU), errSKU);
                            }
                            else if (!skuV01.IsPurchasable)
                            {
                                setErrorDelegate(s, string.Format(GetLocalResourceObject("SKUCantBePurchased") as string, s.SKU), errSKU);
                            }
                            else if (skuV01.ProductAvailability == ProductAvailabilityType.Unavailable)
                            {
                                setErrorDelegate(s, string.Format(PlatformResources.GetGlobalResourceString("ErrorMessage", "SKUNotAvailable"), s.SKU), errSKU);
                            }
                            else if (HLConfigManager.Configurations.DOConfiguration.IsChina && ChinaPromotionProvider.GetPCPromoSkus(skuV01.SKU))
                            {
                                setErrorDelegate(s, string.Format(GetLocalResourceObject("SKUCantBePurchased") as string, s.SKU), errSKU);
                            }
                            else
                            {
                                int backorderCoverage = CheckBackorderCoverage(s.Qty, skuV01, friendlyMessages);
                                if (backorderCoverage == 0)
                                {
                                    // out of stock
                                    if ((availQty = ShoppingCartProvider.CheckInventory(skuV01.CatalogItem, GetAllQuantities(ShoppingCart.CartItems, s.Qty, s.SKU), CurrentWarehouse)) == 0)
                                    {
                                        setErrorDelegate(s, string.Format(MyHL_ErrorMessage.OutOfInventory, s.SKU), errSKU);
                                    }
                                    else if (availQty < GetAllQuantities(ShoppingCart.CartItems, s.Qty, s.SKU))
                                    {
                                        setErrorDelegate(s, string.Format(PlatformResources.GetGlobalResourceString("ErrorMessage", "LessInventory"), s.SKU, availQty), errSKU);
                                        HLRulesManager.Manager.PerformBackorderRules(ShoppingCart, skuV01.CatalogItem);
                                        IEnumerable <string> ruleResultMessages =
                                            from r in ShoppingCart.RuleResults
                                            where r.Result == RulesResult.Failure && r.RuleName == "Back Order"
                                            select r.Messages[0];
                                        if (null != ruleResultMessages && ruleResultMessages.Count() > 0)
                                        {
                                            errSKU.Add(ruleResultMessages.First());
                                            ShoppingCart.RuleResults.Clear();
                                        }
                                    }
                                }
                            }
                        }
                    }

                    //if (errSKU.Count == 0)
                    {
                        products.AddRange((from c in skuList
                                           where c.HasError == false
                                           select new ShoppingCartItem_V01(0, c.SKU, c.Qty, DateTime.Now)).ToList());
                    }
                }
                catch (Exception ex)
                {
                    LoggerHelper.Error(string.Format("getAllInput error:" + ex));
                }
            }

            return(products);
        }
        /// <summary>
        /// Validates if the promo should be in cart.
        /// </summary>
        /// <param name="cart">The cart.</param>
        /// <param name="result">The promo rule result.</param>
        /// <param name="requiredSkus">The required sku list.</param>
        /// <param name="promoSku">The promo sku.</param>
        /// <returns></returns>
        private ShoppingCartRuleResult CheckPromoIncart(MyHLShoppingCart cart, ShoppingCartRuleResult result, List <string> requiredSkus, string promoSku)
        {
            // Check if promo sku should be in cart
            var quantityToAdd = cart.CartItems.Where(i => requiredSkus.Contains(i.SKU)).Sum(i => i.Quantity);
            var promoInCart   = cart.CartItems.FirstOrDefault(i => i.SKU.Equals(promoSku));

            // If not elegibe for promo then nothing to do
            if (quantityToAdd == 0)
            {
                if (promoInCart != null)
                {
                    cart.DeleteItemsFromCart(new List <string> {
                        promoSku
                    }, true);
                }

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

            // Define the quantity to add
            if (promoInCart != null)
            {
                if (promoInCart.Quantity == quantityToAdd)
                {
                    // Check if nothing to do
                    result.Result = RulesResult.Success;
                    cart.RuleResults.Add(result);
                    return(result);
                }
                if (promoInCart.Quantity > quantityToAdd)
                {
                    // Remove the promo sku if quantity to add is minor than the quantity in cart
                    cart.DeleteItemsFromCart(new List <string> {
                        promoSku
                    }, true);
                }
                else
                {
                    // Change item quantity adding the excess to the existent sku
                    quantityToAdd -= promoInCart.Quantity;
                }
            }

            // Check promo items in catalog
            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.AddMessage(message);
                    cart.RuleResults.Add(result);
                }
                return(result);
            }

            //Promo items must have inventory
            var catItem = CatalogProvider.GetCatalogItem(promoSku, Country);

            if (cart.DeliveryInfo != null && !string.IsNullOrEmpty(cart.DeliveryInfo.WarehouseCode))
            {
                WarehouseInventory warehouseInventory = null;
                if (catItem.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, quantityToAdd, DateTime.Now) }), true);
                            result.Result = RulesResult.Success;
                            cart.RuleResults.Add(result);
                        }
                    }
                }
            }

            return(result);
        }
Exemple #13
0
        /// <summary>
        ///     Adds to cart.
        /// </summary>
        /// <param name="cart">The cart.</param>
        /// <param name="Result">The result.</param>
        /// <returns></returns>
        private ShoppingCartRuleResult AddToCart(MyHLShoppingCart cart, ShoppingCartRuleResult Result, int quantity, ShoppingCartRuleReason reason, bool displayMessage)
        {
            cart.IsPromoDiscarted = false;
            var allSkus = CatalogProvider.GetAllSKU(Locale);

            if (!allSkus.Keys.Contains(promoSku))
            {
                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, promoSku);
                    LoggerHelper.Error(message);
                    Result.Result = RulesResult.Failure;
                    Result.AddMessage(message);
                    cart.RuleResults.Add(Result);
                    return(Result);
                }

                return(Result);
            }

            //Promo items must have inventory
            var catItem = CatalogProvider.GetCatalogItem(promoSku, 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, promoSku, quantity, DateTime.Now) }), true);

                        string message = string.Empty;
                        if (reason == ShoppingCartRuleReason.CartItemsAdded)
                        {
                            if (displayMessage)
                            {
                                message =
                                    string.Format(
                                        HttpContext.GetGlobalResourceObject(
                                            string.Format("{0}_Rules", HLConfigManager.Platform),
                                            "PromotionalSkuAdded").ToString());
                                Result.Result = RulesResult.Feedback;
                            }
                            else if (cart.CurrentItems.Count > 0 && cart.CurrentItems[0].SKU == promoSku)
                            {
                                message       = string.Format(HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform), "NoModifyPromoSku").ToString());
                                Result.Result = RulesResult.Failure;
                            }
                            else
                            {
                                Result.Result = RulesResult.Success;
                            }
                        }
                        Result.AddMessage(message);
                        cart.IsPromoNotified = true;
                        cart.RuleResults.Add(Result);
                    }
                }
            }

            return(Result);
        }
        //4	‘P’ type items will be allowed for Back order but ‘A’ and ‘L’ items, if out of stock at the warehouse will not be allowed to be backordered.
        //a.	For items that are ‘Out of Stock’, and will be available for Back Order these items will be displayed in ‘Yellow’. (Green for Available and Red for Not Available is standard)
        //b.	When a Back Order item is added to the cart a message will be presented to alert the user that this item will be on Back Order.
        //c.	Blocks for items will over ride the item status.  If there is a block on the item then the item will not be available for purchase.
        //d.	Under NO circumstances Back Orders shall be allowed for shipping WH 25 and I1. Back orders will be allowed for product type “P” only (not “A” or “L”) for shipping WH I2.
        //e.	There will be an assumption that IBP’s will never be out of stock. Internet will not provide an exception list for ‘A’or ‘L’ items.
        private ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart,
                                                    ShoppingCartRuleReason reason,
                                                    ShoppingCartRuleResult Result)
        {
            if (reason == ShoppingCartRuleReason.CartItemsAdded && HLConfigManager.Configurations.ShoppingCartConfiguration.AllowBackorder)
            {
                bool bEventTicket = isEventTicket(cart.DistributorID, Locale);
                var  thisCart     = cart as MyHLShoppingCart;
                if (null != thisCart)
                {
                    string warehouse = string.Empty;
                    if (thisCart.DeliveryInfo != null)
                    {
                        warehouse = thisCart.DeliveryInfo.WarehouseCode;
                    }
                    if (!string.IsNullOrEmpty(warehouse) && thisCart.CurrentItems != null)
                    {
                        var  ALLSKUs         = CatalogProvider.GetAllSKU(Locale, warehouse);
                        bool isAPFSkuPresent = APFDueProvider.IsAPFSkuPresent(thisCart.CurrentItems);
                        foreach (ShoppingCartItem_V01 cartItem in thisCart.CurrentItems)
                        {
                            SKU_V01 SKU_V01;
                            if (ALLSKUs.TryGetValue(cartItem.SKU, out SKU_V01))
                            {
                                if (SKU_V01.CatalogItem.InventoryList.Values.Where(
                                        i =>
                                        (i is WarehouseInventory_V01) &&
                                        (i as WarehouseInventory_V01).WarehouseCode == warehouse &&
                                        (i as WarehouseInventory_V01).IsBackOrder).Count() > 0)
                                {
                                    if (isAPFSkuPresent)
                                    {
                                        if (APFDueProvider.IsAPFDueAndNotPaid(cart.DistributorID, Locale))
                                        {
                                            Result.AddMessage(
                                                HttpContext.GetGlobalResourceObject(
                                                    string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                                    "NoBackOrdersOnAPFOrder") as string);
                                            Result.Result = RulesResult.Failure;
                                            cart.RuleResults.Add(Result);
                                            Result.RuleName = "Back Order";
                                            //return Result;
                                        }
                                    }

                                    var isSplitted = false;
                                    ShoppingCartProvider.CheckInventory(SKU_V01.CatalogItem, cartItem.Quantity, warehouse, thisCart.DeliveryInfo.FreightCode, ref isSplitted);
                                    if (!bEventTicket && !isSplitted &&
                                        HLConfigManager.Configurations.ShoppingCartConfiguration
                                        .DisplayMessageForBackorder)
                                    {
                                        var errorMessage = HttpContext.GetGlobalResourceObject(string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                                                                               "BackOrderItem") ?? "The SKU {0} {1} added will be on back order.";
                                        Result.AddMessage(string.Format(errorMessage.ToString(), SKU_V01.SKU, SKU_V01.Description));

                                        Result.Result = RulesResult.Failure;
                                        cart.RuleResults.Add(Result);
                                        Result.RuleName = "Back Order";
                                        //return Result;
                                    }
                                }
                            }
                        }
                        return(Result);
                    }
                }
            }
            return(Result);
        }
Exemple #15
0
        private ShoppingCartRuleResult CheckPromoInCart(MyHLShoppingCart shoppingCart,
                                                        bool checkPayment,
                                                        ShoppingCartRuleResult result)
        {
            var promo = ShoppingCartProvider.GetEligibleForPromo(shoppingCart.DistributorID, shoppingCart.Locale);

            PromoSKUs = HLConfigManager.Configurations.ShoppingCartConfiguration.PromotionalSku.Split(',').ToList();

            var promoWarehouse = string.IsNullOrEmpty(HLConfigManager.Configurations.ShoppingCartConfiguration.PromotionalWarehouse) ?
                                 PromotionWarehouse : HLConfigManager.Configurations.ShoppingCartConfiguration.PromotionalWarehouse;

            var allSkus = CatalogProvider.GetAllSKU(Locale);

            if (promo != null && !allSkus.Keys.Contains(promo.Sku))
            {
                LoggerHelper.Info("No promo sku in catalog");
                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, promo.Sku);
                    }
                    LoggerHelper.Error(message);
                    result.Result = RulesResult.Feedback;
                    result.AddMessage(message);
                    shoppingCart.RuleResults.Add(result);
                    return(result);
                }
                return(result);
            }

            result = RemovePromoOnEmptyCart(shoppingCart, result);

            int selectedPaymentMethod = 0;

            if (checkPayment)
            {
                var session = SessionInfo.GetSessionInfo(shoppingCart.DistributorID, shoppingCart.Locale);
                selectedPaymentMethod = session.SelectedPaymentMethod;
            }

            var promoSkuInCart = promo != null?
                                 shoppingCart.CartItems.Where(i => i.SKU == promo.Sku).Select(i => i.SKU).ToList() :
                                     shoppingCart.CartItems.Where(i => PromoSKUs.Contains(i.SKU)).Select(i => i.SKU).ToList();

            if (promo == null && promoSkuInCart.Count == 0)
            {
                // Nothing to do
                LoggerHelper.Info("Not elegible for promo and not promo sku in cart");
                result.Result = RulesResult.Success;
                shoppingCart.RuleResults.Add(result);
                return(result);
            }

            if (shoppingCart.Totals == null)
            {
                // Nothing to do
                LoggerHelper.Info("Not able to add or remove sku. Totals are null");
                result.Result = RulesResult.Failure;
                shoppingCart.RuleResults.Add(result);
                return(result);
            }

            if (shoppingCart.CartItems.Count == 0)
            {
                // Just remove promo sku and nothing more to do
                LoggerHelper.Info("No items in cart to add promo");
                result.Result = RulesResult.Success;
                shoppingCart.RuleResults.Add(result);
                return(result);
            }

            if (promoSkuInCart.Count > 0)
            {
                // Remove promoSkus from cart
                shoppingCart.DeleteItemsFromCart(promoSkuInCart, true);

                if (!AlowedOrderSubTypes.Contains(shoppingCart.OrderSubType) ||
                    (promo != null && !shoppingCart.CartItems.Any(i => !i.SKU.Equals(promo.Sku))) ||
                    (checkPayment && selectedPaymentMethod > 1) || shoppingCart.IsPromoDiscarted)
                {
                    // Just remove promo sku and nothing more to do
                    LoggerHelper.Info("Removed promo sku in cart");
                    result.Result = RulesResult.Success;
                    shoppingCart.RuleResults.Add(result);
                    return(result);
                }
                else if (shoppingCart.IgnorePromoSKUAddition)
                {
                    shoppingCart.IgnorePromoSKUAddition = false;
                    result.Result = RulesResult.Failure;
                    string message = string.Format(HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform), "SKUCantBePurchased").ToString(), promoSkuInCart[0]);
                    result.AddMessage(message);
                    shoppingCart.RuleResults.Add(result);
                }
            }

            // Adding promo if it has inventory and if it is allowed
            if (promo != null && AlowedOrderSubTypes.Contains(shoppingCart.OrderSubType) && shoppingCart.CartItems.Any() &&
                shoppingCart.DeliveryInfo != null && !string.IsNullOrEmpty(shoppingCart.DeliveryInfo.WarehouseCode) && shoppingCart.DeliveryInfo.WarehouseCode.Equals(promoWarehouse) &&
                ((checkPayment && selectedPaymentMethod <= 1) || !checkPayment) && !shoppingCart.IsPromoDiscarted && !APFDueProvider.IsAPFSkuPresent(shoppingCart.CartItems))
            {
                LoggerHelper.Info("Checking Inventory");
                WarehouseInventory warehouseInventory;
                var catItemPromo = CatalogProvider.GetCatalogItem(promo.Sku, Country);
                if (catItemPromo.InventoryList.TryGetValue(shoppingCart.DeliveryInfo.WarehouseCode,
                                                           out warehouseInventory))
                {
                    if (warehouseInventory != null)
                    {
                        var warehouseInventory01 = warehouseInventory as WarehouseInventory_V01;
                        if (warehouseInventory01 != null && warehouseInventory01.QuantityAvailable > promo.Quantity)
                        {
                            var    country = new RegionInfo(new CultureInfo(Locale, false).LCID);
                            string message = "PromoInCart";
                            var    globalResourceObject = HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform), "PromoInCart");
                            if (globalResourceObject != null)
                            {
                                message = string.Format(globalResourceObject.ToString(), country.DisplayName);
                            }

                            shoppingCart.AddItemsToCart(
                                new List <ShoppingCartItem_V01>(new[]
                                                                { new ShoppingCartItem_V01(0, promo.Sku, promo.Quantity, DateTime.Now) }), true);

                            if (result.Result != RulesResult.Failure)
                            {
                                result.Result = checkPayment ? RulesResult.Success : (shoppingCart.IsPromoNotified ? RulesResult.Feedback : RulesResult.Success);
                                result.AddMessage(message);
                                shoppingCart.RuleResults.Add(result);
                            }
                            shoppingCart.IsPromoNotified = false;
                        }
                        else
                        {
                            LoggerHelper.Info("Warehouse information is null or not enough quantity is available");
                        }
                    }
                }
                else
                {
                    LoggerHelper.Info("Not inventory list was gotten for promo sku");
                }
            }
            return(result);
        }
Exemple #16
0
        public GetFavouriteResponseWrapper Post(SetFavouriteRequestViewModel request, string memberId)
        {
            if (request == null)
            {
                throw CreateException(HttpStatusCode.BadRequest, "Invalid or Incomplete Set Favourite SKU information", 999998);
            }

            if (request.Data.Favourites.Count < 1)
            {
                throw CreateException(HttpStatusCode.BadRequest, "Invalid or Incomplete Set Favourite SKU information", 999998);
            }
            string obj      = JsonConvert.SerializeObject(request);
            var    response = new GetFavouriteResponseWrapper
            {
                ValidationErrors = new List <ValidationErrorViewModel>(),
                Data             = new FavouriteSetSKUResponseViewModel
                {
                    Favourites = new List <FavouriteSetSKUResponseViewModelItem>()
                }
            };

            try
            {
                string locale = Thread.CurrentThread.CurrentCulture.Name;

                Dictionary <string, SKU_V01>           allSKU    = CatalogProvider.GetAllSKU(locale);
                List <FavouriteSKUUpdateItemViewModel> favorList = request.Data.Favourites;
                List <ValidationErrorViewModel>        errors    = new List <ValidationErrorViewModel>();

                IEnumerable <FavouriteSKUUpdateItemViewModel> availableList = favorList.Where(x => allSKU.Select(y => y.Key).Contains(x.ProductSKU));
                IEnumerable <FavouriteSKUUpdateItemViewModel> exceptList    = favorList.Except(availableList);


                List <FavouriteSKUUpdateItemViewModel> SKUs = new List <FavouriteSKUUpdateItemViewModel>();
                foreach (var fv in availableList)
                {
                    var sku = allSKU.Where(x => x.Key == fv.ProductSKU); //.Where(x => x.Key == fv.ProductSKU).Select(x => x.Value);

                    if (sku != null)
                    {
                        SKU_V01 pd = (SKU_V01)sku.First().Value;
                        SKUs.Add(new FavouriteSKUUpdateItemViewModel {
                            productID = int.Parse(pd.CatalogItem.StockingSKU), ProductSKU = fv.ProductSKU, Action = fv.Action
                        });
                    }
                }

                string skuList = "";
                foreach (var sku in SKUs)
                {
                    skuList += sku.productID + "," + sku.ProductSKU + "," + sku.Action + "|";
                }


                SetFavouriteParam query = new SetFavouriteParam {
                    DistributorID = memberId,
                    Locale        = Thread.CurrentThread.CurrentCulture.Name,
                    SKUList       = skuList
                };

                var result = _mobileFavouriteProvider.SetFavouriteSKUs(query, ref errors);

                if (result)
                {
                    foreach (var s in SKUs)
                    {
                        response.Data.Favourites.Add(new FavouriteSetSKUResponseViewModelItem {
                            productSKU = s.ProductSKU, Updated = true
                        });
                    }

                    if (exceptList.Any())
                    {
                        foreach (var ex in exceptList)
                        {
                            response.Data.Favourites.Add(new FavouriteSetSKUResponseViewModelItem {
                                productSKU = ex.ProductSKU, Updated = false, reason = "SKU of " + ex.ProductSKU + " not part of product master"
                            });
                        }

                        response.ValidationErrors.Add(
                            new ValidationErrorViewModel
                        {
                            Message = "Update partially successful!"
                        });
                    }
                }
                else
                {
                    response.ValidationErrors.Add(
                        new ValidationErrorViewModel
                    {
                        Message = "Update not successful, kindly contact the administrator!"
                    });
                }
                JObject json = JObject.Parse(obj);
                MobileActivityLogProvider.ActivityLog(json, response, memberId, true,
                                                      this.Request.RequestUri.ToString(),
                                                      this.Request.Headers.ToString(),
                                                      this.Request.Headers.UserAgent.ToString(),
                                                      locale);


                return(response);
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(ex.ToString());
                throw CreateException(HttpStatusCode.InternalServerError,
                                      "Internal server errror searching for Set Favourite SKU" + ex.Message, 404);
            }
        }
        /// <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);
        }