コード例 #1
0
        private async Task <string> PrettifyVariableValue(ViewProperty variable, List <ViewProperty> properties,
                                                          CommerceContext commerceContext)
        {
            switch (variable.Name)
            {
            case "Hc_BasicStringCompare":
            case "Hc_Compares":
            case "Hc_Operator":
                return(variable.Value.PrettifyOperatorName());

            case "Hc_SpecificCategory":
                return(await PrettifyCategory(variable.Value, properties, commerceContext));

            case "Hc_Date":
                if (DateTimeOffset.TryParse(variable.Value, out DateTimeOffset date))
                {
                    return(date.LocalDateTime.ToString("d MMM yyyy HH:mm"));
                }

                return(variable.Value);

            case "Hc_ApplyActionTo":
                return(ApplicationOrder.Parse(variable.Value).DisplayName);

            case "TargetItemId":
                return(await PrettifyProduct(variable.Value, commerceContext));

            default:
                return(variable.Value);
            }
        }
コード例 #2
0
        public void Execute(IRuleExecutionContext context)
        {
            var commerceContext = context.Fact <CommerceContext>();

            //Get configuration
            string  specificCategory     = Ny_SpecificCategory.Yield(context);
            decimal itemsToAward         = Ny_ItemsToAward.Yield(context);
            decimal itemsToPurchase      = Ny_ItemsToPurchase.Yield(context);
            bool    includeSubCategories = Ny_IncludeSubCategories.Yield(context);
            decimal percentageOff        = Ny_PercentageOff.Yield(context);
            string  applyActionTo        = Ny_ApplyActionTo.Yield(context);
            int     actionLimit          = Ny_ActionLimit.Yield(context);

            if (string.IsNullOrEmpty(specificCategory) ||
                itemsToAward == 0 ||
                itemsToPurchase == 0 ||
                percentageOff == 0 ||
                string.IsNullOrEmpty(applyActionTo) ||
                actionLimit == 0)
            {
                return;
            }

            //Get data
            IEnumerable <CartLineComponent> categoryLines =
                categoryCartLinesResolver.Resolve(commerceContext, specificCategory, includeSubCategories);

            if (categoryLines == null)
            {
                return;
            }

            //Validate and apply action
            int     cartQuantity        = Convert.ToInt32(categoryLines.Sum(x => x.Quantity));
            decimal cartProductsToAward = Math.Floor(cartQuantity / itemsToPurchase) * itemsToAward;

            decimal productsToAward = cartProductsToAward > actionLimit ? actionLimit : cartProductsToAward;

            if (productsToAward <= 0)
            {
                return;
            }

            var discountApplicator = new DiscountApplicator(commerceContext);

            discountApplicator.ApplyPercentageDiscount(categoryLines, percentageOff, new DiscountOptions
            {
                ActionLimit      = Convert.ToInt32(productsToAward),
                ApplicationOrder = ApplicationOrder.Parse(applyActionTo),
                AwardingBlock    = nameof(CartEveryXItemsInCategoryPercentageDiscountAction)
            });
        }
コード例 #3
0
        public void Execute(IRuleExecutionContext context)
        {
            var commerceContext = context.Fact <CommerceContext>();

            //Get configuration
            string  specificCategory     = Ny_SpecificCategory.Yield(context);
            decimal specificValue        = Ny_SpecificValue.Yield(context);
            bool    includeSubCategories = Ny_IncludeSubCategories.Yield(context);
            decimal percentageOff        = Ny_PercentageOff.Yield(context);
            string  applyActionTo        = Ny_ApplyActionTo.Yield(context);
            int     actionLimit          = Ny_ActionLimit.Yield(context);

            if (string.IsNullOrEmpty(specificCategory) ||
                specificValue == 0 ||
                percentageOff == 0 ||
                string.IsNullOrEmpty(applyActionTo) ||
                actionLimit == 0 ||
                Ny_Operator == null)
            {
                return;
            }

            //Get data
            IEnumerable <CartLineComponent> categoryLines =
                categoryCartLinesResolver.Resolve(commerceContext, specificCategory, includeSubCategories);

            if (categoryLines == null)
            {
                return;
            }

            //Validate and apply action
            decimal productAmount = categoryLines.Sum(x => x.Quantity);

            if (!Ny_Operator.Evaluate(productAmount, specificValue))
            {
                return;
            }

            var discountApplicator = new DiscountApplicator(commerceContext);

            discountApplicator.ApplyPercentageDiscount(categoryLines, percentageOff, new DiscountOptions
            {
                ActionLimit      = actionLimit,
                ApplicationOrder = ApplicationOrder.Parse(applyActionTo),
                AwardingBlock    = nameof(CartItemsMatchingInCategoryPercentageDiscountAction)
            });
        }