Ejemplo n.º 1
0
        public static QuoteRequest ToWebModel(this VirtoCommerceQuoteModuleWebModelQuoteRequest serviceModel, IEnumerable <Currency> availCurrencies, Language language)
        {
            var currency = availCurrencies.FirstOrDefault(x => x.Equals(serviceModel.Currency)) ?? new Currency(language, serviceModel.Currency);
            var webModel = new QuoteRequest(currency, language);

            webModel.InjectFrom <NullableAndEnumValueInjecter>(serviceModel);

            webModel.Currency = currency;
            webModel.Language = language;
            webModel.ManualRelDiscountAmount = new Money(serviceModel.ManualRelDiscountAmount ?? 0, currency);
            webModel.ManualShippingTotal     = new Money(serviceModel.ManualShippingTotal ?? 0, currency);
            webModel.ManualSubTotal          = new Money(serviceModel.ManualSubTotal ?? 0, currency);

            if (serviceModel.Addresses != null)
            {
                webModel.Addresses = serviceModel.Addresses.Select(a => a.ToWebModel()).ToList();
            }

            if (serviceModel.Attachments != null)
            {
                webModel.Attachments = serviceModel.Attachments.Select(a => a.ToWebModel()).ToList();
            }

            if (!string.IsNullOrEmpty(serviceModel.Coupon))
            {
                webModel.Coupon = new Coupon {
                    AppliedSuccessfully = true, Code = serviceModel.Coupon
                };
            }

            if (serviceModel.DynamicProperties != null)
            {
                webModel.DynamicProperties = serviceModel.DynamicProperties.Select(dp => dp.ToWebModel()).ToList();
            }

            if (serviceModel.Items != null)
            {
                webModel.Items = serviceModel.Items.Select(i => i.ToWebModel(currency)).ToList();
            }

            // TODO
            if (serviceModel.ShipmentMethod != null)
            {
            }

            if (serviceModel.TaxDetails != null)
            {
                webModel.TaxDetails = serviceModel.TaxDetails.Select(td => td.ToWebModel(currency)).ToList();
            }

            if (serviceModel.Totals != null)
            {
                webModel.Totals = serviceModel.Totals.ToWebModel(currency);
            }

            return(webModel);
        }
Ejemplo n.º 2
0
        public virtual QuoteRequest ToQuoteRequest(quoteDto.QuoteRequest quoteRequestDto, IEnumerable <Currency> availCurrencies, Language language)
        {
            var currency = availCurrencies.FirstOrDefault(x => x.Equals(quoteRequestDto.Currency)) ?? new Currency(language, quoteRequestDto.Currency);
            var result   = new QuoteRequest(currency, language);

            result.InjectFrom <NullableAndEnumValueInjecter>(quoteRequestDto);

            result.Currency = currency;
            result.Language = language;
            result.ManualRelDiscountAmount = new Money(quoteRequestDto.ManualRelDiscountAmount ?? 0, currency);
            result.ManualShippingTotal     = new Money(quoteRequestDto.ManualShippingTotal ?? 0, currency);
            result.ManualSubTotal          = new Money(quoteRequestDto.ManualSubTotal ?? 0, currency);

            if (quoteRequestDto.Addresses != null)
            {
                result.Addresses = quoteRequestDto.Addresses.Select(a => ToAddress(a)).ToList();
            }

            if (quoteRequestDto.Attachments != null)
            {
                result.Attachments = quoteRequestDto.Attachments.Select(a => ToAttachment(a)).ToList();
            }

            if (!string.IsNullOrEmpty(quoteRequestDto.Coupon))
            {
                result.Coupon = new Coupon {
                    AppliedSuccessfully = true, Code = quoteRequestDto.Coupon
                };
            }

            if (quoteRequestDto.DynamicProperties != null)
            {
                result.DynamicProperties = quoteRequestDto.DynamicProperties.Select(ToDynamicProperty).ToList();
            }

            if (quoteRequestDto.Items != null)
            {
                result.Items = quoteRequestDto.Items.Select(i => ToQuoteItem(i, currency)).ToList();
            }

            // TODO
            if (quoteRequestDto.ShipmentMethod != null)
            {
            }

            if (quoteRequestDto.TaxDetails != null)
            {
                result.TaxDetails = quoteRequestDto.TaxDetails.Select(td => ToTaxDetail(td, currency)).ToList();
            }

            if (quoteRequestDto.Totals != null)
            {
                result.Totals = ToQuoteTotals(quoteRequestDto.Totals, currency);
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static QuoteRequest ToShopifyModel(this Storefront.Model.Quote.QuoteRequest storefrontModel)
        {
            var shopifyModel = new QuoteRequest();

            shopifyModel.InjectFrom <NullableAndEnumValueInjecter>(storefrontModel);

            shopifyModel.Addresses = new List <Address>();
            foreach (var address in storefrontModel.Addresses)
            {
                shopifyModel.Addresses.Add(address.ToShopifyModel());
            }

            shopifyModel.Attachments = new List <Attachment>();
            foreach (var attachment in storefrontModel.Attachments)
            {
                shopifyModel.Attachments.Add(attachment.ToShopifyModel());
            }

            if (storefrontModel.Coupon != null)
            {
                shopifyModel.Coupon = storefrontModel.Coupon.Code;
            }

            shopifyModel.Currency = storefrontModel.Currency.ToShopifyModel();

            shopifyModel.Items = new List <QuoteItem>();
            foreach (var quoteItem in storefrontModel.Items)
            {
                shopifyModel.Items.Add(quoteItem.ToShopifyModel());
            }

            shopifyModel.Language = storefrontModel.Language.ToShopifyModel();
            shopifyModel.ManualRelDiscountAmount = storefrontModel.ManualRelDiscountAmount.Amount;
            shopifyModel.ManualShippingTotal     = storefrontModel.ManualShippingTotal.Amount;
            shopifyModel.ManualSubTotal          = storefrontModel.ManualSubTotal.Amount;

            if (storefrontModel.ShipmentMethod != null)
            {
                shopifyModel.ShipmentMethod = storefrontModel.ShipmentMethod.ToShopifyModel();
            }

            shopifyModel.TaxDetails = new List <TaxLine>();
            foreach (var taxDetail in storefrontModel.TaxDetails)
            {
                shopifyModel.TaxDetails.Add(taxDetail.ToShopifyModel());
            }

            if (storefrontModel.Totals != null)
            {
                shopifyModel.Totals = storefrontModel.Totals.ToShopifyModel();
            }

            return(shopifyModel);
        }
        public virtual QuoteRequest ToLiquidQuoteRequest(Storefront.Model.Quote.QuoteRequest quoteRequest)
        {
            var result = new QuoteRequest();

            result.InjectFrom <NullableAndEnumValueInjecter>(quoteRequest);

            result.Addresses = new List <Address>();
            foreach (var address in quoteRequest.Addresses)
            {
                result.Addresses.Add(ToLiquidAddress(address));
            }

            result.Attachments = new List <Attachment>();
            foreach (var attachment in quoteRequest.Attachments)
            {
                result.Attachments.Add(ToLiquidAttachment(attachment));
            }

            if (quoteRequest.Coupon != null)
            {
                result.Coupon = quoteRequest.Coupon.Code;
            }

            result.Currency = ToLiquidCurrency(quoteRequest.Currency);

            result.Items = new List <QuoteItem>();
            foreach (var quoteItem in quoteRequest.Items)
            {
                result.Items.Add(ToLiquidQuoteItem(quoteItem));
            }

            result.Language = ToLiquidLanguage(quoteRequest.Language);
            result.ManualRelDiscountAmount = quoteRequest.ManualRelDiscountAmount.Amount;
            result.ManualShippingTotal     = quoteRequest.ManualShippingTotal.Amount;
            result.ManualSubTotal          = quoteRequest.ManualSubTotal.Amount;

            if (quoteRequest.ShipmentMethod != null)
            {
                result.ShipmentMethod = ToLiquidShippingMethod(quoteRequest.ShipmentMethod);
            }

            result.TaxDetails = new List <TaxLine>();
            foreach (var taxDetail in quoteRequest.TaxDetails)
            {
                result.TaxDetails.Add(ToLiquidTaxLine(taxDetail));
            }

            if (quoteRequest.Totals != null)
            {
                result.Totals = ToLiquidRequestTotal(quoteRequest.Totals);
            }

            return(result);
        }