public static ShoppingCart ToShoppingCart(this cartDto.ShoppingCart cartDto, Currency currency, Language language, Model.Customer.CustomerInfo customer) { return(CartConverterInstance.ToShoppingCart(cartDto, currency, language, customer)); }
public virtual ShoppingCart ToShoppingCart(cartDto.ShoppingCart cartDto, Currency currency, Language language, Model.Customer.CustomerInfo customer) { var result = ServiceLocator.Current.GetInstance <CartFactory>().CreateCart(currency, language); result.InjectFrom <NullableAndEnumValueInjecter>(cartDto); result.Customer = customer; if (cartDto.Coupon != null) { result.Coupon = new Coupon { Code = cartDto.Coupon.Code, AppliedSuccessfully = cartDto.Coupon.IsValid ?? false }; } if (cartDto.Items != null) { result.Items = cartDto.Items.Select(i => ToLineItem(i, currency, language)).ToList(); result.HasPhysicalProducts = result.Items.Any(i => string.IsNullOrEmpty(i.ProductType) || !string.IsNullOrEmpty(i.ProductType) && i.ProductType.Equals("Physical", StringComparison.OrdinalIgnoreCase)); } if (cartDto.Addresses != null) { result.Addresses = cartDto.Addresses.Select(ToAddress).ToList(); var billingAddress = result.Addresses.FirstOrDefault(a => a.Type == AddressType.Billing); if (billingAddress == null) { billingAddress = new Address { Type = AddressType.Billing }; } if (result.HasPhysicalProducts) { var shippingAddress = result.Addresses.FirstOrDefault(a => a.Type == AddressType.Shipping); if (shippingAddress == null) { shippingAddress = new Address { Type = AddressType.Shipping }; } } } if (cartDto.Payments != null) { result.Payments = cartDto.Payments.Select(p => ToPayment(p, currency)).ToList(); } if (cartDto.Shipments != null) { result.Shipments = cartDto.Shipments.Select(s => ToShipment(s, result)).ToList(); } if (cartDto.DynamicProperties != null) { result.DynamicProperties = cartDto.DynamicProperties.Select(ToDynamicProperty).ToList(); } if (cartDto.TaxDetails != null) { result.TaxDetails = cartDto.TaxDetails.Select(td => ToTaxDetail(td, currency)).ToList(); } result.DiscountAmount = new Money(cartDto.DiscountAmount ?? 0, currency); result.HandlingTotal = new Money(cartDto.HandlingTotal ?? 0, currency); result.HandlingTotalWithTax = new Money(cartDto.HandlingTotalWithTax ?? 0, currency); result.IsAnonymous = cartDto.IsAnonymous == true; result.IsRecuring = cartDto.IsRecuring == true; result.VolumetricWeight = (decimal)(cartDto.VolumetricWeight ?? 0); result.Weight = (decimal)(cartDto.Weight ?? 0); return(result); }
public virtual ShoppingCart ToShoppingCart(cartDto.ShoppingCart cartDto, Currency currency, Language language, Model.Customer.CustomerInfo customer) { var result = new ShoppingCart(currency, language); result.InjectFrom <NullableAndEnumValueInjecter>(cartDto); result.Customer = customer; if (cartDto.Coupon != null) { result.Coupon = new Coupon { Code = cartDto.Coupon, AppliedSuccessfully = !string.IsNullOrEmpty(cartDto.Coupon) }; } if (cartDto.Items != null) { result.Items = cartDto.Items.Select(i => ToLineItem(i, currency, language)).ToList(); result.HasPhysicalProducts = result.Items.Any(i => string.IsNullOrEmpty(i.ProductType) || !string.IsNullOrEmpty(i.ProductType) && i.ProductType.Equals("Physical", StringComparison.OrdinalIgnoreCase)); } if (cartDto.Addresses != null) { result.Addresses = cartDto.Addresses.Select(ToAddress).ToList(); } if (cartDto.Payments != null) { result.Payments = cartDto.Payments.Select(p => ToPayment(p, result)).ToList(); } if (cartDto.Shipments != null) { result.Shipments = cartDto.Shipments.Select(s => ToShipment(s, result)).ToList(); } if (cartDto.DynamicProperties != null) { result.DynamicProperties = cartDto.DynamicProperties.Select(ToDynamicProperty).ToList(); } if (cartDto.TaxDetails != null) { result.TaxDetails = cartDto.TaxDetails.Select(td => ToTaxDetail(td, currency)).ToList(); } result.DiscountAmount = new Money(cartDto.DiscountAmount ?? 0, currency); result.HandlingTotal = new Money(cartDto.HandlingTotal ?? 0, currency); result.HandlingTotalWithTax = new Money(cartDto.HandlingTotalWithTax ?? 0, currency); result.IsAnonymous = cartDto.IsAnonymous == true; result.IsRecuring = cartDto.IsRecuring == true; result.VolumetricWeight = (decimal)(cartDto.VolumetricWeight ?? 0); result.Weight = (decimal)(cartDto.Weight ?? 0); return(result); }