public string ProcessProducts(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { HashSet <ProductData> productDatas = dataReader.GetProducts(); HashSet <ProductOptionValueData> optionValues = dataReader.GetProductOptionValues(); HashSet <ProductSpecificationValueData> specificationValues = dataReader.GetProductSpecificationValues(); var productContainer = _uniquePageService.GetUniquePage <ProductContainer>(); _session.Transact(session => { foreach (ProductData productData in productDatas) { var suggestParams = new SuggestParams { DocumentType = typeof(Product).FullName, PageName = productData.Name, UseHierarchy = true }; var product = new Product { Name = productData.Name, ProductAbstract = productData.Abstract.LimitCharacters(500), BodyContent = productData.Description, Parent = productContainer, UrlSegment = string.IsNullOrWhiteSpace(productData.Url) ? _webpageUrlService.Suggest(productContainer, suggestParams) : productData.Url, BrandPage = productData.BrandId.HasValue ? nopImportContext.FindNew <Brand>(productData.BrandId.Value) : null, Categories = productData.Categories.Select(nopImportContext.FindNew <Category>).ToList(), Tags = new HashSet <Tag>(productData.Tags.Select(nopImportContext.FindNew <Tag>).ToList()), PublishOn = productData.Published ? CurrentRequestData.Now.Date : (DateTime?)null }; SetSpecificationValues(nopImportContext, specificationValues.FindAll(data => data.ProductId == productData.Id), product); _importProductVariants.CreateProductVariants(nopImportContext, productData.ProductVariants, optionValues, product); session.Save(product); var pictureIds = productData.Pictures; foreach (var pictureId in pictureIds) { var mediaFile = nopImportContext.FindNew <MediaFile>(pictureId); if (mediaFile != null) { mediaFile.MediaCategory = product.Gallery; session.Update(mediaFile); } } } }); return(string.Format("{0} products processed.", productDatas.Count)); }
public string ProcessProducts(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { HashSet<ProductData> productDatas = dataReader.GetProducts(); HashSet<ProductOptionValueData> optionValues = dataReader.GetProductOptionValues(); HashSet<ProductSpecificationValueData> specificationValues = dataReader.GetProductSpecificationValues(); var productContainer = _uniquePageService.GetUniquePage<ProductContainer>(); _session.Transact(session => { foreach (ProductData productData in productDatas) { var suggestParams = new SuggestParams { DocumentType = typeof(Product).FullName, PageName = productData.Name, UseHierarchy = true }; var product = new Product { Name = productData.Name, ProductAbstract = productData.Abstract.LimitCharacters(500), BodyContent = productData.Description, Parent = productContainer, UrlSegment = string.IsNullOrWhiteSpace(productData.Url) ? _webpageUrlService.Suggest(productContainer, suggestParams) : productData.Url, BrandPage = productData.BrandId.HasValue ? nopImportContext.FindNew<Brand>(productData.BrandId.Value) : null, Categories = productData.Categories.Select(nopImportContext.FindNew<Category>).ToList(), Tags = new HashSet<Tag>(productData.Tags.Select(nopImportContext.FindNew<Tag>).ToList()), PublishOn = productData.Published ? CurrentRequestData.Now.Date : (DateTime?) null }; SetSpecificationValues(nopImportContext, specificationValues.FindAll(data => data.ProductId == productData.Id), product); _importProductVariants.CreateProductVariants(nopImportContext, productData.ProductVariants, optionValues, product); session.Save(product); var pictureIds = productData.Pictures; foreach (var pictureId in pictureIds) { var mediaFile = nopImportContext.FindNew<MediaFile>(pictureId); if (mediaFile != null) { mediaFile.MediaCategory = product.Gallery; session.Update(mediaFile); } } } }); return string.Format("{0} products processed.", productDatas.Count); }
private static void CreateStandardProductVariant(NopImportContext nopImportContext, ProductVariantData variantData, Product product) { var variant = new ProductVariant { Name = variantData.Name, SKU = variantData.SKU, Weight = variantData.Weight, TrackingPolicy = variantData.TrackingPolicy, StockRemaining = variantData.StockRemaining, RequiresShipping = variantData.RequiresShipping, AllowedNumberOfDaysForDownload = variantData.DownloadDays, AllowedNumberOfDownloads = variantData.MaxDownloads, IsDownloadable = variantData.Download, BasePrice = variantData.BasePrice, DownloadFileUrl = variantData.DownloadUrl, GiftCardType = variantData.GiftCardType, IsGiftCard = variantData.GiftCard, Product = product, PreviousPrice = variantData.PreviousPrice, ManufacturerPartNumber = variantData.PartNumber, TaxRate = nopImportContext.FindNew <TaxRate>(variantData.TaxRate) }; product.Variants.Add(variant); nopImportContext.AddEntry(variantData.Id, variant); }
public string ProcessAddresses(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { var addressData = dataReader.GetAddressData(); _session.Transact(session => { foreach (var data in addressData) { var country = nopImportContext.FindNew<Country>(data.Country.GetValueOrDefault()); var address = new Address { Address1 = data.Address1, Address2 = data.Address2, City = data.City, Company = data.Company, CountryCode = country == null ? string.Empty : country.ISOTwoLetterCode, FirstName = data.FirstName, LastName = data.LastName, PhoneNumber = data.PhoneNumber, PostalCode = data.PostalCode, StateProvince = data.StateProvince, }; session.Save(address); nopImportContext.AddEntry(data.Id, address); } }); return string.Format("{0} addresses added", addressData.Count); }
public string ProcessAddresses(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { var addressData = dataReader.GetAddressData(); _session.Transact(session => { foreach (var data in addressData) { var country = nopImportContext.FindNew <Country>(data.Country.GetValueOrDefault()); var address = new Address { Address1 = data.Address1, Address2 = data.Address2, City = data.City, Company = data.Company, CountryCode = country == null ? string.Empty : country.ISOTwoLetterCode, FirstName = data.FirstName, LastName = data.LastName, PhoneNumber = data.PhoneNumber, PostalCode = data.PostalCode, StateProvince = data.StateProvince, }; session.Save(address); nopImportContext.AddEntry(data.Id, address); } }); return(string.Format("{0} addresses added", addressData.Count)); }
private void UpdateCategory(ISession session, CategoryData categoryData, Webpage parent, HashSet<CategoryData> allData, NopImportContext nopImportContext) { CategoryData data = categoryData; var suggestParams = new SuggestParams { DocumentType = typeof(Category).FullName, PageName = data.Name, UseHierarchy = true }; var category = new Category { Name = data.Name, UrlSegment = string.IsNullOrWhiteSpace(data.Url) ? _webpageUrlService.Suggest(parent, suggestParams) : data.Url, Parent = parent, CategoryAbstract = data.Abstract.LimitCharacters(500), PublishOn = data.Published ? CurrentRequestData.Now.Date : (DateTime?)null, RevealInNavigation = true }; var mediaFile = nopImportContext.FindNew<MediaFile>(data.PictureId); if (mediaFile != null) { category.FeatureImage = mediaFile.FileUrl; } session.Save(category); nopImportContext.AddEntry(data.Id, category); List<CategoryData> children = allData.Where(d => d.ParentId == data.Id).ToList(); foreach (CategoryData child in children) { UpdateCategory(session, child, category, allData, nopImportContext); } }
private static ProductVariant CreateCartesianProductVariant(NopImportContext nopImportContext, ProductVariantData variantData, Product product, IEnumerable <ProductOptionValueData> cartesianProduct, int index) { var variant = new ProductVariant { Name = variantData.Name, SKU = variantData.SKU + "-" + (index + 1), Weight = variantData.Weight, TrackingPolicy = variantData.TrackingPolicy, StockRemaining = variantData.StockRemaining, RequiresShipping = variantData.RequiresShipping, AllowedNumberOfDaysForDownload = variantData.DownloadDays, AllowedNumberOfDownloads = variantData.MaxDownloads, IsDownloadable = variantData.Download, BasePrice = variantData.BasePrice, DownloadFileUrl = variantData.DownloadUrl, GiftCardType = variantData.GiftCardType, IsGiftCard = variantData.GiftCard, Product = product, PreviousPrice = variantData.PreviousPrice, ManufacturerPartNumber = variantData.PartNumber, TaxRate = nopImportContext.FindNew <TaxRate>(variantData.TaxRate) }; foreach (ProductOptionValueData valueData in cartesianProduct) { variant.Weight += valueData.WeightAdjustment; variant.BasePrice += valueData.PriceAdjustment; var productOptionValue = new ProductOptionValue { ProductVariant = variant, Value = valueData.Value, ProductOption = nopImportContext.FindNew <ProductOption>(valueData.OptionId) }; variant.OptionValues.Add(productOptionValue); if (!product.Options.Contains(productOptionValue.ProductOption)) { product.Options.Add(productOptionValue.ProductOption); } nopImportContext.AddEntry(valueData.Id, productOptionValue); } product.Variants.Add(variant); nopImportContext.AddEntry(variantData.Id, variant); return(variant); }
private static void SetSpecificationValues(NopImportContext nopImportContext, HashSet <ProductSpecificationValueData> specificationValues, Product product) { foreach ( ProductSpecificationValueData valueData in specificationValues) { var specificationValue = new ProductSpecificationValue { ProductSpecificationAttributeOption = nopImportContext.FindNew <ProductSpecificationAttributeOption>(valueData.OptionId), Product = product, DisplayOrder = valueData.DisplayOrder }; product.SpecificationValues.Add(specificationValue); nopImportContext.AddEntry(valueData.Id, specificationValue); } }
private static IEnumerable <ProductSpecificationValue> SetSpecificationValues(NopImportContext nopImportContext, HashSet <ProductSpecificationValueData> specificationValues, Product product, Site site) { foreach ( ProductSpecificationValueData valueData in specificationValues) { var specificationValue = new ProductSpecificationValue { ProductSpecificationAttributeOption = nopImportContext.FindNew <ProductSpecificationAttributeOption>(valueData.OptionId), Product = product, DisplayOrder = valueData.DisplayOrder }; specificationValue.AssignBaseProperties(site); nopImportContext.AddEntry(valueData.Id, specificationValue); yield return(specificationValue); } }
public string ProcessUsers(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { HashSet <UserData> userDatas = dataReader.GetUserData(); var guids = _session.QueryOver <User>().Select(x => x.Guid).List <Guid>(); _session.Transact(session => { foreach (UserData userData in userDatas) { var guid = userData.Guid; if (guids.Contains(guid)) { continue; } var user = new User { CurrentEncryption = userData.Format, PasswordHash = Encoding.Default.GetBytes(userData.Hash), PasswordSalt = Encoding.Default.GetBytes(userData.Salt), FirstName = userData.FirstName.LimitCharacters(255), LastName = userData.LastName.LimitCharacters(255), Email = userData.Email, IsActive = userData.Active, }; user.SetGuid(userData.Guid); user.AssignBaseProperties(); session.Insert(user); foreach (AddressData addressData in userData.AddressData) { var address = nopImportContext.FindNew <Address>(addressData.Id); if (address != null) { address.User = user; session.Update(address); } } } }); return(string.Format("{0} users imported.", userDatas.Count)); }
public string ProcessRegions(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { HashSet <RegionData> regionDatas = dataReader.GetRegionData(); _session.Transact(session => { foreach (RegionData regionData in regionDatas) { var region = new Region { Name = regionData.Name, Country = nopImportContext.FindNew <Country>(regionData.CountryId) }; session.Save(region); nopImportContext.AddEntry(regionData.Id, region); } }); return(string.Format("{0} regions processed", regionDatas.Count)); }
public string ProcessSpecificationAttributeOptions(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { var optionDatas = dataReader.GetProductSpecificationOptions(); _session.Transact(session => { foreach (ProductSpecificationAttributeOptionData optionData in optionDatas) { var option = new ProductSpecificationAttributeOption { Name = optionData.Name, ProductSpecificationAttribute = nopImportContext.FindNew <ProductSpecificationAttribute>(optionData.ProductSpecificationId) }; session.Save(option); nopImportContext.AddEntry(optionData.Id, option); } }); return(string.Format("{0} product specification attribute options processed", optionDatas.Count)); }
public string ProcessSpecificationAttributeOptions(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { var optionDatas = dataReader.GetProductSpecificationOptions(); _session.Transact(session => { foreach (ProductSpecificationAttributeOptionData optionData in optionDatas) { var option = new ProductSpecificationAttributeOption { Name = optionData.Name, ProductSpecificationAttribute = nopImportContext.FindNew<ProductSpecificationAttribute>(optionData.ProductSpecificationId) }; session.Save(option); nopImportContext.AddEntry(optionData.Id, option); } }); return string.Format("{0} product specification attribute options processed", optionDatas.Count); }
public string ProcessRegions(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { HashSet<RegionData> regionDatas = dataReader.GetRegionData(); _session.Transact(session => { foreach (RegionData regionData in regionDatas) { var region = new Region { Name = regionData.Name, Country = nopImportContext.FindNew<Country>(regionData.CountryId) }; session.Save(region); nopImportContext.AddEntry(regionData.Id, region); } }); return string.Format("{0} regions processed", regionDatas.Count); }
private static ProductVariant CreateStandardProductVariant(NopImportContext nopImportContext, ProductVariantData variantData, Product product) { var variant = new ProductVariant { Name = variantData.Name, SKU = variantData.SKU, Weight = variantData.Weight, TrackingPolicy = variantData.TrackingPolicy, StockRemaining = variantData.StockRemaining, RequiresShipping = variantData.RequiresShipping, AllowedNumberOfDaysForDownload = variantData.DownloadDays, AllowedNumberOfDownloads = variantData.MaxDownloads, IsDownloadable = variantData.Download, BasePrice = variantData.BasePrice, DownloadFileUrl = variantData.DownloadUrl, GiftCardType = variantData.GiftCardType, IsGiftCard = variantData.GiftCard, Product = product, PreviousPrice = variantData.PreviousPrice, ManufacturerPartNumber = variantData.PartNumber, TaxRate = nopImportContext.FindNew <TaxRate>(variantData.TaxRate), PriceBreaks = variantData.PriceBreaks.Select(price => new PriceBreak { Price = price.Price, Quantity = price.Quantity }).ToList() }; if (variantData.PriceBreaks.Count > 0) { product.Variants.Add(variant); } else { product.Variants.Add(variant); } nopImportContext.AddEntry(variantData.Id, variant); return(variant); }
public string ProcessUsers(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { HashSet<UserData> userDatas = dataReader.GetUserData(); _session.Transact(session => { foreach (UserData userData in userDatas) { var guid = userData.Guid; if (session.QueryOver<User>().Where(u => u.Guid == guid).Any()) continue; var user = new User { CurrentEncryption = userData.Format, PasswordHash = Encoding.Default.GetBytes(userData.Hash), PasswordSalt = Encoding.Default.GetBytes(userData.Salt), FirstName = userData.FirstName.LimitCharacters(255), LastName = userData.LastName.LimitCharacters(255), Email = userData.Email, IsActive = userData.Active, }; user.SetGuid(userData.Guid); session.Save(user); foreach (AddressData addressData in userData.AddressData) { var address = nopImportContext.FindNew<Address>(addressData.Id); if (address != null) { address.User = user; session.Update(address); } } } }); return string.Format("{0} users imported.", userDatas.Count); }
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)); }
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); }
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)); }
private static void SetSpecificationValues(NopImportContext nopImportContext, HashSet<ProductSpecificationValueData> specificationValues, Product product) { foreach ( ProductSpecificationValueData valueData in specificationValues) { var specificationValue = new ProductSpecificationValue { ProductSpecificationAttributeOption = nopImportContext.FindNew<ProductSpecificationAttributeOption>(valueData.OptionId), Product = product, DisplayOrder = valueData.DisplayOrder }; product.SpecificationValues.Add(specificationValue); nopImportContext.AddEntry(valueData.Id, specificationValue); } }