Ejemplo n.º 1
0
 private void RunActions(PromotionContext context)
 {
     foreach (var a in _actions)
     {
         a.ApplyAction(context);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        ///     Applies to shipping rate.
        /// </summary>
        /// <param name="requestContext">The request context.</param>
        /// <param name="o">The o.</param>
        /// <param name="account">The account.</param>
        /// <param name="shipMethodId">The ship method identifier.</param>
        /// <param name="originalShippingMethodRate">The original shipping method rate.</param>
        /// <returns></returns>
        public decimal ApplyToShippingRate(HccRequestContext requestContext, Order o, CustomerAccount account,
                                           string shipMethodId, decimal originalShippingMethodRate)
        {
            var result = originalShippingMethodRate;

            if (requestContext == null)
            {
                return(result);
            }
            if (o == null)
            {
                return(result);
            }

            var context = new PromotionContext(requestContext, Mode, Id)
            {
                Order                   = o,
                CurrentCustomer         = account,
                CustomerDescription     = CustomerDescription,
                CurrentShippingMethodId = shipMethodId,
                AdjustedShippingRate    = originalShippingMethodRate,
                OtherOffersApplied      = o.HasAnyNonSaleDiscounts
            };

            if (ApplyPromotion(context, PromotionQualificationMode.Orders))
            {
                result = context.AdjustedShippingRate;
            }

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Applies to product.
        /// </summary>
        /// <param name="requestContext">The request context.</param>
        /// <param name="p">The p.</param>
        /// <param name="price">The price.</param>
        /// <param name="account">The account.</param>
        /// <returns></returns>
        public bool ApplyToProduct(HccRequestContext requestContext, Product p, UserSpecificPrice price,
                                   CustomerAccount account)
        {
            if (requestContext == null)
            {
                return(false);
            }
            if (p == null)
            {
                return(false);
            }
            if (price == null)
            {
                return(false);
            }

            var context = new PromotionContext(requestContext, Mode, Id)
            {
                Product             = p,
                UserPrice           = price,
                CurrentCustomer     = account,
                CustomerDescription = CustomerDescription
            };

            return(ApplyPromotion(context, PromotionQualificationMode.Products));
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Applies to affiliate.
        /// </summary>
        /// <param name="requestContext">The request context.</param>
        /// <param name="account">The account.</param>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        public bool ApplyToAffiliate(HccRequestContext requestContext, CustomerAccount account, DateTime date)
        {
            if (requestContext == null)
            {
                return(false);
            }

            var context = new PromotionContext(requestContext, Mode, Id)
            {
                CurrentCustomer = account
            };

            return(ApplyPromotion(context, PromotionQualificationMode.Affiliates));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// </summary>
        /// <param name="requestContext"></param>
        /// <param name="o"></param>
        /// <returns></returns>
        public bool ApplyToOrder(HccRequestContext requestContext, Order o)
        {
            if (requestContext == null)
            {
                return(false);
            }
            if (o == null)
            {
                return(false);
            }

            var membershipServices = Factory.CreateService <MembershipServices>(requestContext);
            var context            = new PromotionContext(requestContext, Mode, Id)
            {
                Order               = o,
                CurrentCustomer     = string.IsNullOrEmpty(o.UserID) ? null : membershipServices.Customers.Find(o.UserID),
                CustomerDescription = CustomerDescription,
                OtherOffersApplied  = o.HasAnyNonSaleDiscounts
            };

            var result = false;

            if (Mode == PromotionType.OfferForLineItems || Mode == PromotionType.OfferForFreeItems)
            {
                for (var i = 0; i < context.Order.Items.Count; i++)
                {
                    var li = context.Order.Items[i];

                    if (!li.IsUserSuppliedPrice && (!li.IsGiftCard || Mode == PromotionType.OfferForFreeItems) &&
                        (!li.IsFreeItem || Mode == PromotionType.OfferForLineItems))
                    {
                        // don't try to add it again, if it's already there
                        if (li.DiscountDetails.Any(d => d.PromotionId == context.PromotionId))
                        {
                            continue;
                        }

                        context.CurrentlyProcessingLineItem = li;
                        result = ApplyPromotion(context, PromotionQualificationMode.LineItems);
                    }
                }
            }
            else
            {
                result = ApplyPromotion(context, PromotionQualificationMode.Orders);
            }

            return(result);
        }
Ejemplo n.º 6
0
        private bool ApplyPromotion(PromotionContext context, PromotionQualificationMode qualificationMode)
        {
            if (GetStatus() == PromotionStatus.Active)
            {
                var qualified = CheckQualifications(context, qualificationMode);

                if (qualified)
                {
                    RunActions(context);
                }

                return(qualified);
            }

            return(false);
        }
Ejemplo n.º 7
0
        public bool ApplyForFreeShipping(PromotionContext promoContext)
        {
            var result = false;

            for (var i = 0; i < promoContext.Order.Items.Count; i++)
            {
                var li = promoContext.Order.Items[i];

                promoContext.CurrentlyProcessingLineItem = li;

                //if (li.DiscountDetails.Any(d => d.PromotionId == promoContext.PromotionId)) continue;

                result = ApplyPromotion(promoContext, PromotionQualificationMode.LineItems);
            }
            return(result);
        }
Ejemplo n.º 8
0
        /// <summary>
        ///     Make sure we meet all requirements
        /// </summary>
        /// <remarks>
        ///     NOTE: we order by processing cost which should allow us to check
        ///     the fastest items first. For example, checking userID is faster
        ///     than checking user group because ID is in the context and group
        ///     requires a database call.
        /// </remarks>
        /// <param name="context"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        public bool CheckQualifications(PromotionContext context, PromotionQualificationMode mode)
        {
            var qualificationsSorted = _qualifications.OrderBy(y => y.ProcessingCost);

            return(qualificationsSorted.All(q => q.MeetsQualification(context, mode)));
        }