Пример #1
0
        protected override ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart, ShoppingCartRuleReason reason,
                                                               ShoppingCartRuleResult Result)
        {
            if (reason == ShoppingCartRuleReason.CartItemsBeingAdded)
            {
                var currentLimits = base.GetPurchasingLimits(cart.DistributorID, string.Empty);
                var theLimits     = currentLimits[PurchasingLimitProvider.GetOrderMonth()];
                // If it's threshold volume point for all product types is counted
                if (PurchasingLimitProvider.IsOrderThresholdMaxVolume(theLimits))
                {
                    Result = base.PerformRules(cart, reason, Result);
                }
                else if (!DistributorIsExemptFromPurchasingLimits(cart.DistributorID))
                {
                    CatalogItem_V01 currentItem = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU, Country);
                    Result = base.PerformRules(cart, reason, Result);
                }
            }

            return(Result);
        }
Пример #2
0
        protected override ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart, ShoppingCartRuleReason reason,
                                                               ShoppingCartRuleResult Result)
        {
            if (reason == ShoppingCartRuleReason.CartItemsBeingAdded)
            {
                var currentLimits = base.GetPurchasingLimits(cart.DistributorID, string.Empty);
                var theLimits     = currentLimits[PurchasingLimitProvider.GetOrderMonth()];
                // If it's threshold volume point for all product types is counted
                if (PurchasingLimitProvider.IsOrderThresholdMaxVolume(theLimits))
                {
                    Result = base.PerformRules(cart, reason, Result);
                }
                else if (!DistributorIsExemptFromPurchasingLimits(cart.DistributorID))
                {
                    CatalogItem_V01 currentItem = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU, Country);
                    Result = base.PerformRules(cart, reason, Result);
                }
            }

            if (reason == ShoppingCartRuleReason.CartCreated && cart.CartItems.Any())
            {
                var currentLimits = base.GetPurchasingLimits(cart.DistributorID, string.Empty);
                var theLimits     = currentLimits[PurchasingLimitProvider.GetOrderMonth()];
                // If it's threshold volume point for all product types is counted
                if (PurchasingLimitProvider.IsOrderThresholdMaxVolume(theLimits))
                {
                    Result = base.PerformRules(cart, reason, Result);
                }
                else if (!DistributorIsExemptFromPurchasingLimits(cart.DistributorID))
                {
                    var     purchasingLimitManager               = PurchasingLimitManager(cart.DistributorID);
                    decimal DistributorRemainingVolumePoints     = 0;
                    decimal DistributorRemainingDiscountedRetail = 0;
                    var     myhlCart = cart as MyHLShoppingCart;
                    if (null == myhlCart)
                    {
                        LoggerHelper.Error(
                            string.Format("{0} myhlCart is null {1}", Locale, cart.DistributorID));
                        Result.Result = RulesResult.Failure;
                        return(Result);
                    }

                    PurchasingLimits_V01 PurchasingLimits =
                        PurchasingLimitProvider.GetCurrentPurchasingLimits(cart.DistributorID);

                    purchasingLimitManager.SetPurchasingLimits(PurchasingLimits);

                    if (null == PurchasingLimits)
                    {
                        LoggerHelper.Error(
                            string.Format("{0} PurchasingLimits could not be retrieved for distributor {1}", Locale,
                                          cart.DistributorID));
                        Result.Result = RulesResult.Failure;
                        return(Result);
                    }

                    DistributorRemainingVolumePoints         =
                        DistributorRemainingDiscountedRetail = PurchasingLimits.RemainingVolume;

                    if (PurchasingLimits.PurchaseLimitType == PurchaseLimitType.Volume)
                    {
                        if (PurchasingLimits.maxVolumeLimit == -1)
                        {
                            return(Result);
                        }
                        decimal cartVolume = (cart as MyHLShoppingCart).VolumeInCart;
                        if (DistributorRemainingVolumePoints - cartVolume < 0)
                        {
                            Result.Result = RulesResult.Failure;
                            Result.AddMessage(
                                PlatformResources.GetGlobalResourceString("ErrorMessage",
                                                                          "NoCheckoutPurchaseLimitsExceeded"));
                            cart.RuleResults.Add(Result);
                        }
                    }
                    else
                    {
                        Result.Result = RulesResult.Success;
                    }
                }
                else
                {
                    Result = base.PerformRules(cart, reason, Result);
                }
            }
            return(Result);
        }
Пример #3
0
        /// <summary>
        ///     The IShoppingCart Rule Interface implementation
        /// </summary>
        /// <param name="cart">The current Shopping Cart</param>
        /// <param name="reason">The Rule invoke Reason</param>
        /// <param name="Result">The Rule Results collection</param>
        /// <returns>The cumulative rule results - including the results of this iteration</returns>
        protected override ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart,
                                                               ShoppingCartRuleReason reason,
                                                               ShoppingCartRuleResult Result)
        {
            if (reason == ShoppingCartRuleReason.CartItemsBeingAdded)
            {
                decimal DistributorRemainingVolumePoints = 0;
                decimal NewVolumePoints = 0;

                if (cart.CurrentItems == null || cart.CurrentItems.Count == 0)
                {
                    Result.Result = RulesResult.Failure;
                    return(Result);
                }

                var orderMonth = new OrderMonth(Country);

                PurchasingLimitManager(cart.DistributorID).SetPurchasingLimits(PurchasingLimitProvider.GetOrderMonth());

                var PurchasingLimits =
                    PurchasingLimitProvider.GetCurrentPurchasingLimits(cart.DistributorID);

                if (null == PurchasingLimits)
                {
                    LoggerHelper.Error(
                        string.Format("{0} PurchasingLimits could not be retrieved for distributor {1}", Locale,
                                      cart.DistributorID));
                    Result.Result = RulesResult.Failure;
                    return(Result);
                }

                DistributorRemainingVolumePoints = PurchasingLimits.RemainingVolume;
                var currentItem = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU, Country);
                if (currentItem != null)
                {
                    if (currentItem.ProductType == ServiceProvider.CatalogSvc.ProductType.EventTicket)
                    {
                        PurchasingLimitProvider.GetPurchasingLimits(cart.DistributorID, "ETO");
                    }
                    else
                    {
                        NewVolumePoints = currentItem.VolumePoints * cart.CurrentItems[0].Quantity;
                    }
                }

                // validate order threshold first
                if (PurchasingLimits.maxVolumeLimit == -1)
                {
                    return(Result);
                }

                if (PurchasingLimits.PurchaseLimitType == PurchaseLimitType.ProductCategory && currentItem.ProductType == ServiceProvider.CatalogSvc.ProductType.Product)
                {
                    Result.Result = RulesResult.Failure;
                    Result.AddMessage(
                        string.Format(
                            HttpContext.GetGlobalResourceObject(
                                string.Format("{0}_Rules", HLConfigManager.Platform),
                                "PurchaseLimitTypeProductCategory") as string ?? string.Empty,
                            cart.CurrentItems[0].SKU));
                    cart.RuleResults.Add(Result);
                    return(Result);
                }

                // validate against order threshold first
                decimal cartVolume = (cart as MyHLShoppingCart).VolumeInCart;
                if (PurchasingLimitProvider.IsOrderThresholdMaxVolume(PurchasingLimits) ||
                    PurchasingLimits.PurchaseLimitType != PurchaseLimitType.None)
                {
                    if (DistributorRemainingVolumePoints - (cartVolume + NewVolumePoints) < 0)
                    {
                        Result.Result = RulesResult.Failure;

                        string message = string.Empty;

                        if (cart.CartItems.Exists(item => item.SKU == cart.CurrentItems[0].SKU))
                        {
                            Result.Messages.Add(
                                string.Format(
                                    HttpContext.GetGlobalResourceObject(
                                        string.Format("{0}_Rules", HLConfigManager.Platform),
                                        "VolumePointExceedsThresholdByIncreasingQuantity") as string ?? string.Empty,
                                    cart.CurrentItems[0].SKU, cart.CurrentItems[0].Quantity));
                        }
                        else
                        {
                            Result.Messages.Add(
                                string.Format(
                                    HttpContext.GetGlobalResourceObject(
                                        string.Format("{0}_Rules", HLConfigManager.Platform),
                                        "VolumePointExceedsThreshold") as string ?? string.Empty, cart.CurrentItems[0].SKU));
                        }

                        if (Result.Messages.Any())
                        {
                            cart.RuleResults.Add(Result);
                        }
                        else
                        {
                            Result.Result = RulesResult.Success;
                        }

                        return(Result); // if fails, just return
                    }
                }

                if (PurchasingLimits.PurchaseLimitType == PurchaseLimitType.ProductCategory)
                {
                    if (DistributorRemainingVolumePoints -
                        ((cart as MyHLShoppingCart).VolumeInCart + NewVolumePoints) < 0)
                    {
                        Result.Result = RulesResult.Failure;
                        if (cart.CartItems.Exists(item => item.SKU == cart.CurrentItems[0].SKU))
                        {
                            Result.AddMessage(
                                string.Format(
                                    HttpContext.GetGlobalResourceObject(
                                        string.Format("{0}_Rules", HLConfigManager.Platform),
                                        "VolumePointExceedsThresholdByIncreasingQuantity") as string ?? string.Empty,
                                    cart.CurrentItems[0].SKU, cart.CurrentItems[0].Quantity));
                        }
                        else
                        {
                            Result.AddMessage(
                                string.Format(
                                    HttpContext.GetGlobalResourceObject(
                                        string.Format("{0}_Rules", HLConfigManager.Platform),
                                        "VolumePointExceedsThreshold") as string ?? string.Empty, cart.CurrentItems[0].SKU));
                        }
                    }
                }
                else
                {
                    Result.Result = RulesResult.Success;
                }
            }
            return(Result);
        }