Example #1
0
        public static OrdersOrder ToShipstationOrder(this VirtoCommerce.Domain.Order.Model.CustomerOrder order)
        {
            if (order.Shipments != null && order.Shipments.Any())
            {
                var retVal = new OrdersOrder
                {
                    OrderNumber             = order.Number,
                    OrderID                 = order.Id,
                    OrderStatus             = order.Status,
                    OrderDate               = String.Format("{0:MM'/'dd'/'yyyy HH:mm}", order.CreatedDate),
                    LastModified            = String.Format("{0:MM'/'dd'/'yyyy HH:mm}", order.ModifiedDate),
                    OrderTotal              = (float)order.Sum,
                    ShippingAmount          = (float)order.Shipments.Sum(sh => sh.Sum),
                    TaxAmount               = (float)order.Tax,
                    ShippingMethod          = order.Shipments.First().ShipmentMethodCode,
                    ShippingAmountSpecified = true,
                    PaymentMethod           = order.InPayments.First().GatewayCode
                };
                var items = new List <OrdersOrderItem>();
                order.Shipments.Where(s => s.Items != null && s.Items.Any()).ForEach(sh =>
                {
                    sh.Items.ForEach(shi =>
                    {
                        var item = new OrdersOrderItem
                        {
                            SKU             = shi.LineItem.ProductId,
                            ImageUrl        = shi.LineItem.ImageUrl,
                            LineItemID      = shi.LineItemId,
                            Name            = shi.LineItem.Name,
                            Quantity        = (sbyte)shi.Quantity,
                            UnitPrice       = (float)order.Items.Single(i => i.ProductId == shi.LineItem.ProductId).Price,
                            Weight          = (float)(order.Items.Single(i => i.ProductId == shi.LineItem.ProductId).Weight ?? 0),
                            WeightSpecified = order.Items.Single(i => i.ProductId == shi.LineItem.ProductId).Weight != null,
                            WeightUnits     = order.Items.Single(i => i.ProductId == shi.LineItem.ProductId).WeightUnit,
                        };

                        items.Add(item);
                    });

                    retVal.Items = items.ToArray();
                });

                var customer = new OrdersOrderCustomer
                {
                    CustomerCode = order.CustomerId
                };

                var billAddress =
                    order.Addresses.FirstOrDefault(
                        a => a.AddressType == AddressType.Billing || a.AddressType == AddressType.BillingAndShipping);

                if (billAddress != null)
                {
                    var billTo = new OrdersOrderCustomerBillTo
                    {
                        Company = billAddress.Organization,
                        Name    = billAddress.FirstName + " " + billAddress.LastName,
                        Phone   = billAddress.Phone
                    };

                    customer.BillTo = billTo;
                }

                var shipAddress =
                    order.Addresses.FirstOrDefault(
                        a => a.AddressType == AddressType.Shipping || a.AddressType == AddressType.BillingAndShipping);

                if (shipAddress != null)
                {
                    var shipTo = new OrdersOrderCustomerShipTo
                    {
                        Company    = shipAddress.Organization,
                        Name       = shipAddress.FirstName + " " + shipAddress.LastName,
                        Phone      = shipAddress.Phone,
                        Address1   = shipAddress.Line1,
                        City       = shipAddress.City,
                        PostalCode = shipAddress.PostalCode,
                        Country    = shipAddress.CountryCode,
                        State      = shipAddress.RegionId ?? shipAddress.RegionName
                    };

                    customer.ShipTo = shipTo;
                }

                retVal.Customer = customer;

                return(retVal);
            }

            return(null);
        }
Example #2
0
 /// <summary>
 /// This should be loaded from the database query.I ma just adding a template to help your development
 /// </summary>
 public string OrdersReadByParameters(DateTime startDate, DateTime endDate, int page)
 {
     try
     {
         Orders rootOrder = new Orders();
         rootOrder.pages = 50;
         OrdersOrder order = new OrdersOrder
         {
             OrderID = "123456",
             OrderNumber = "abcd",
             OrderTotal = 12.56F,
             OrderDate = DateTime.Now.ToShortDateString(),
             OrderStatus = "Open",
             LastModified = DateTime.Now.AddDays(3).ToShortDateString(),
             ShippingMethod = "USPS-Ground",
             PaymentMethod = "Credit Card",
             TaxAmount = 3.45F,
             ShippingAmount = 5.99F,
             CustomerNotes = "Adding a note on an order really sucks !!!!",
             InternalNotes = "This also sucks too !!",
             Customer = new OrdersOrderCustomer
             {
                 BillTo = new OrdersOrderCustomerBillTo
                 {
                     Name = "Rennish Joseph",
                     Email = "*****@*****.**",
                     Company = "Kerala Tate Buds",
                     Phone = "9075671234"
                 },
                 CustomerCode = "010",
                 ShipTo = new OrdersOrderCustomerShipTo
                 {
                     Address1 = "123 Mainstareet",
                     City = "Jacksonville",
                     State = "Florida",
                     Phone = "123456",
                     PostalCode = "32226"
                 }
             },
             Items = new OrdersOrderItem[]
             {
                 new OrdersOrderItem
                 {
                     SKU = "SKU-12345",
                     Name = "RV part",
                     ImageUrl = "http://asp.net/image.png",
                     Weight = 3.89f,
                     Options = new OrdersOrderItemOption[]
                     {
                         new OrdersOrderItemOption
                         {
                             Name = "XL",
                             Value = "LX",
                             Weight = 6.78f,
                             WeightSpecified = true
                         },
                         new OrdersOrderItemOption
                         {
                             Name = "Medium",
                             Value = "MD",
                             Weight = 6.78f,
                             WeightSpecified = true
                         }
                     }
                 }
             }
         };
         rootOrder.Order = new OrdersOrder[] { order };
         //use the xml serializer to convert the object into an xml string
         string xmlString = new XmlUtils().XmlStringSerialize(rootOrder);
         return xmlString;
     }
     catch (Exception ex)
     {
         //Log errors
         throw;
     }
 }
Example #3
0
        //[Fact]
        public void TestSerialization()
        {
            const string dateFormat = "{0:MM'/'dd'/'yyyy  HH:mm:ss tt}";

            var billAddress = new OrdersOrderCustomerBillTo
            {
                Company = "Home",
                Email   = "*****@*****.**",
                Name    = "Test Person"
            };

            var shipAddress = new OrdersOrderCustomerShipTo
            {
                Address1   = "45 Fremont street, 2",
                City       = "Los Angeles",
                Company    = "Home",
                Country    = "US",
                Name       = "Test Person",
                PostalCode = "91311",
                State      = "California"
            };

            var customer = new OrdersOrderCustomer
            {
                CustomerCode = "testCustomer",
                BillTo       = billAddress,
                ShipTo       = shipAddress
            };

            var order = new OrdersOrder
            {
                OrderID        = "1234567890",
                OrderNumber    = "CU123456789",
                OrderDate      = String.Format(dateFormat, DateTime.UtcNow),
                LastModified   = String.Format(dateFormat, DateTime.UtcNow),
                OrderStatus    = OrderStatusEnum.AwaitingShipment.ToString(),
                Customer       = customer,
                OrderTotal     = (float)111.2,
                TaxAmount      = (float)11.2,
                ShippingAmount = (float)3.02,
                ShippingMethod = "USPS"
            };


            var value = new Orders
            {
                Order          = new[] { order },
                pages          = 5,
                pagesSpecified = true
            };

            var xml = new XmlMediaTypeFormatter {
                UseXmlSerializer = true
            };;

            xml.WriterSettings.OmitXmlDeclaration = true;

            var str = Serialize(xml, value);
            //IsValidXml(str);
            //var json = new JsonMediaTypeFormatter();
            //str = Serialize(json, value);

            // Round trip
            //var orders = Deserialize<Order>(xml, str);
        }