public CartLineModel Initialize(CartLine model)
        {
            Assert.ArgumentNotNull(model, nameof(model));

            var result = new CartLineModel();

            result.Id = model.ExternalCartLineId;

            var commerceCartProduct = model.Product as CommerceCartProduct;

            var product = this.catalogRepository.GetProduct(model.Product.ProductId);

            result.Product  = product;
            result.Variant  = product.Variants?.FirstOrDefault(x => x.ProductVariantId == commerceCartProduct?.ProductVariantId);
            result.Quantity = model.Quantity;

            var price = new CartPriceModel();

            price.Initialize(model.Total, this.currencyProvider);
            result.Price = price;

            result.Temp = model;

            return(result);
        }
        public TResult Initialize <TResult>(Cart model)
            where TResult : CartModel, new()
        {
            Assert.ArgumentNotNull(model, nameof(model));

            var result = new TResult();

            result.Id = model.ExternalId;

            result.CartLines   = model.Lines.Select(this.Initialize).ToList();
            result.Adjustments = model.Adjustments?.Select(a => a.Description).ToList() ?? new List <string>();
            result.Addresses   = model.Parties?.Select(x => this.entityMapper.MapToAddress(x)).ToList()
                                 ?? new List <AddressModel>();
            result.Payments = model.Payment?.Select(x => this.entityMapper.MapToFederatedPayment(x)).ToList()
                              ?? new List <FederatedPaymentModel>();
            result.Shippings = model.Shipping?.Select(x => this.entityMapper.MapToShippingMethodModel(x)).ToList()
                               ?? new List <ShippingMethodModel>();

            var price = new CartPriceModel();

            price.Initialize(model.Total, this.currencyProvider);
            result.Price = price;

            result.Email = model.Email;

            result.Temp = model;

            return(result);
        }