Exemple #1
0
        private bool CanBuy_eLearningRule(MyHLShoppingCart hlCart)
        {
            bool retVal = true;

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

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

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

                if (currentVolumePoints > HLConfigManager.Configurations.ShoppingCartConfiguration.eLearningMaxPPV)
                {
                    if (hlCart.ItemsBeingAdded != null)
                    {
                        hlCart.ItemsBeingAdded.Clear();
                    }
                    retVal = false;
                }
            }
            return(retVal);
        }
Exemple #2
0
        public override void SetPurchaseRestriction(List <TaxIdentification> tins, int orderMonth, string distributorId, IPurchaseRestrictionManager manager)
        {
            //check if is a elearning and set the new limits for the second order
            base.SetPurchaseRestriction(tins, orderMonth, distributorId, manager);
            var currentLimits = GetLimits(LimitsRestrictionType.PurchasingLimits, orderMonth, manager);

            if (HLConfigManager.Configurations.ShoppingCartConfiguration.CheckELearning)
            {
                PurchaseLimitType limitType = PurchaseLimitType.Volume;
                currentLimits.PurchaseLimitType = limitType;
                var session = SessionInfo.GetSessionInfo(distributorId, Locale);
                if (PurchaseRestrictionProvider.RequireTraining(distributorId, this.Locale, this.Country))
                {
                    if (currentLimits.RemainingVolume != currentLimits.maxVolumeLimit && !session.LimitsHasModified)
                    {
                        var used     = (currentLimits.maxVolumeLimit - currentLimits.RemainingVolume);
                        var shouldbe = 1100 - used;
                        currentLimits.PurchaseLimitType = limitType;
                        if (currentLimits.RemainingVolume != shouldbe && shouldbe > 0 && !session.LimitsHasModified)
                        {
                            currentLimits.RemainingVolume = HLConfigManager.Configurations.ShoppingCartConfiguration.eLearningMaxPPV - (currentLimits.maxVolumeLimit - currentLimits.RemainingVolume);
                            session.LimitsHasModified     = true;
                        }
                    }
                    //check for the members without limits and create
                    else if (currentLimits.RemainingVolume == -1 && currentLimits.maxVolumeLimit == -1 && !session.LimitsHasModified)
                    {
                        var currentLoggedInCounrtyCode      = Locale.Substring(3);
                        DistributorLoader distributorLoader = new DistributorLoader();
                        var distributorProfile = distributorLoader.Load(distributorId, currentLoggedInCounrtyCode);

                        var remainingVolume = HLConfigManager.Configurations.ShoppingCartConfiguration.eLearningMaxPPV - distributorProfile.PersonallyPurchasedVolume;
                        //PurchasingLimits_V01 newLimits = new PurchasingLimits_V01();
                        currentLimits.Month                 = currentLimits.Month;
                        currentLimits.LastRead              = DateTime.UtcNow;
                        currentLimits.RemainingVolume       = distributorProfile.PersonallyPurchasedVolume != 0 ? remainingVolume : 0;
                        currentLimits.LimitsRestrictionType = LimitsRestrictionType.PurchasingLimits;
                        currentLimits.PurchaseLimitType     = limitType;
                        currentLimits.LastRead              = DateTime.UtcNow;
                        currentLimits.maxVolumeLimit        = HLConfigManager.Configurations.ShoppingCartConfiguration.eLearningMaxPPV;
                        session.LimitsHasModified           = true;
                    }
                }
            }
            else
            {
                base.SetPurchaseRestriction(tins, orderMonth, distributorId, manager);
            }

            if (currentLimits == null)
            {
                return;
            }
            SetLimits(orderMonth, manager, currentLimits);
        }