Ejemplo n.º 1
0
        public CatalogProfile(ICurrencyProvider currencyProvider)
        {
            Assert.ArgumentNotNull(currencyProvider, nameof(currencyProvider));

            this.CreateMap <Connect.BaseProduct, BaseProduct>()
            .ForMember(
                dest => dest.StockStatusName,
                opt => opt.MapFrom(src => src.StockStatus != null ? src.StockStatus.Name : null))
            .ForMember(
                dest => dest.CurrencySymbol,
                opt => opt.MapFrom(src => currencyProvider.GetCurrencySymbolByCode(src.CurrencyCode)));

            this.CreateMap <Connect.Product, Product>()
            .IncludeBase <Connect.BaseProduct, BaseProduct>();

            this.CreateMap <Connect.Variant, Variant>()
            .IncludeBase <Connect.BaseProduct, BaseProduct>()
            .ForMember(dest => dest.VariantId, opt => opt.MapFrom(src => src.Id));

            this.CreateMap <Item, Category>()
            .ForMember(dest => dest.SitecoreId, opt => opt.MapFrom(src => src["SitecoreId"]))
            .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src["Name"]))
            .ForMember(dest => dest.DisplayName, opt => opt.MapFrom(src => src["DisplayName"]))
            .ForMember(dest => dest.Description, opt => opt.MapFrom(src => src["Description"]))
            .ForMember(
                dest => dest.ParentCatalogList,
                opt => opt.ResolveUsing <MultilistFieldResolver, string>(src => src["ParentCatalogList"]))
            .ForMember(
                dest => dest.ChildrenCategoryList,
                opt => opt.ResolveUsing <MultilistFieldResolver, string>(src => src["ChildrenCategoryList"]));
        }
        public CartProfile(ICurrencyProvider currencyProvider)
        {
            Assert.ArgumentNotNull(currencyProvider, nameof(currencyProvider));

            this.CreateMap <Connect.Cart, Cart>()
            .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.ExternalId))
            .ForMember(dest => dest.Price, opt => opt.MapFrom(src => src.Total))
            .ForMember(dest => dest.CartLines, opt => opt.Ignore())
            .ForMember(dest => dest.Addresses, opt => opt.MapFrom(src => src.Parties))
            .ForMember(
                dest => dest.Adjustments,
                opt => opt.MapFrom(src => src.Adjustments.Select(a => a.Description).ToList()))
            .ReverseMap();

            this.CreateMap <CommerceCart, Cart>()
            .IncludeBase <Connect.Cart, Cart>()
            .ReverseMap();

            this.CreateMap <Connect.CartLine, CartLine>()
            .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.ExternalCartLineId))
            .ForMember(dest => dest.Price, opt => opt.MapFrom(src => src.Total))
            .ForMember(dest => dest.Product, opt => opt.Ignore())
            .ForMember(dest => dest.Variant, opt => opt.Ignore())
            .ReverseMap();

            this.CreateMap <CommerceCartLine, CartLine>()
            .IncludeBase <Connect.CartLine, CartLine>()
            .ReverseMap();

            this.CreateMap <TotalPrice, Total>()
            .ForMember(dest => dest.Amount, opt => opt.MapFrom(src => src.Total))
            .ForMember(
                dest => dest.TaxTotal,
                opt => opt.MapFrom(
                    src => new TaxTotal
            {
                Amount = src.TaxTotal
            }))
            .ForMember(src => src.Description, opt => opt.Ignore());

            this.CreateMap <Total, TotalPrice>()
            .ForMember(dest => dest.Total, opt => opt.MapFrom(src => src.Amount))
            .ForMember(dest => dest.TaxTotal, opt => opt.MapFrom(src => src.TaxTotal.Amount))
            .ForMember(dest => dest.CurrencyCode, opt => opt.MapFrom(src => src.CurrencyCode))
            .ForMember(
                dest => dest.CurrencySymbol,
                opt => opt.MapFrom(src => currencyProvider.GetCurrencySymbolByCode(src.CurrencyCode)))
            .ForAllOtherMembers(opt => opt.Ignore());

            this.CreateMap <CommerceTotal, TotalPrice>()
            .ForMember(
                dest => dest.TotalSavings,
                opt => opt.MapFrom(src => src.LineItemDiscountAmount + src.OrderLevelDiscountAmount))
            .ForMember(dest => dest.Subtotal, opt => opt.MapFrom(src => src.Subtotal))
            .ForMember(dest => dest.HandlingTotal, opt => opt.MapFrom(src => src.HandlingTotal))
            .ForMember(dest => dest.ShippingTotal, opt => opt.MapFrom(src => src.ShippingTotal))
            .IncludeBase <Total, TotalPrice>();
        }
Ejemplo n.º 3
0
        public void Initialize(Total model, ICurrencyProvider currencyProvider)
        {
            Assert.ArgumentNotNull(model, nameof(model));
            Assert.ArgumentNotNull(model, nameof(currencyProvider));

            this.CurrencySymbol = currencyProvider.GetCurrencySymbolByCode(model.CurrencyCode);

            this.CurrencyCode = model.CurrencyCode;
            this.Total        = model.Amount;
            this.TaxTotal     = model.TaxTotal?.Amount ?? 0;

            var commerceModel = model as CommerceTotal;

            this.Subtotal      = commerceModel?.Subtotal;
            this.ShippingTotal = commerceModel?.ShippingTotal;
            this.HandlingTotal = commerceModel?.HandlingTotal;
            this.TotalSavings  = commerceModel?.LineItemDiscountAmount + commerceModel?.OrderLevelDiscountAmount;

            this.Temp = model;
        }