Exemple #1
0
        private void EnsureExchangeOrderCreated()
        {
            if (ExchangeOrder == null)
            {
                ExchangeOrder = new OrderModel(CreateEntity <Foundation.Orders.Model.Order>(), _client, _orderService)
                {
                    Name            = CurrentOrder.Name,
                    StoreId         = CurrentOrder.StoreId,
                    BillingCurrency = CurrentOrder.BillingCurrency,
                    CurrentStatus   = (int)OrderStatus.AwaitingExchange,
                    CustomerId      = CurrentOrder.CustomerId,
                    CustomerName    = CurrentOrder.CustomerName
                };
                ExchangeOrder.GenerateTrackingNumber();
                ExchangeOrder.InnerItem.ParentOrderId = CurrentOrder.OrderGroupId;
                RmaRequest.ExchangeOrder   = ExchangeOrder.InnerItem;
                RmaRequest.ExchangeOrderId = ExchangeOrder.OrderGroupId;

                //Copy order addresses to exchange order
                foreach (var orderAddress in CurrentOrder.OrderAddresses)
                {
                    var newAddress = CreateEntity <OrderAddress>();
                    newAddress.InjectFrom(orderAddress);
                    newAddress.OrderAddressId = newAddress.GenerateNewKey();
                    newAddress.OrderGroup     = ExchangeOrder.InnerItem;
                    newAddress.OrderGroupId   = ExchangeOrder.OrderGroupId;
                    ExchangeOrder.OrderAddresses.Add(newAddress);
                }

                //Create order form
                var orderForm = CreateEntity <OrderForm>();
                orderForm.Name       = CurrentOrder.OrderForms[0].Name;
                orderForm.OrderGroup = ExchangeOrder.InnerItem;
                ExchangeOrder.OrderForms.Add(orderForm);

                //Create shipment
                var shipment = CreateEntity <Shipment>();
                orderForm.Shipments.Add(shipment);
                shipment.OrderForm = orderForm;
            }
        }