private ShoppingCartRuleResult CartItemAddedRuleHandler(ShoppingCart_V01 cart, ShoppingCartRuleResult result, string level)
        {
            var distributorId      = cart.DistributorID;
            var isAPFDueandNotPaid = APFDueProvider.IsAPFDueAndNotPaid(distributorId, Locale);

            if (isAPFDueandNotPaid && HLConfigManager.Configurations.DOConfiguration.IsChina)
            {
                string cacheKey   = string.Empty;
                bool   reloadAPFs = (null != cart && null != cart.CartItems) && isAPFDueandNotPaid &&
                                    !APFDueProvider.IsAPFSkuPresent(cart.CartItems);
                cart.APFEdited = false;
                DoApfDue(cart.DistributorID, cart, cacheKey, Locale, reloadAPFs, result, true);
            }

            try
            {
                var hlCart = cart as MyHLShoppingCart;
                if (null != hlCart)
                {
                    var isPlacing = !String.IsNullOrWhiteSpace(hlCart.SrPlacingForPcOriginalMemberId);
                    if (isPlacing)
                    {
                        var skuList = APFDueProvider.GetAPFSkuList();
                        if (skuList != null && skuList.Count > 0)
                        {
                            var items =
                                (from s in skuList
                                 from c in cart.CartItems
                                 where s == c.SKU
                                 select c.SKU).ToList();

                            if (null != items && items.Count > 0)
                            {
                                hlCart.DeleteItemsFromCart(items, true);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(
                    string.Format("APFRules.CartItemAddedRuleHandler DS:{0} locale:{2} ERR:{1}", cart.DistributorID,
                                  ex, Locale));
            }

            return(result);
        }
        protected void ddl_DSSubType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(ddl_DSSubType.SelectedItem.Value))
            {
                bool refresh = false;

                ShoppingCart.SelectedDSSubType = ddl_DSSubType.SelectedItem.Value;
                PurchasingLimits_V01 limits = PurchasingLimitProvider.GetPurchasingLimits(DistributorID,
                                                                                          ddl_DSSubType.SelectedItem
                                                                                          .Value);
                //If the order type is switched to Resale and DS has added APFs to cart, throw them out
                if (limits.PurchaseType == OrderPurchaseType.Consignment &&
                    APFDueProvider.IsAPFSkuPresent(ShoppingCart.CartItems) &&
                    !APFDueProvider.IsAPFDueAndNotPaid(DistributorID, Locale))
                {
                    ShoppingCart.DeleteItemsFromCart(APFDueProvider.GetAPFSkuList());
                    refresh = true;
                }
                if (ShoppingCart.CartItems.Count > 0)
                {
                    List <ShoppingCartRuleResult> results = HLRulesManager.Manager.ProcessCart(ShoppingCart,
                                                                                               ShoppingCartRuleReason
                                                                                               .CartCalculated);
                    if (results.Count > 0 && results.Any(r => r.Result == RulesResult.Failure))
                    {
                        foreach (ShoppingCartRuleResult result in results)
                        {
                            if (result.Result == RulesResult.Failure)
                            {
                                var args = new CartModifiedForSKULimitationsEventArgs(result.Messages[0]);
                                OnCartItemRemovedDueToSKULimitationRules(this, args);
                            }
                        }
                    }
                }
                DisplayRemainingValues(ddl_DSSubType.SelectedItem.Value, refresh);
            }
            else
            {
                ShoppingCart.SelectedDSSubType = String.Empty;
                trRemainingVal.Visible         = false;
            }
        }
Exemple #3
0
        private ShoppingCartRuleResult CartRetrievedRuleHandler(ShoppingCart_V01 cart,
                                                                ShoppingCartRuleResult result)
        {
            try
            {
                if (null != cart)
                {
                    if (APFDueProvider.IsAPFSkuPresent(cart.CartItems) &&
                        APFDueProvider.IsAPFDueAndNotPaid(cart.DistributorID, Locale))
                    {
                        var limits =
                            PurchasingLimitProvider.GetCurrentPurchasingLimits(cart.DistributorID);
                        if (null != limits && null != limits.PurchaseSubType)
                        {
                            if (limits.PurchaseType == ServiceProvider.OrderSvc.OrderPurchaseType.Consignment)
                            //No consignment allowed when APFDue
                            {
                                if (limits.PurchaseSubType == "A1")
                                {
                                    limits.PurchaseSubType = "A2";
                                }
                                if (limits.PurchaseSubType == "B1")
                                {
                                    limits.PurchaseSubType = "B2";
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(string.Format("APFRules.it-IT.ProcessAPF DS:{0} locale:{2} ERR:{1}", cart.DistributorID, ex, Locale));
            }

            return(result);
        }
        private ShoppingCartRuleResult CartRetrievedRuleHandler(ShoppingCart_V01 cart, ShoppingCartRuleResult result, string level)
        {
            if (cart != null)
            {
                var myhlCart = cart as MyHLShoppingCart;

                if (APFDueProvider.IsAPFSkuPresent(cart.CartItems) && myhlCart != null)
                {
                    // Change the APF sku according tins
                    var tins = DistributorOrderingProfileProvider.GetTinList(cart.DistributorID, true);
                    var huvt = tins.Find(p => p.IDType.Key == "HUVT");
                    var hupt = tins.Find(p => p.IDType.Key == "HUPT");
                    if (huvt != null && hupt != null)
                    {
                        myhlCart.DeleteItemsFromCart(null, true);
                        myhlCart.AddItemsToCart(new List <ShoppingCartItem_V01>(new[] { new ShoppingCartItem_V01(0, AlternAPFSku, 1, DateTime.Now) }), true);
                        return(result);
                    }
                    //Prevent to have a cart with skus Bug 148170
                    if (cart.CartItems.Count > 1)
                    {
                        //get the skus != apf
                        var nonApfItems =
                            (from c in cart.CartItems where APFDueProvider.IsAPFSku(c.SKU.Trim()) == false select c)
                            .ToList <ShoppingCartItem_V01>();
                        if (nonApfItems.Count > 0 ||
                            HLConfigManager.Configurations.APFConfiguration.StandaloneAPFOnlyAllowed)
                        {
                            var skuToBeRemoved = nonApfItems.Select(x => x.SKU).ToList();
                            myhlCart.DeleteItemsFromCart(skuToBeRemoved);
                        }
                    }
                }
            }
            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);
        }
        private ShoppingCartRuleResult CartRetrievedRuleHandler(ShoppingCart_V01 cart, ShoppingCartRuleResult result, string level)
        {
            string key = string.Format("{0}_{1}_{2}", "JustEntered", cart.DistributorID, Locale);

            bool justEntered = (Session != null && ((null != Session[key]))) ? (bool)Session[key] : true;

            if (Session != null)
            {
                Session[key] = null;
            }

            string cacheKey   = string.Empty; ////ShoppingCartProvider.GetCacheKey(distributor.Value.ID, Locale);
            bool   reloadAPFs = (null != cart && null != cart.CartItems) &&
                                APFDueProvider.IsAPFDueAndNotPaid(cart.DistributorID, Locale) &&
                                !APFDueProvider.IsAPFSkuPresent(cart.CartItems);

            var  myhlCart     = cart as MyHLShoppingCart;
            bool shouldAddAPF = ShouldAddAPFPT(myhlCart);

            if (null == cart || null == cart.CartItems || cart.CartItems.Count == 0 || reloadAPFs ||
                APFDueProvider.IsAPFSkuPresent(cart.CartItems))
            {
                try
                {
                    if (null != cart)
                    {
                        if (APFDueProvider.IsAPFDueAndNotPaid(cart.DistributorID, Locale))
                        {
                            if (justEntered || !cart.APFEdited)
                            {
                                if (shouldAddAPF)
                                {
                                    DoApfDue(cart.DistributorID, cart, cacheKey, Locale, reloadAPFs, result, justEntered);
                                }
                                else
                                {
                                    myhlCart.DeleteItemsFromCart(null, true);   //remove items from the cart since TIN is not active or member only has mailing addresses in PT
                                    return(result);
                                }
                            }
                        }
                        else
                        {
                            if (APFDueProvider.IsAPFSkuPresent(cart.CartItems))
                            {
                                if (!shouldAddAPF)                            //if APF shouldn't be present in cart
                                {
                                    myhlCart.DeleteItemsFromCart(null, true); //remove items from the cart since TIN is not active
                                    return(result);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LoggerHelper.Error(
                        string.Format("APFRules.ProcessAPF DS:{0} locale:{2} ERR:{1}", cart.DistributorID, ex, Locale));
                }
            }

            return(result);
        }
        private ShoppingCartRuleResult CartItemBeingDeletedRuleHandler(ShoppingCart_V01 cart,
                                                                       ShoppingCartRuleResult result,
                                                                       string level)
        {
            if (APFDueProvider.IsAPFDueAndNotPaid(cart.DistributorID, Locale) &&
                HLConfigManager.Configurations.APFConfiguration.StandaloneAPFOnlyAllowed)
            {
                result.Result = RulesResult.Failure;
                result.AddMessage(
                    HttpContext.GetGlobalResourceObject(string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                                        "CompleteAPFPurchase") as string);
                var sku = APFDueProvider.GetAPFSku();
                SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.StandaloneAPFOnlyAllowed,
                                   "CompleteAPFPurchase");

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

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

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

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

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

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

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

            return(result);
        }
        private ShoppingCartRuleResult CartItemBeingAddedRuleHandler(ShoppingCart_V01 cart,
                                                                     ShoppingCartRuleResult result,
                                                                     string level)
        {
            var distributorId      = cart.DistributorID;
            var isAPFDueandNotPaid = APFDueProvider.IsAPFDueAndNotPaid(distributorId, Locale);

            if (isAPFDueandNotPaid && HLConfigManager.Configurations.APFConfiguration.StandaloneAPFOnlyAllowed)
            {
                result.Result = RulesResult.Failure;
                result.AddMessage(
                    HttpContext.GetGlobalResourceObject(string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                                        "CompleteAPFPurchase") as string);
                var sku = APFDueProvider.GetAPFSku();
                SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.StandaloneAPFOnlyAllowed,
                                   "CompleteAPFPurchase");

                cart.RuleResults.Add(result);
                return(result);
            }
            else if (isAPFDueandNotPaid && HLConfigManager.Configurations.DOConfiguration.IsChina)
            {
                string cacheKey   = string.Empty;
                bool   reloadAPFs = (null != cart && null != cart.CartItems) && isAPFDueandNotPaid &&
                                    !APFDueProvider.IsAPFSkuPresent(cart.CartItems);

                DoApfDue(cart.DistributorID, cart, cacheKey, Locale, reloadAPFs, result, true);
            }

            if ((cart as MyHLShoppingCart).OrderCategory == OrderCategoryType.ETO) //No APFs allowed in ETO cart
            {
                result.Result = RulesResult.Success;
                return(result);
            }

            //cart.CurrentItems[0] contains the current item being added
            //because the provider only adds one at a time, we just need to return a single error, but aggregate to the cart errors for the UI
            if (APFDueProvider.IsAPFSku(cart.CurrentItems[0].SKU))
            {
                if (APFDueProvider.CanRemoveAPF(distributorId, Locale, level))
                {
                    if (APFDueProvider.IsAPFSku(cart.CurrentItems[0].SKU))
                    {
                        var originaItem =
                            (from c in cart.CartItems where c.SKU == cart.CurrentItems[0].SKU select c).ToList();
                        int previousQuantity = 0;
                        if (null != originaItem && originaItem.Count > 0)
                        {
                            previousQuantity = originaItem[0].Quantity;
                        }
                        if (APFDueProvider.IsAPFDueAndNotPaid(distributorId, Locale))
                        {
                            int requiredQuantity = APFDueProvider.APFQuantityDue(distributorId, Locale);
                            if (cart.CurrentItems[0].Quantity + previousQuantity <= requiredQuantity)
                            {
                                if (level == "SP")
                                {
                                    cart.CurrentItems[0].Quantity = requiredQuantity - previousQuantity;
                                    result.Result = RulesResult.Recalc;
                                    result.AddMessage(
                                        HttpContext.GetGlobalResourceObject(
                                            string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                            "RequiredAPFLeftInCart") as string);
                                    var sku = APFDueProvider.GetAPFSku();
                                    SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.CantDSRemoveAPF,
                                                       "RequiredAPFLeftInCart");
                                    cart.RuleResults.Add(result);
                                    cart.APFEdited = false;
                                    return(result);
                                }
                                else
                                {
                                    result.Result = RulesResult.Recalc;
                                    result.AddMessage(string.Empty);
                                    cart.RuleResults.Add(result);
                                    cart.APFEdited = true;
                                    return(result);
                                }
                            }
                            else if (cart.CurrentItems[0].Quantity + previousQuantity > requiredQuantity)
                            {
                                cart.CurrentItems[0].Quantity = requiredQuantity - previousQuantity;
                                result.Result = RulesResult.Recalc;
                                result.AddMessage(
                                    HttpContext.GetGlobalResourceObject(
                                        string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                        "RequiredAPFLeftInCart") as string);
                                var sku = APFDueProvider.GetAPFSku();
                                SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.CantDSRemoveAPF,
                                                   "RequiredAPFLeftInCart");
                                cart.RuleResults.Add(result);
                                cart.APFEdited = false;
                                return(result);
                            }
                        }
                        else
                        {
                            if (cart.CurrentItems[0].Quantity + previousQuantity > 1)
                            {
                                if (APFDueProvider.CanAddAPF(distributorId))
                                {
                                    result.Result = RulesResult.Failure;
                                    result.AddMessage(
                                        HttpContext.GetGlobalResourceObject(
                                            string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                            "CanOnlyPrepayOneAPF") as string);
                                    var sku = APFDueProvider.GetAPFSku();
                                    SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.CantDSRemoveAPF,
                                                       "CanOnlyPrepayOneAPF");
                                    cart.RuleResults.Add(result);
                                    cart.APFEdited = true;
                                    return(result);
                                }
                            }
                        }
                    }
                }

                if (!APFDueProvider.CanAddAPF(distributorId))
                {
                    result.Result = RulesResult.Failure;
                    result.AddMessage(
                        HttpContext.GetGlobalResourceObject(
                            string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "CannotAddAPFSku") as string);
                    var sku = APFDueProvider.GetAPFSku();
                    SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.CannotAddAPFSku,
                                       "CannotAddAPFSku");

                    cart.RuleResults.Add(result);
                    return(result);
                }
                else
                {
                    string apfSku = APFDueProvider.GetAPFSku();
                    if (cart.CurrentItems[0].SKU == apfSku)
                    {
                        cart.APFEdited = true;
                    }
                    else
                    {
                        result.Result = RulesResult.Failure;
                        result.AddMessage(
                            HttpContext.GetGlobalResourceObject(
                                string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "SkuNotValid") as string);
                        var sku = APFDueProvider.GetAPFSku();
                        SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.CannotAddAPFSku,
                                           "SkuNotValid");
                        cart.RuleResults.Add(result);
                        return(result);
                    }
                }
            }

            if (APFDueProvider.IsAPFSkuPresent(cart.CartItems))
            {
                var currentSession = SessionInfo.GetSessionInfo(cart.DistributorID, cart.Locale);
                if ((!APFDueProvider.CanEditAPFOrder(cart.DistributorID, Thread.CurrentThread.CurrentCulture.Name, level)) || (currentSession.IsAPFOrderFromPopUp))
                {
                    result.Result = RulesResult.Failure;
                    result.AddMessage(
                        HttpContext.GetGlobalResourceObject(
                            string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "CompleteAPFPurchase") as
                        string);
                    var sku = APFDueProvider.GetAPFSku();
                    SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.StandaloneAPFOnlyAllowed,
                                       "CompleteAPFPurchase");
                    cart.RuleResults.Add(result);
                    return(result);
                }
                else
                {
                    if (APFDueProvider.containsOnlyAPFSku(cart.CartItems))
                    {
                        CatalogItem item = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU, Country);
                        if (null != item)
                        {
                            if (!HLConfigManager.Configurations.APFConfiguration.AllowNonProductItemsWithStandaloneAPF)
                            {
                                if (item.ProductType != ProductType.Product)
                                {
                                    result.Result = RulesResult.Failure;
                                    result.AddMessage(
                                        HttpContext.GetGlobalResourceObject(
                                            string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                            "NoNonProductToStandaloneAPF") as string);

                                    var sku = APFDueProvider.GetAPFSku();
                                    SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.AllowNonProductItemsWithStandaloneAPF,
                                                       "NoNonProductToStandaloneAPF");

                                    cart.RuleResults.Add(result);
                                    return(result);
                                }
                            }
                            if (item.SKU == HLConfigManager.Configurations.DOConfiguration.TodayMagazineSku ||
                                item.SKU == HLConfigManager.Configurations.DOConfiguration.TodayMagazineSecondarySku)
                            {
                                result.Result = RulesResult.Failure;
                                result.AddMessage(
                                    HttpContext.GetGlobalResourceObject(
                                        string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                        "NoTodayMagazineWithStandalonAPF") as string);
                                var sku = APFDueProvider.GetAPFSku();
                                SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.StandaloneAPFOnlyAllowed,
                                                   "NoTodayMagazineWithStandalonAPF");

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

                            //To the standalone APF, DS trying to add product then change the Freight code & warehouse code.
                            else if (item.ProductType == ProductType.Product ||
                                     item.ProductType == ProductType.Literature ||
                                     item.ProductType == ProductType.PromoAccessory)
                            {
                                SetNonStandAloneAPFDeliveryOption(cart as MyHLShoppingCart);
                            }
                        }
                    }
                }
            }

            //Can add
            if (APFDueProvider.IsAPFSku(cart.CurrentItems[0].SKU))
            {
                if (cart.CurrentItems[0].Quantity < 0)
                {
                    var originaItem =
                        (from c in cart.CartItems where c.SKU == cart.CurrentItems[0].SKU select c).ToList();
                    int previousQuantity = originaItem[0].Quantity;
                    if (APFDueProvider.IsAPFDueAndNotPaid(distributorId, Locale))
                    {
                        int requiredQuantity = APFDueProvider.APFQuantityDue(distributorId, Locale);
                        if (level == "SP" || !HLConfigManager.Configurations.APFConfiguration.AllowDSRemoveAPFWhenDue)
                        {
                            if (cart.CurrentItems[0].Quantity + previousQuantity < requiredQuantity)
                            {
                                cart.CurrentItems[0].Quantity = (previousQuantity - requiredQuantity) * -1;
                                result.Result = RulesResult.Recalc;
                                result.AddMessage(
                                    HttpContext.GetGlobalResourceObject(
                                        string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                        "RequiredAPFLeftInCart") as string);
                                var sku = APFDueProvider.GetAPFSku();
                                SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.StandaloneAPFOnlyAllowed,
                                                   "RequiredAPFLeftInCart");

                                cart.RuleResults.Add(result);
                                cart.APFEdited = false;
                                return(result);
                            }
                        }
                    }
                }
            }

            return(result);
        }
        //   private void SetApfRuleResponse()

        #region Event methods

        private ShoppingCartRuleResult CartRetrievedRuleHandler(ShoppingCart_V01 cart,
                                                                ShoppingCartRuleResult result,
                                                                string level)
        {
            string key = string.Format("{0}_{1}_{2}", "JustEntered", cart.DistributorID, Locale);

            bool justEntered = (Session != null && ((null != Session[key]))) ? (bool)Session[key] : true;

            if (Session != null)
            {
                Session[key] = null;
            }

            string cacheKey   = string.Empty; ////ShoppingCartProvider.GetCacheKey(distributor.Value.ID, Locale);
            bool   reloadAPFs = (null != cart && null != cart.CartItems) &&
                                APFDueProvider.IsAPFDueAndNotPaid(cart.DistributorID, Locale) &&
                                !APFDueProvider.IsAPFSkuPresent(cart.CartItems);

            if (null == cart || null == cart.CartItems || cart.CartItems.Count == 0 || reloadAPFs ||
                APFDueProvider.IsAPFSkuPresent(cart.CartItems))
            {
                try
                {
                    if (null != cart)
                    {
                        if (APFDueProvider.IsAPFDueAndNotPaid(cart.DistributorID, Locale))
                        {
                            if (justEntered || !cart.APFEdited)
                            {
                                DoApfDue(cart.DistributorID, cart, cacheKey, Locale, reloadAPFs, result, justEntered);
                            }
                        }
                        else
                        {
                            if (APFDueProvider.IsAPFSkuPresent(cart.CartItems))
                            {
                                var currentSession = SessionInfo.GetSessionInfo(cart.DistributorID, cart.Locale);
                                if ((!cart.APFEdited ||
                                     !APFDueProvider.CanEditAPFOrder(cart.DistributorID, Locale, level)) && (currentSession != null && !currentSession.IsAPFOrderFromPopUp))
                                {
                                    var skuList = APFDueProvider.GetAPFSkuList();
                                    if (skuList != null && skuList.Count > 0)
                                    {
                                        var hlCart = cart as MyHLShoppingCart;
                                        if (null != hlCart)
                                        {
                                            var items =
                                                (from s in skuList
                                                 from c in cart.CartItems
                                                 where s == c.SKU
                                                 select c.SKU).ToList();
                                            if (null != items && items.Count > 0)
                                            {
                                                hlCart.DeleteItemsFromCart(items);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LoggerHelper.Error(
                        string.Format("APFRules.ProcessAPF DS:{0} locale:{2} ERR:{1}", cart.DistributorID,
                                      ex, Locale));
                }
            }

            return(result);
        }
Exemple #10
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 #11
0
        protected void checkoutClicked(object sender, EventArgs e)
        {
            if (!CheckDSCantBuyStatus())
            {
                return;
            }

            CheckHAPOptions();

            ProceedingToCheckoutFromMiniCart(this, null);

            if (_errors.Count > 0)
            {
                //this.noItemToPurchase.Visible = true;
                //this.noItemToPurchase.Text = _errors[0];
                (Page.Master as OrderingMaster).Status.AddMessage(
                    StatusMessageType.Error, _errors[0]);
                return;
            }
            if (!String.IsNullOrEmpty(HLConfigManager.Configurations.DOConfiguration.PurchasingLimitsControl))
            {
                //if (PurchasingLimitProvider.RequirePurchasingLimits(this.DistributorID, this.CountryCode))
                //{

                //Check Value Selected in Drop Down
                if (String.IsNullOrEmpty(ShoppingCart.SelectedDSSubType))
                {
                    //TODO- Replace with resource entry
                    noItemToPurchase.Visible = true;
                    noItemToPurchase.Text    = GetLocalResourceObject("OrderTypeNotSelected").ToString();
                    return;
                }
                //}
            }

            if (!CheckDRFraud())
            {
                return;
            }

            noItemToPurchase.Visible = false;
            errDRFraud.Visible       = false;
            //}
            //else
            //{
            //    this.noItemToPurchase.Visible = true;
            //}

            bool isNotified;

            bool.TryParse(Session["isNonResidentNotified"] != null ? Session["isNonResidentNotified"].ToString() : "false", out isNotified);

            if (HLConfigManager.Configurations.DOConfiguration.DisplayNonResidentsMessage && !isNotified)
            {
                var member = (MembershipUser <DistributorProfileModel>)System.Web.Security.Membership.GetUser();

                if (ShoppingCart.DeliveryInfo != null && ShoppingCart.DeliveryInfo.Option == ServiceProvider.ShippingSvc.DeliveryOptionType.Pickup &&
                    !SessionInfo.IsEventTicketMode && !APFDueProvider.IsAPFSkuPresent(ShoppingCart.CartItems) &&
                    member != null && member.Value != null && !member.Value.ProcessingCountryCode.Equals(CountryCode))
                {
                    Session["isNonResidentNotified"] = Session["displayNonResidentModal"] = true;
                    (this.Master as OrderingMaster).DisplayHtml("NonResidentsDisclaimer.html");
                    return;
                }
            }

            if (SessionInfo != null && !SessionInfo.IsFirstTimeSpainPopup && ShoppingCart != null && ShoppingCart.Locale == "es-ES" && !APFDueProvider.containsOnlyAPFSku(ShoppingCart.CartItems) &&
                ShoppingCart.CartItems != null && ShoppingCart.CartItems.Count > 0 && ShoppingCart.OrderCategory == OrderCategoryType.RSO &&
                !HLConfigManager.Configurations.APFConfiguration.StandaloneAPFOnlyAllowed && ShoppingCart.DeliveryInfo.Option == ServiceProvider.ShippingSvc.DeliveryOptionType.Pickup)
            {
                SpainPlasticBagAlert.Show();
            }
            else
            {
                Response.Redirect("~/Ordering/ShoppingCart.aspx");
            }
        }
Exemple #12
0
        public static bool DisplayNonResidentMessage(string shoppingCartID)
        {
            bool isNotified;

            bool.TryParse(HttpContext.Current.Session["isNonResidentNotified"] != null ? HttpContext.Current.Session["isNonResidentNotified"].ToString() : "false", out isNotified);

            if (HLConfigManager.Configurations.DOConfiguration.DisplayNonResidentsMessage && !isNotified)
            {
                var member = (MembershipUser <DistributorProfileModel>)Membership.GetUser();
                if (member != null && member.Value != null && !member.Value.ProcessingCountryCode.Equals(StaticLocale.Substring(3)))
                {
                    var id = 0;
                    if (int.TryParse(shoppingCartID, out id))
                    {
                        var shoppingCart = ShoppingCartProvider.GetShoppingCart(StaticDistributorID, StaticLocale, id);
                        if (shoppingCart.DeliveryInfo != null && shoppingCart.DeliveryInfo.Option == ServiceProvider.ShippingSvc.DeliveryOptionType.Pickup &&
                            !SessionInfo.GetSessionInfo(StaticDistributorID, StaticLocale).IsEventTicketMode&& !APFDueProvider.IsAPFSkuPresent(shoppingCart.CartItems))
                        {
                            HttpContext.Current.Session["isNonResidentNotified"] = true;
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }