public static Data.ShoppingCart AsServiceModel(this Cart cart)
        {
            var ret = new Data.ShoppingCart {
                Id = cart.Key
            };

            ret.CreatedBy    = cart.CreatedBy;
            ret.CreatedDate  = cart.CreatedAt;
            ret.Currency     = cart.Currency;
            ret.CustomerId   = cart.CustomerId;
            ret.CustomerName = cart.CustomerName;
            ret.LanguageCode = cart.Language;
            ret.Name         = cart.Name;
            ret.StoreId      = cart.StoreId;

            if (cart.Items != null && cart.Items.Any())
            {
                ret.Items = new List <Data.CartItem>(cart.Items.Select(x => x.AsServiceModel()));
                //cart.Items.ForEach(i => ret.Items.Add(i.AsServiceModel()));
            }
            else
            {
                ret.Items = new List <Data.CartItem>();
            }

            return(ret);
        }
 public Task<ShoppingCart> UpdateCurrentCartAsync(ShoppingCart cart)
 {
     return SendAsync<ShoppingCart, ShoppingCart>(
         CreateRequestUri(RelativePaths.UpdateCart),
         HttpMethod.Put,
         cart);
 }
        public static Cart AsWebModel(this Data.ShoppingCart cart)
        {
            var ret = new Cart {
                Key = cart.Id
            };

            if (cart.Items != null && cart.Items.Any())
            {
                ret.Items.AddRange(cart.Items.Select(x => x.AsWebModel()));
            }

            return(ret);
        }
Beispiel #4
0
        public static Data.ShoppingCart AsServiceModel(this Cart cart, string currency)
        {
            var ret = new Data.ShoppingCart { Id = cart.Key };
            ret.Currency = currency;

            if (cart.Items != null && cart.Items.Any())
            {
                ret.Items = new List<Data.CartItem>(cart.Items.Select(x => x.AsServiceModel()));
                //cart.Items.ForEach(i => ret.Items.Add(i.AsServiceModel()));
            }
            else
            {
                ret.Items = new List<Data.CartItem>();
            }

            return ret;
        }
        public static Cart AsWebModel(this Data.ShoppingCart cart)
        {
            var ret = new Cart(cart.StoreId, cart.CustomerId, cart.Currency, cart.LanguageCode);

            ret.CreatedAt = cart.CreatedDate;
            ret.CreatedBy = cart.CreatedBy;

            if (cart.Items != null && cart.Items.Any())
            {
                ret.Items.AddRange(cart.Items.Select(x => x.AsWebModel()));
            }

            ret.Key  = cart.Id;
            ret.Name = cart.Name;
            ret.Note = cart.Note;

            return(ret);
        }
        public static Data.ShoppingCart AsServiceModel(this Cart cart, string currency)
        {
            var ret = new Data.ShoppingCart {
                Id = cart.Key
            };

            ret.Currency = currency;

            if (cart.Items != null && cart.Items.Any())
            {
                ret.Items = new List <Data.CartItem>(cart.Items.Select(x => x.AsServiceModel()));
                //cart.Items.ForEach(i => ret.Items.Add(i.AsServiceModel()));
            }
            else
            {
                ret.Items = new List <Data.CartItem>();
            }

            return(ret);
        }
        public static Data.ShoppingCart AsServiceModel(this Cart cart)
        {
            var ret = new Data.ShoppingCart { Id = cart.Key };
            ret.CreatedBy = cart.CreatedBy;
            ret.CreatedDate = cart.CreatedAt;
            ret.Currency = cart.Currency;
            ret.CustomerId = cart.CustomerId;
            ret.CustomerName = cart.CustomerName;
            ret.LanguageCode = cart.Language;
            ret.Name = cart.Name;
            ret.StoreId = cart.StoreId;

            if (cart.Items != null && cart.Items.Any())
            {
                ret.Items = new List<Data.CartItem>(cart.Items.Select(x => x.AsServiceModel()));
                //cart.Items.ForEach(i => ret.Items.Add(i.AsServiceModel()));
            }
            else
            {
                ret.Items = new List<Data.CartItem>();
            }

            return ret;
        }
        public static Checkout AsCheckoutWebModel(
            this Data.ShoppingCart cart, VirtoCommerce.ApiClient.DataContracts.Orders.CustomerOrder order = null)
        {
            var checkoutModel = new Checkout();

            checkoutModel.TaxLines = new List <TaxLine>();

            if (cart.Addresses != null)
            {
                var billingAddress = cart.Addresses.FirstOrDefault(a => a.Type == AddressType.Billing);
                if (billingAddress != null)
                {
                    checkoutModel.BillingAddress = billingAddress.AsCartWebModel();
                    checkoutModel.Email          = billingAddress.Email;
                }

                var shippingAddress = cart.Addresses.FirstOrDefault(a => a.Type == AddressType.Shipping);
                if (shippingAddress != null)
                {
                    checkoutModel.ShippingAddress = shippingAddress.AsCartWebModel();
                    checkoutModel.Email           = shippingAddress.Email;
                }
            }

            checkoutModel.BuyerAcceptsMarketing = true;
            checkoutModel.Currency   = cart.Currency;
            checkoutModel.CustomerId = cart.CustomerId;

            if (cart.Discounts != null)
            {
                checkoutModel.Discounts = new List <VirtoCommerce.Web.Models.Discount>();

                foreach (var discount in cart.Discounts)
                {
                    checkoutModel.Discounts.Add(new VirtoCommerce.Web.Models.Discount
                    {
                        Amount = (decimal)discount.DiscountAmount,
                        Code   = discount.PromotionId,
                        Id     = discount.Id
                    });
                }
            }

            checkoutModel.Email = "";

            // TODO: Gift cards

            checkoutModel.Id = cart.Id;

            if (cart.Items != null)
            {
                checkoutModel.LineItems = new List <LineItem>();

                foreach (var item in cart.Items)
                {
                    checkoutModel.LineItems.Add(item.AsWebModel());
                }

                checkoutModel.TaxLines.Add(new TaxLine
                {
                    Title = "Line items taxes",
                    Price = cart.Items.Sum(i => i.TaxTotal)
                });
            }

            checkoutModel.Name = cart.Name;
            //checkoutModel.Note = cart.Note;

            if (order != null)
            {
                checkoutModel.Order = order.AsWebModel();
            }

            if (cart.Payments != null)
            {
                var payment = cart.Payments.FirstOrDefault(); // Remake for multipayment

                if (payment != null)
                {
                    checkoutModel.PaymentMethod = new Models.PaymentMethod
                    {
                        Code = payment.PaymentGatewayCode
                    };
                }

                checkoutModel.TaxLines.Add(new TaxLine
                {
                    Title = "Payments taxes",
                    Price = 0
                });
            }

            if (cart.Shipments != null)
            {
                var shipment = cart.Shipments.FirstOrDefault(); // Remake for multishipment

                if (shipment != null)
                {
                    checkoutModel.ShippingMethod = new ShippingMethod
                    {
                        Handle = shipment.ShipmentMethodCode,
                        Price  = shipment.ShippingPrice,
                        Title  = shipment.ShipmentMethodCode
                    };
                }

                checkoutModel.TaxLines.Add(new TaxLine
                {
                    Title = "Shipping taxes",
                    Price = cart.Shipments.Sum(s => s.TaxTotal)
                });
            }

            // Transactions

            return(checkoutModel);
        }
        public static Data.ShoppingCart AsServiceModel(this Checkout checkoutModel, ref Data.ShoppingCart cart)
        {
            cart.Addresses = new List <Data.Address>();
            if (checkoutModel.BillingAddress != null)
            {
                var billingAddress = checkoutModel.BillingAddress.AsCartServiceModel();
                billingAddress.Email = checkoutModel.Email;
                billingAddress.Type  = AddressType.Billing;

                cart.Addresses.Add(billingAddress);
            }
            if (checkoutModel.ShippingAddress != null)
            {
                var shippingAddress = checkoutModel.ShippingAddress.AsCartServiceModel();
                shippingAddress.Email = checkoutModel.Email;
                shippingAddress.Type  = AddressType.Shipping;

                cart.Addresses.Add(shippingAddress);
            }

            cart.Currency   = checkoutModel.Currency;
            cart.CustomerId = checkoutModel.CustomerId;

            // DISCOUNTS

            if (checkoutModel.LineItems != null)
            {
                cart.Items = new List <CartItem>();
                foreach (var lineItemModel in checkoutModel.LineItems)
                {
                    cart.Items.Add(lineItemModel.AsServiceModel());
                }
            }

            //cart.Note = checkoutModel.Note;

            if (checkoutModel.PaymentMethod != null)
            {
                cart.Payments = new List <Payment>();
                cart.Payments.Add(new Payment
                {
                    Currency           = checkoutModel.Currency,
                    PaymentGatewayCode = checkoutModel.PaymentMethod.Code,
                    Amount             = checkoutModel.TotalPrice
                });
            }

            if (checkoutModel.ShippingMethod != null)
            {
                cart.Shipments = new List <Shipment>();
                cart.Shipments.Add(new Shipment
                {
                    Currency           = checkoutModel.Currency,
                    ShipmentMethodCode = checkoutModel.ShippingMethod.Handle,
                    ShippingPrice      = checkoutModel.ShippingMethod.Price
                });
            }

            cart.ShippingTotal = checkoutModel.ShippingPrice;
            cart.SubTotal      = checkoutModel.SubtotalPrice;
            cart.TaxTotal      = checkoutModel.TaxPrice;
            cart.Total         = checkoutModel.TotalPrice;

            return(cart);
        }