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 ProcessTags(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { HashSet <TagData> tagDatas = dataReader.GetTags(); var site = _session.Get <Site>(_site.Id); Dictionary <string, Tag> tags = _session.QueryOver <Tag>() .List().ToDictionary(x => x.Name); _session.Transact(session => { foreach (TagData tagData in tagDatas) { string name = tagData.Name.Trim(); Tag tag; if (!tags.ContainsKey(name)) { tag = new Tag { Name = name }; tag.AssignBaseProperties(site); session.Insert(tag); } else { tag = tags[name]; } nopImportContext.AddEntry(tagData.Id, tag); } }); return(string.Format("{0} tags processed", tagDatas.Count)); }
public string ImportPictures(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { var pictureData = dataReader.GetPictureData(); var mediaCategory = _documentService.GetDocumentByUrl <MediaCategory>(NopProductImages); if (mediaCategory == null) { mediaCategory = new MediaCategory { Name = "Nop Product Images", UrlSegment = NopProductImages, IsGallery = false, HideInAdminNav = false }; _documentService.AddDocument(mediaCategory); } foreach (var data in pictureData) { using (var fileData = data.GetData()) { var memoryStream = new MemoryStream(); fileData.CopyTo(memoryStream); memoryStream.Position = 0; var mediaFile = _fileService.AddFile(memoryStream, data.FileName, data.ContentType, memoryStream.Length, mediaCategory); nopImportContext.AddEntry(data.Id, mediaFile); } } return(string.Format("{0} pictures imported", pictureData.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); }
public string ImportPictures(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { var pictureData = dataReader.GetPictureData(); var mediaCategory = _documentService.GetDocumentByUrl<MediaCategory>(NopProductImages); if (mediaCategory == null) { mediaCategory = new MediaCategory { Name = "Nop Product Images", UrlSegment = NopProductImages, IsGallery = false, HideInAdminNav = false }; _documentService.AddDocument(mediaCategory); } foreach (var data in pictureData) { using (var fileData = data.GetData()) { var memoryStream = new MemoryStream(); fileData.CopyTo(memoryStream); memoryStream.Position = 0; var mediaFile = _fileService.AddFile(memoryStream, data.FileName, data.ContentType, memoryStream.Length, mediaCategory); nopImportContext.AddEntry(data.Id, mediaFile); } } return string.Format("{0} pictures imported", pictureData.Count); }
public ImportResult Execute(NopCommerceDataReader dataReader) { using (new NotificationDisabler()) { var nopImportContext = new NopImportContext(); var messages = new List<string> { _importPictureData.ImportPictures(dataReader,nopImportContext), _importCountryData.ProcessCountries(dataReader, nopImportContext), _importRegionData.ProcessRegions(dataReader, nopImportContext), _importAddresses.ProcessAddresses(dataReader, nopImportContext), _importUsers.ProcessUsers(dataReader, nopImportContext), _importTaxRates.ProcessTaxRates(dataReader, nopImportContext), _importBrands.ProcessBrands(dataReader, nopImportContext), _importSpecifications.ProcessSpecifications(dataReader, nopImportContext), _importSpecificationAttributeOptions.ProcessSpecificationAttributeOptions(dataReader, nopImportContext), _importOptions.ProcessOptions(dataReader, nopImportContext), _importTags.ProcessTags(dataReader, nopImportContext), _importCategories.ProcessCategories(dataReader, nopImportContext), _importProducts.ProcessProducts(dataReader, nopImportContext), _importOrders.ProcessOrders(dataReader,nopImportContext) }; _indexService.InitializeAllIndices(); return new ImportResult { Messages = messages, Success = true }; } }
public string ProcessAddresses(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { var addressData = dataReader.GetAddressData(); var site = _session.Get <Site>(_site.Id); _session.Transact(session => { foreach (var data in addressData) { var address = new Address { Address1 = data.Address1, Address2 = data.Address2, City = data.City, Company = data.Company, CountryCode = data.CountryCode, FirstName = data.FirstName, LastName = data.LastName, PhoneNumber = data.PhoneNumber, PostalCode = data.PostalCode, StateProvince = data.StateProvince, }; address.AssignBaseProperties(site); session.Insert(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); } }
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 CreateGroupedProductVariants(NopImportContext nopImportContext, HashSet <ProductOptionValueData> productOptionValueDatas, ProductVariantData variantData, Product product) { IEnumerable <IGrouping <int, ProductOptionValueData> > groups = productOptionValueDatas.GroupBy(data => data.OptionId); var cartesianProductList = CartesianProduct(groups).ToList(); for (int index = 0; index < cartesianProductList.Count; index++) { var cartesianProduct = cartesianProductList[index]; CreateCartesianProductVariant(nopImportContext, variantData, product, cartesianProduct, index); } }
public void CreateProductVariants(NopImportContext nopImportContext, HashSet <ProductVariantData> productVariants, HashSet <ProductOptionValueData> optionValues, Product product) { foreach (ProductVariantData variantData in productVariants) { HashSet <ProductOptionValueData> productOptionValueDatas = optionValues.Where(data => data.VariantId == variantData.Id).ToHashSet(); if (productOptionValueDatas.Any()) { CreateGroupedProductVariants(nopImportContext, productOptionValueDatas, variantData, product); } else { CreateStandardProductVariant(nopImportContext, variantData, product); } } }
public string ProcessCategories(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { var categoryDatas = dataReader.GetCategoryData(); IEnumerable<CategoryData> parentCategories = categoryDatas.Where(data => !data.ParentId.HasValue); var productSearch = _uniquePageService.GetUniquePage<ProductSearch>(); _session.Transact(session => { foreach (CategoryData categoryData in parentCategories) { UpdateCategory(session, categoryData, productSearch, categoryDatas, nopImportContext); } }); return string.Format("{0} categories processed.", categoryDatas.Count); }
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); } }
public string ProcessOptions(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { var productOptionDatas = dataReader.GetProductOptions(); _session.Transact(session => { foreach (ProductOptionData productOptionData in productOptionDatas) { var productOption = new ProductOption { Name = productOptionData.Name }; session.Save(productOption); nopImportContext.AddEntry(productOptionData.Id, productOption); } }); return(string.Format("{0} product options processed", productOptionDatas.Count)); }
public string ProcessOptions(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { var productOptionDatas = dataReader.GetProductOptions(); _session.Transact(session => { foreach (ProductOptionData productOptionData in productOptionDatas) { var productOption = new ProductOption { Name = productOptionData.Name }; session.Save(productOption); nopImportContext.AddEntry(productOptionData.Id, productOption); } }); return string.Format("{0} product options processed", productOptionDatas.Count); }
public string ProcessSpecifications(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { var productSpecificationDatas = dataReader.GetProductSpecifications(); _session.Transact(session => { foreach (ProductSpecificationData productSpecificationData in productSpecificationDatas) { var specificationAttribute = new ProductSpecificationAttribute { Name = productSpecificationData.Name, }; session.Save(specificationAttribute); nopImportContext.AddEntry(productSpecificationData.Id, specificationAttribute); } }); return(string.Format("{0} product specifications processed", productSpecificationDatas.Count)); }
public string ProcessBrands(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { var brandDatas = dataReader.GetBrands(); foreach (BrandData brandData in brandDatas) { string name = brandData.Name.Trim(); Brand brand = _session.QueryOver<Brand>() .Where(b => b.Name.IsInsensitiveLike(name, MatchMode.Exact)) .List().FirstOrDefault(); if (brand == null) { brand = _getNewBrandPage.Get(name); _session.Transact(session => session.Save(brand)); } nopImportContext.AddEntry(brandData.Id, brand); } return string.Format("{0} brands processed", brandDatas.Count); }
public IEnumerable <ProductVariant> CreateProductVariants(NopImportContext nopImportContext, HashSet <ProductVariantData> productVariants, HashSet <ProductOptionValueData> optionValues, Product product) { foreach (ProductVariantData variantData in productVariants) { HashSet <ProductOptionValueData> productOptionValueDatas = optionValues.Where(data => data.VariantId == variantData.Id).ToHashSet(); if (productOptionValueDatas.Any()) { foreach (var variant in CreateGroupedProductVariants(nopImportContext, productOptionValueDatas, variantData, product)) { yield return(variant); } } else { yield return(CreateStandardProductVariant(nopImportContext, variantData, product)); } } }
public string ProcessSpecifications(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { var productSpecificationDatas = dataReader.GetProductSpecifications(); _session.Transact(session => { foreach (ProductSpecificationData productSpecificationData in productSpecificationDatas) { var specificationAttribute = new ProductSpecificationAttribute { Name = productSpecificationData.Name, }; session.Save(specificationAttribute); nopImportContext.AddEntry(productSpecificationData.Id, specificationAttribute); } }); return string.Format("{0} product specifications processed", productSpecificationDatas.Count); }
public string ProcessTags(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { HashSet<TagData> tagDatas = dataReader.GetTags(); foreach (TagData tagData in tagDatas) { string name = tagData.Name.Trim(); Tag tag = _session.QueryOver<Tag>() .Where(b => b.Name.IsInsensitiveLike(name, MatchMode.Exact)) .List().FirstOrDefault(); if (tag == null) { tag = new Tag { Name = name }; _session.Transact(session => session.Save(tag)); } nopImportContext.AddEntry(tagData.Id, tag); } return string.Format("{0} tags processed", tagDatas.Count); }
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 ProcessCountries(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { var countryDatas = dataReader.GetCountryData(); _session.Transact(session => { foreach (CountryData countryData in countryDatas) { var country = new Country { Name = countryData.Name, ISOTwoLetterCode = countryData.IsoCode }; session.Save(country); nopImportContext.AddEntry(countryData.Id, country); } }); return string.Format("{0} countries processed", countryDatas.Count); }
public string ProcessTaxRates(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { HashSet <TaxData> taxDatas = dataReader.GetTaxData(); _session.Transact(session => { foreach (TaxData taxData in taxDatas) { var taxRate = new TaxRate { Name = taxData.Name, Percentage = taxData.Rate, }; session.Save(taxRate); nopImportContext.AddEntry(taxData.Id, taxRate); } }); return(string.Format("{0} tax rates processed", taxDatas.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 ProcessBrands(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { var brandDatas = dataReader.GetBrands(); foreach (BrandData brandData in brandDatas) { string name = brandData.Name.Trim(); Brand brand = _session.QueryOver <Brand>() .Where(b => b.Name.IsInsensitiveLike(name, MatchMode.Exact)) .List().FirstOrDefault(); if (brand == null) { brand = _getNewBrandPage.Get(name); _session.Transact(session => session.Save(brand)); } nopImportContext.AddEntry(brandData.Id, brand); } return(string.Format("{0} brands processed", brandDatas.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 ProcessTaxRates(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { HashSet<TaxData> taxDatas = dataReader.GetTaxData(); _session.Transact(session => { foreach (TaxData taxData in taxDatas) { var taxRate = new TaxRate { Name = taxData.Name, Percentage = taxData.Rate, }; session.Save(taxRate); nopImportContext.AddEntry(taxData.Id, taxRate); } }); return string.Format("{0} tax rates processed", taxDatas.Count); }
public string ProcessOptions(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { var productOptionDatas = dataReader.GetProductOptions(); var site = _session.Get <Site>(_site.Id); _session.Transact(session => { foreach (ProductOptionData productOptionData in productOptionDatas) { var productOption = new ProductOption { Name = productOptionData.Name }; productOption.AssignBaseProperties(site); session.Insert(productOption); nopImportContext.AddEntry(productOptionData.Id, productOption); } }); return(string.Format("{0} product options processed", productOptionDatas.Count)); }
public string ProcessCountries(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { var countryDatas = dataReader.GetCountryData(); _session.Transact(session => { foreach (CountryData countryData in countryDatas) { var country = new Country { Name = countryData.Name, ISOTwoLetterCode = countryData.IsoCode }; session.Save(country); nopImportContext.AddEntry(countryData.Id, country); } }); return(string.Format("{0} countries processed", countryDatas.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 ProcessTags(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { HashSet <TagData> tagDatas = dataReader.GetTags(); foreach (TagData tagData in tagDatas) { string name = tagData.Name.Trim(); Tag tag = _session.QueryOver <Tag>() .Where(b => b.Name.IsInsensitiveLike(name, MatchMode.Exact)) .List().FirstOrDefault(); if (tag == null) { tag = new Tag { Name = name }; _session.Transact(session => session.Save(tag)); } nopImportContext.AddEntry(tagData.Id, tag); } return(string.Format("{0} tags processed", tagDatas.Count)); }
public string ProcessCountries(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { var countryDatas = dataReader.GetCountryData(); var site = _session.Get <Site>(_site.Id); _session.Transact(session => { foreach (CountryData countryData in countryDatas) { var country = new Country { Name = countryData.Name, ISOTwoLetterCode = countryData.IsoCode }; country.AssignBaseProperties(site); session.Insert(country); nopImportContext.AddEntry(countryData.Id, country); } }); return(string.Format("{0} countries processed", countryDatas.Count)); }
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 ProcessBrands(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { HashSet <BrandData> brandDatas = dataReader.GetBrands(); var brands = _session.QueryOver <Brand>().List().ToDictionary(x => x.Name); var site = _session.Get <Site>(_site.Id); foreach (BrandData brandData in brandDatas) { string name = brandData.Name.Trim(); Brand brand; if (!brands.ContainsKey(name)) { brand = _getNewBrandPage.Get(name); brand.AssignBaseProperties(site); _session.Transact(session => session.Insert(brand)); } else { brand = brands[name]; } nopImportContext.AddEntry(brandData.Id, brand); } return(string.Format("{0} brands processed", brandDatas.Count)); }
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 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); } }
public ImportResult UpdateOrdersAndUsers(NopCommerceDataReader dataReader) { using (new NotificationDisabler()) { var nopImportContext = new NopImportContext(); var messages = new List<string> { _importUsers.ProcessUsers(dataReader, nopImportContext), _importOrders.ProcessOrders(dataReader, nopImportContext) }; _indexService.InitializeAllIndices(); return new ImportResult { Messages = messages, Success = true }; } }
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 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)); }