public static marketingDto.PromotionEvaluationContext ToPromotionEvaluationContextDto(this PromotionEvaluationContext promoEvalContext)
        {
            var result = new marketingDto.PromotionEvaluationContext();

            if (promoEvalContext.Cart != null)
            {
                result.CartPromoEntries = promoEvalContext.Cart.Items.Select(x => x.ToProductPromoEntryDto()).ToList();

                result.CartTotal        = (double)promoEvalContext.Cart.SubTotal.Amount;
                result.Coupons          = promoEvalContext.Cart.Coupons?.Select(c => c.Code).ToList();
                result.Currency         = promoEvalContext.Cart.Currency.Code;
                result.CustomerId       = promoEvalContext.Cart.CustomerId;
                result.UserGroups       = promoEvalContext.Cart.Customer?.Contact?.UserGroups;
                result.IsRegisteredUser = promoEvalContext.Cart.Customer?.IsRegisteredUser;
                result.Language         = promoEvalContext.Cart.Language.CultureName;
                //Set cart line items as default promo items
                result.PromoEntries = result.CartPromoEntries;

                if (!promoEvalContext.Cart.Shipments.IsNullOrEmpty())
                {
                    var shipment = promoEvalContext.Cart.Shipments.First();
                    result.ShipmentMethodCode   = shipment.ShipmentMethodCode;
                    result.ShipmentMethodOption = shipment.ShipmentMethodOption;
                    result.ShipmentMethodPrice  = (double)shipment.Price.Amount;
                }
                if (!promoEvalContext.Cart.Payments.IsNullOrEmpty())
                {
                    var payment = promoEvalContext.Cart.Payments.First();
                    result.PaymentMethodCode  = payment.PaymentGatewayCode;
                    result.PaymentMethodPrice = (double)payment.Price.Amount;
                }
            }

            if (!promoEvalContext.Products.IsNullOrEmpty())
            {
                result.PromoEntries = promoEvalContext.Products.Select(x => x.ToProductPromoEntryDto()).ToList();
            }

            if (promoEvalContext.Product != null)
            {
                result.PromoEntry = promoEvalContext.Product.ToProductPromoEntryDto();
            }

            result.UserGroups = promoEvalContext?.User?.Contact?.UserGroups;

            result.CustomerId       = promoEvalContext.User.Id;
            result.IsEveryone       = true;
            result.IsRegisteredUser = promoEvalContext.User.IsRegisteredUser;
            result.IsFirstTimeBuyer = promoEvalContext.User.IsFirstTimeBuyer;

            result.Currency = promoEvalContext.Currency != null ? promoEvalContext.Currency.Code : null;
            result.Language = promoEvalContext.Language != null ? promoEvalContext.Language.CultureName : null;
            result.StoreId  = promoEvalContext.StoreId;

            return(result);
        }
Ejemplo n.º 2
0
        public virtual marketingDto.PromotionEvaluationContext ToPromotionEvaluationContextDto(PromotionEvaluationContext promoEvalContext)
        {
            var result = new marketingDto.PromotionEvaluationContext();

            result.InjectFrom <NullableAndEnumValueInjecter>(promoEvalContext);

            result.CartPromoEntries = promoEvalContext.CartPromoEntries.Select(ToProductPromoEntryDto).ToList();
            result.CartTotal        = promoEvalContext.CartTotal != null ? (double?)promoEvalContext.CartTotal.Amount : null;
            result.Currency         = promoEvalContext.Currency != null ? promoEvalContext.Currency.Code : null;
            result.Language         = promoEvalContext.Language != null ? promoEvalContext.Language.CultureName : null;
            result.PromoEntries     = promoEvalContext.PromoEntries.Select(ToProductPromoEntryDto).ToList();
            result.PromoEntry       = promoEvalContext.PromoEntry != null?ToProductPromoEntryDto(promoEvalContext.PromoEntry) : null;

            result.ShipmentMethodPrice = promoEvalContext.ShipmentMethodPrice != null ? (double?)promoEvalContext.ShipmentMethodPrice.Amount : null;

            return(result);
        }