コード例 #1
0
        private void DoApfDue(string distributorID,
                              ShoppingCart_V01 result,
                              string cacheKey,
                              string locale,
                              bool cartHasItems,
                              ShoppingCartRuleResult ruleResult,
                              bool justEntered)
        {
            var cart = result as MyHLShoppingCart;

            if (cart == null)
            {
                return;
            }

            try
            {
                string level;
                if (DistributorProfileModel != null)
                {
                    level = DistributorProfileModel.TypeCode.ToUpper();
                }
                else
                {
                    level = GetMemberLevelFromDistributorProfile(cart.DistributorID);
                }

                var distributorOrderingProfile = DistributorOrderingProfileProvider.GetProfile(cart.DistributorID,
                                                                                               cart.CountryCode);
                if ((distributorOrderingProfile.HardCashOnly &&
                     !HLConfigManager.Configurations.PaymentsConfiguration.AllowWireForHardCash))
                {
                    return;
                }
                var apfItems = new List <ShoppingCartItem_V01>();
                if (cart.CartItems != null && cart.CartItems.Count > 0)
                {
                    //Stash off all non-APF items - to be re-added if appropriate
                    var nonApfItems =
                        (from c in cart.CartItems where APFDueProvider.IsAPFSku(c.SKU.Trim()) == false select c)
                        .ToList <ShoppingCartItem_V01>();
                    apfItems =
                        (from c in cart.CartItems where APFDueProvider.IsAPFSku(c.SKU.Trim()) select c)
                        .ToList <ShoppingCartItem_V01>();
                    if (nonApfItems.Count > 0 ||
                        HLConfigManager.Configurations.APFConfiguration.StandaloneAPFOnlyAllowed)
                    {
                        // Clear the cart
                        cart.DeleteItemsFromCart(null, true);
                        //if (APFDueProvider.CanEditAPFOrder(distributorID, locale, level))
                        //{
                        //Global rule - they can always edit the cart ie add remove products at least
                        var list =
                            CatalogProvider.GetCatalogItems((from p in nonApfItems select p.SKU).ToList(), Country);
                        var products =
                            (from c in list where c.Value.ProductType == ProductType.Product select c.Value.SKU).ToList();
                        var nonproducts =
                            (from c in list where c.Value.ProductType != ProductType.Product select c.Value.SKU).ToList();
                        if (!HLConfigManager.Configurations.APFConfiguration.AllowNonProductItemsWithStandaloneAPF)
                        //We don't allow non product items alone on an apf order
                        {
                            if (products.Count == 0)
                            {
                                if (nonproducts.Count > 0)
                                {
                                    ruleResult.Result = RulesResult.Success;
                                    ruleResult.AddMessage(
                                        HttpContext.GetGlobalResourceObject(
                                            string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                            "NonProductItemsRemovedForStandaloneAPF") as string);
                                    cart.RuleResults.Add(ruleResult);
                                }
                            }
                            else
                            {
                                cart.AddItemsToCart(nonApfItems, true);
                            }
                        }
                        else
                        {
                            if (!HLConfigManager.Configurations.APFConfiguration.StandaloneAPFOnlyAllowed)
                            {
                                cart.AddItemsToCart(nonApfItems, true);
                            }
                        }
                    }
                }
                else if (null != cart && null != cart.RuleResults)
                {
                    var rules =
                        (from rule in cart.RuleResults
                         where rule.RuleName == RuleName && rule.Result == RulesResult.Failure
                         select rule);
                    if (null != rules && rules.Count() > 0)
                    {
                        cart.RuleResults.Remove(rules.First());
                    }
                }

                //Add the APF in
                var apfSku = new List <ShoppingCartItem_V01>();
                var sku    = APFDueProvider.GetAPFSku();
                apfSku.Add(new ShoppingCartItem_V01(0, sku, 1, DateTime.Now));
                if (!cart.APFEdited)
                {
                    apfSku[0].Quantity = 1; //CalcQuantity(distributorOrderingProfile.ApfDueDate);
                    if (cart.CartItems.Exists(c => c.SKU == apfSku[0].SKU))
                    {
                        var apf =
                            (from a in cart.CartItems where a.SKU == apfSku[0].SKU select a).First();
                        cart.DeleteItemsFromCart(
                            (from a in cart.CartItems where a.SKU == apfSku[0].SKU select a.SKU).ToList(), true);
                    }
                    if (cart.CartItems.Count == 0) //This is now a Standalone APF
                    {
                        SetAPFDeliveryOption(cart);
                    }
                    cart.AddItemsToCart(apfSku, true);

                    if (justEntered)
                    {
                        ruleResult.AddMessage(
                            HttpContext.GetGlobalResourceObject(
                                string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "APFDueAdded") as string);
                        ruleResult.Result = RulesResult.Success;

                        SetApfRuleResponse(ruleResult, ApfAction.None, sku, "ApfRule", TypeOfApf.CantDSRemoveAPF,
                                           "APFDueAdded");

                        cart.RuleResults.Add(ruleResult);
                    }
                    else
                    {
                        foreach (ShoppingCartRuleResult r in cart.RuleResults)
                        {
                            if (r.RuleName == RuleName)
                            {
                                r.Messages.Clear();
                                r.AddMessage(string.Empty);
                            }
                        }
                    }
                }
                //else
                //{
                //    if (APFDueProvider.CanRemoveAPF(distributorID, locale, level))
                //    {
                //        cart.AddItemsToCart(apfSku, true);
                //    }
                //}
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(string.Format("doAPFDue DS:{0} ERR:{1}", distributorID, ex));
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
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);
        }