Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
 }
Ejemplo n.º 6
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);
 }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
        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);

        }
Ejemplo n.º 10
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);

        }
Ejemplo n.º 11
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);

        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
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);
        }