Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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));
        }
Esempio n. 7
0
        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));
        }
Esempio n. 8
0
 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);
     }
 }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
 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);
     }
 }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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));
        }
Esempio n. 13
0
        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));
        }
Esempio n. 14
0
 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);
     }
 }
Esempio n. 15
0
 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);
 }
Esempio n. 16
0
 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);
 }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
        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);
        }
Esempio n. 19
0
        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));
        }
Esempio n. 20
0
        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));
        }
Esempio n. 21
0
        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));
        }
Esempio n. 22
0
        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);

        }
Esempio n. 24
0
        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));
        }
Esempio n. 25
0
        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));
        }
Esempio n. 26
0
        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);

        }
Esempio n. 27
0
        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);

        }
Esempio n. 28
0
        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);
        }
Esempio n. 29
0
        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));
        }
Esempio n. 30
0
        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));
        }
Esempio n. 31
0
        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));
        }
Esempio n. 32
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));
        }
Esempio n. 33
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);
        }
Esempio n. 34
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));
        }
Esempio n. 35
0
 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);
     }
 }