Beispiel #1
0
        public static MivaOrder ToSVOrder(this Order order)
        {
            var svOrder = new MivaOrder()
            {
                Id            = order.Id.ToString(),
                OrderDateUtc  = order.OrderDate.FromEpochTime(),
                Status        = (MivaOrderStatusEnum)order.Status,
                PaymentStatus = GetPaymentStatus(order),
                ShippingInfo  = new MivaShippingInfo()
                {
                    ContactInfo = new MivaShippingContactInfo()
                    {
                        FirstName    = order.ShipFName,
                        LastName     = order.ShipLName,
                        EmailAddress = order.ShipEmail,
                        CompanyName  = order.ShipComp,
                        PhoneNumber  = order.ShipPhone
                    },
                    Address = new MivaShippingAddress()
                    {
                        Line1      = order.ShipAddr1,
                        Line2      = order.ShipAddr2,
                        City       = order.ShipCity,
                        Country    = order.ShipCountry,
                        PostalCode = order.ShipZip,
                        State      = order.ShipState
                    },
                    Carrier        = order.ShipMethod,
                    ShippingCharge = order.TotalShip
                },
                Items = GetOrderItems(order),
                Total = order.Total
            };

            var notes = order.Notes?.Where(n => !string.IsNullOrEmpty(n.NoteText) && n.UserId != 0).Select(n => n.NoteText);

            if (notes != null)
            {
                svOrder.Note = string.Join(";", notes);
            }

            if (order.Charges != null && order.Charges.Any())
            {
                FillOrderCharges(order, svOrder);
            }

            if (order.Coupons != null && order.Coupons.Any())
            {
                svOrder.Promotions = order.Coupons.Select(c => new MivaOrderPromotion()
                {
                    Code = c.Code, Amount = c.Total
                });
            }

            return(svOrder);
        }
Beispiel #2
0
        private static void FillOrderCharges(Order order, MivaOrder svOrder)
        {
            foreach (var orderCharge in order.Charges)
            {
                switch (orderCharge.Type)
                {
                case "TAX":
                {
                    svOrder.Tax = orderCharge.Amount;
                    break;
                }

                case "DISCOUNT":
                {
                    svOrder.Discount = orderCharge.Amount * -1;
                    break;
                }
                }
            }
        }