예제 #1
0
        public string ProcessOrders(NopCommerceDataReader dataReader, NopImportContext nopImportContext)
        {
            HashSet <OrderData> orders = dataReader.GetOrderData();
            var orderLines             = dataReader.GetOrderLineData().GroupBy(x => x.OrderId)
                                         .ToDictionary(x => x.Key, x => x.ToHashSet());
            var site  = _session.Get <Site>(_site.Id);
            var guids = _session.QueryOver <Order>().Select(o => o.Guid).List <Guid>();

            using (EventContext.Instance.Disable <GenerateGiftCards>())
            {
                _session.Transact(session =>
                {
                    foreach (OrderData data in orders)
                    {
                        Guid guid = data.Guid;
                        if (guids.Contains(guid))
                        {
                            continue;
                        }

                        Entities.Orders.AddressData billingAddressData = null;
                        if (data.BillingAddress != null)
                        {
                            billingAddressData = new Entities.Orders.AddressData
                            {
                                Address1      = data.BillingAddress.Address1,
                                Address2      = data.BillingAddress.Address2,
                                City          = data.BillingAddress.City,
                                Company       = data.BillingAddress.Company,
                                CountryCode   = data.BillingAddress.CountryCode,
                                FirstName     = data.BillingAddress.FirstName,
                                LastName      = data.BillingAddress.LastName,
                                PhoneNumber   = data.BillingAddress.PhoneNumber,
                                PostalCode    = data.BillingAddress.PostalCode,
                                StateProvince = data.BillingAddress.StateProvince
                            };
                        }


                        Entities.Orders.AddressData shippingAddressData = null;
                        if (data.ShippingAddress != null)
                        {
                            shippingAddressData = new Entities.Orders.AddressData
                            {
                                Address1      = data.ShippingAddress.Address1,
                                Address2      = data.ShippingAddress.Address2,
                                City          = data.ShippingAddress.City,
                                Company       = data.ShippingAddress.Company,
                                CountryCode   = data.ShippingAddress.CountryCode,
                                FirstName     = data.ShippingAddress.FirstName,
                                LastName      = data.ShippingAddress.LastName,
                                PhoneNumber   = data.ShippingAddress.PhoneNumber,
                                PostalCode    = data.ShippingAddress.PostalCode,
                                StateProvince = data.ShippingAddress.StateProvince
                            };
                        }

                        var order = new Order
                        {
                            BillingAddress  = billingAddressData,
                            ShippingAddress = shippingAddressData,
                            CustomerIP      = data.CustomerIp,
                            DiscountAmount  = data.OrderDiscount,
                            Id                 = data.Id,
                            OrderEmail         = data.Email,
                            PaidDate           = data.PaidDate,
                            PaymentStatus      = GetPaymentStatus(data.PaymentStatus),
                            ShippingStatus     = GetShippingStatus(data.ShippingStatus),
                            ShippingMethodName = data.ShippingMethodName,
                            ShippingSubtotal   = data.OrderShippingExclTax,
                            ShippingTax        = data.OrderShippingInclTax - data.OrderShippingExclTax,
                            ShippingTotal      = data.OrderShippingInclTax,
                            Subtotal           = data.OrderSubtotalInclTax,
                            Tax                = data.OrderTax,
                            Total              = data.OrderTotal,
                            TotalPaid          = data.OrderTotal,
                            User               = nopImportContext.FindNew <User>(data.CustomerId),
                            SalesChannel       = EcommerceApp.NopCommerceSalesChannel,
                            PaymentMethod      = data.PaymentMethod,
                            OrderDate          = data.OrderDate
                        };
                        order.SetGuid(data.Guid);
                        order.AssignBaseProperties(site);
                        session.Insert(order);

                        if (order.OrderNotes == null)
                        {
                            order.OrderNotes = new List <OrderNote>();
                        }
                        data.Notes.Add(new OrderNoteData
                        {
                            Note           = "Previous order id: " + data.Id,
                            ShowToCustomer = false
                        });
                        foreach (OrderNoteData note in data.Notes)
                        {
                            var orderNote = new OrderNote
                            {
                                ShowToClient = note.ShowToCustomer,
                                Note         = note.Note,
                                Order        = order
                            };
                            if (note.Date.HasValue)
                            {
                                orderNote.CreatedOn = note.Date.Value;
                            }
                            order.OrderNotes.Add(orderNote);
                            orderNote.AssignBaseProperties(site);
                            session.Insert(orderNote);
                        }
                        int orderId = data.Id;
                        HashSet <OrderLineData> lineDatas = orderLines.ContainsKey(orderId)
                            ? orderLines[orderId]
                            : new HashSet <OrderLineData>();
                        foreach (OrderLineData lineData in lineDatas)
                        {
                            var orderLine = new OrderLine
                            {
                                Discount         = lineData.DiscountAmountInclTax,
                                Id               = lineData.Id,
                                Order            = order,
                                Quantity         = lineData.Quantity,
                                Name             = lineData.ProductName,
                                Price            = lineData.PriceInclTax,
                                UnitPrice        = lineData.UnitPriceInclTax,
                                UnitPricePreTax  = lineData.DiscountAmountExclTax,
                                PricePreTax      = lineData.PriceExclTax,
                                Tax              = lineData.PriceInclTax - lineData.PriceExclTax,
                                Weight           = lineData.ItemWeight.GetValueOrDefault(),
                                SKU              = lineData.SKU,
                                RequiresShipping = lineData.RequiresShipping
                            };
                            order.OrderLines.Add(orderLine);
                            orderLine.AssignBaseProperties(site);
                            session.Insert(orderLine);
                        }
                        nopImportContext.AddEntry(data.Id, order);
                    }
                });
            }

            return(string.Format("{0} orders processed", orders.Count));
        }
예제 #2
0
        public string ProcessOrders(NopCommerceDataReader dataReader, NopImportContext nopImportContext)
        {
            HashSet<OrderData> orders = dataReader.GetOrderData();
            HashSet<OrderLineData> orderLines = dataReader.GetOrderLineData();

            using (EventContext.Instance.Disable<GenerateGiftCards>())
            {
                _session.Transact(session =>
                {
                    foreach (OrderData data in orders)
                    {
                        Guid guid = data.Guid;
                        if (session.QueryOver<Order>().Where(o => o.Guid == guid).Any())
                            continue;

                        var billingAddress = nopImportContext.FindNew<Address>(data.BillingAddressId);
                        var shippingAddress =
                            nopImportContext.FindNew<Address>(data.ShippingAddressId.GetValueOrDefault());
                        var order = new Order
                        {
                            BillingAddress = billingAddress.ToAddressData(),
                            ShippingAddress = shippingAddress != null ? shippingAddress.ToAddressData() : null,
                            CustomerIP = data.CustomerIp,
                            DiscountAmount = data.OrderDiscount,
                            Id = data.Id,
                            OrderEmail = data.Email,
                            PaidDate = data.PaidDate,
                            PaymentStatus = GetPaymentStatus(data.PaymentStatus),
                            ShippingStatus = GetShippingStatus(data.ShippingStatus),
                            ShippingMethodName = data.ShippingMethodName,
                            ShippingSubtotal = data.OrderShippingExclTax,
                            ShippingTax = data.OrderShippingInclTax - data.OrderShippingExclTax,
                            ShippingTotal = data.OrderShippingInclTax,
                            Subtotal = data.OrderSubtotalInclTax,
                            Tax = data.OrderTax,
                            Total = data.OrderTotal,
                            TotalPaid = data.OrderTotal,
                            User = nopImportContext.FindNew<User>(data.CustomerId),
                            SalesChannel = EcommerceApp.NopCommerceSalesChannel,
                            PaymentMethod = data.PaymentMethod,
                            OrderDate = data.OrderDate
                        };
                        order.SetGuid(data.Guid);
                        session.Save(order);

                        if (order.OrderNotes == null)
                            order.OrderNotes = new List<OrderNote>();
                        data.Notes.Add(new OrderNoteData
                        {
                            Note = "Previous order id: " + data.Id,
                            ShowToCustomer = false
                        });
                        foreach (OrderNoteData note in data.Notes)
                        {
                            var orderNote = new OrderNote
                            {
                                ShowToClient = note.ShowToCustomer,
                                Note = note.Note,
                                Order = order
                            };
                            if (note.Date.HasValue)
                                orderNote.CreatedOn = note.Date.Value;
                            order.OrderNotes.Add(orderNote);
                            session.Save(orderNote);
                        }
                        int orderId = data.Id;
                        HashSet<OrderLineData> lineDatas = orderLines.FindAll(x => x.OrderId == orderId);
                        foreach (OrderLineData lineData in lineDatas)
                        {
                            var orderLine = new OrderLine
                            {
                                Discount = lineData.DiscountAmountInclTax,
                                Id = lineData.Id,
                                Order = order,
                                Quantity = lineData.Quantity,
                                Name = lineData.ProductName,
                                Price = lineData.PriceInclTax,
                                UnitPrice = lineData.UnitPriceInclTax,
                                UnitPricePreTax = lineData.DiscountAmountExclTax,
                                PricePreTax = lineData.PriceExclTax,
                                Tax = lineData.PriceInclTax - lineData.PriceExclTax,
                                Weight = lineData.ItemWeight.GetValueOrDefault(),
                                SKU = lineData.SKU,
                                RequiresShipping = lineData.RequiresShipping
                            };
                            order.OrderLines.Add(orderLine);
                            session.Save(orderLine);
                        }
                        nopImportContext.AddEntry(data.Id, order);
                    }
                });
            }

            return string.Format("{0} orders processed", orders.Count);
        }
예제 #3
0
        public string ProcessOrders(NopCommerceDataReader dataReader, NopImportContext nopImportContext)
        {
            HashSet <OrderData>     orders     = dataReader.GetOrderData();
            HashSet <OrderLineData> orderLines = dataReader.GetOrderLineData();

            using (EventContext.Instance.Disable <GenerateGiftCards>())
            {
                _session.Transact(session =>
                {
                    foreach (OrderData data in orders)
                    {
                        Guid guid = data.Guid;
                        if (session.QueryOver <Order>().Where(o => o.Guid == guid).Any())
                        {
                            continue;
                        }

                        var billingAddress  = nopImportContext.FindNew <Address>(data.BillingAddressId);
                        var shippingAddress =
                            nopImportContext.FindNew <Address>(data.ShippingAddressId.GetValueOrDefault());
                        var order = new Order
                        {
                            BillingAddress  = billingAddress.ToAddressData(),
                            ShippingAddress = shippingAddress != null ? shippingAddress.ToAddressData() : null,
                            CustomerIP      = data.CustomerIp,
                            DiscountAmount  = data.OrderDiscount,
                            Id                 = data.Id,
                            OrderEmail         = data.Email,
                            PaidDate           = data.PaidDate,
                            PaymentStatus      = GetPaymentStatus(data.PaymentStatus),
                            ShippingStatus     = GetShippingStatus(data.ShippingStatus),
                            ShippingMethodName = data.ShippingMethodName,
                            ShippingSubtotal   = data.OrderShippingExclTax,
                            ShippingTax        = data.OrderShippingInclTax - data.OrderShippingExclTax,
                            ShippingTotal      = data.OrderShippingInclTax,
                            Subtotal           = data.OrderSubtotalInclTax,
                            Tax                = data.OrderTax,
                            Total              = data.OrderTotal,
                            TotalPaid          = data.OrderTotal,
                            User               = nopImportContext.FindNew <User>(data.CustomerId),
                            SalesChannel       = EcommerceApp.NopCommerceSalesChannel,
                            PaymentMethod      = data.PaymentMethod,
                            OrderDate          = data.OrderDate
                        };
                        order.SetGuid(data.Guid);
                        session.Save(order);

                        if (order.OrderNotes == null)
                        {
                            order.OrderNotes = new List <OrderNote>();
                        }
                        data.Notes.Add(new OrderNoteData
                        {
                            Note           = "Previous order id: " + data.Id,
                            ShowToCustomer = false
                        });
                        foreach (OrderNoteData note in data.Notes)
                        {
                            var orderNote = new OrderNote
                            {
                                ShowToClient = note.ShowToCustomer,
                                Note         = note.Note,
                                Order        = order
                            };
                            if (note.Date.HasValue)
                            {
                                orderNote.CreatedOn = note.Date.Value;
                            }
                            order.OrderNotes.Add(orderNote);
                            session.Save(orderNote);
                        }
                        int orderId = data.Id;
                        HashSet <OrderLineData> lineDatas = orderLines.FindAll(x => x.OrderId == orderId);
                        foreach (OrderLineData lineData in lineDatas)
                        {
                            var orderLine = new OrderLine
                            {
                                Discount         = lineData.DiscountAmountInclTax,
                                Id               = lineData.Id,
                                Order            = order,
                                Quantity         = lineData.Quantity,
                                Name             = lineData.ProductName,
                                Price            = lineData.PriceInclTax,
                                UnitPrice        = lineData.UnitPriceInclTax,
                                UnitPricePreTax  = lineData.DiscountAmountExclTax,
                                PricePreTax      = lineData.PriceExclTax,
                                Tax              = lineData.PriceInclTax - lineData.PriceExclTax,
                                Weight           = lineData.ItemWeight.GetValueOrDefault(),
                                SKU              = lineData.SKU,
                                RequiresShipping = lineData.RequiresShipping
                            };
                            order.OrderLines.Add(orderLine);
                            session.Save(orderLine);
                        }
                        nopImportContext.AddEntry(data.Id, order);
                    }
                });
            }

            return(string.Format("{0} orders processed", orders.Count));
        }