EpiCommerce-如何使用扩展的附加属性修改自定义促销?

时间:2019-02-20 12:06:09

标签: episerver episerver-commerce

我绝对是EpiCommerce的新手。

我正在使用Quicksilver项目。

我创建了自己的自定义促销

[ContentType(DisplayName = "Custom Promotion", GUID = "de5ce21b-f88f-420b-840e-243f5a189ee0")]
    public class CustomPromotion : EntryPromotion
    {
        [PromotionRegion(PromotionRegionName.Discount)]
        public virtual int PercentageDiscount { get; set; }

        [PromotionRegion(PromotionRegionName.Condition)]
        public virtual CustomPercentageBlock Condition { get; set; }
    }

以及定制促销处理器。

    [ServiceConfiguration(Lifecycle = ServiceInstanceScope.Singleton)]
    public class PercentagePromotionProcessor : EntryPromotionProcessorBase<CustomPromotion>
    {
        private readonly CollectionTargetEvaluator _targetEvaluator;
        private readonly FulfillmentEvaluator _fulfillmentEvaluator;
        private readonly LocalizationService _localizationService;

        public PercentagePromotionProcessor(CollectionTargetEvaluator targetEvaluator,
            FulfillmentEvaluator fulfillmentEvaluator,
            LocalizationService localizationService,
            RedemptionDescriptionFactory redemptionDescriptionFactory) : base(redemptionDescriptionFactory)
        {
            _targetEvaluator = targetEvaluator;
            _fulfillmentEvaluator = fulfillmentEvaluator;
            _localizationService = localizationService;
        }

        protected override RewardDescription Evaluate(CustomPromotion promotionData, PromotionProcessorContext context)
        {
            var lineItems = GetLineItems(context.OrderForm);
            var condition = promotionData.Condition;

            var applicableCodes = _targetEvaluator.GetApplicableCodes(lineItems, condition.Targets, false);

            var fulfillmentStatus = _fulfillmentEvaluator.GetStatusForBuyQuantityPromotion(applicableCodes, lineItems, 0, 0);

            var affectedEntries = context.EntryPrices.ExtractEntries(applicableCodes, applicableCodes.Count, promotionData);

            return RewardDescription.CreatePercentageReward(fulfillmentStatus,
                GetRedemptions(applicableCodes,affectedEntries, promotionData, context), 
                promotionData, 
                promotionData.PercentageDiscount, 
                "Custom 50% discount");
        }

        protected override PromotionItems GetPromotionItems(CustomPromotion promotionData)
        {
            var specificItems = new CatalogItemSelection(promotionData.Condition.Targets, CatalogItemSelectionType.Specific, false);
            return new PromotionItems(promotionData, specificItems, specificItems);
        }

        private IEnumerable<RedemptionDescription> GetRedemptions(
             IEnumerable<string> applicableCodes,
             AffectedEntries affectedEntries,
             CustomPromotion promotionData,
             PromotionProcessorContext context)
        {
            var redemptions = new List<RedemptionDescription>();
            if (affectedEntries != null)
            {
                var maxRedemptions = applicableCodes.Count();
                for (int i = 0; i < maxRedemptions; i++)
                {
                    redemptions.Add(CreateRedemptionDescription(affectedEntries));
                }
            }

            return redemptions;
        }

    }

我为女性手袋提供了50%的折扣(以前),而且效果很好。

因此,此外,我的FashionVariant类中具有DisountedItem布尔值属性。我还添加了元字段并将此元字段添加到适当的元类中。

 public class FashionVariant : VariationContent
    {
       // other properties

        [Searchable]
        [IncludeInDefaultSearch]
        [Tokenize]
        [IncludeValuesInSearchResults]
        [BackingType(typeof(PropertyBoolean))]
        [Display(Name = "Discounted Item", Order = 4)]
        public virtual bool DiscountedItem { get; set; }
}

我的问题是对的。使用我的自定义促销后,如何为复选框DiscountedItem创建功能 用于删除,也可以手动向产品添加促销。 创建折扣时应选中复选框,如果要手动从某些产品中删除折扣,则只需取消选中复选框即可。

P.S。正如我添加的metafield一样,此复选框(DiscountedItem)在Cms Edit模式下显示。我只需要功能。

任何建议都会对我有所帮助。

提前感谢大家。

0 个答案:

没有答案