@@ -33,6 +33,7 @@ public class ProductImporter : EntityImporterBase, IEntityImporter
3333 private readonly ICategoryService _categoryService ;
3434 private readonly IProductService _productService ;
3535 private readonly IUrlRecordService _urlRecordService ;
36+ private readonly IProductTemplateService _productTemplateService ;
3637 private readonly IStoreMappingService _storeMappingService ;
3738 private readonly FileDownloadManager _fileDownloadManager ;
3839 private readonly SeoSettings _seoSettings ;
@@ -52,6 +53,7 @@ public ProductImporter(
5253 ICategoryService categoryService ,
5354 IProductService productService ,
5455 IUrlRecordService urlRecordService ,
56+ IProductTemplateService productTemplateService ,
5557 IStoreMappingService storeMappingService ,
5658 FileDownloadManager fileDownloadManager ,
5759 SeoSettings seoSettings ,
@@ -70,6 +72,7 @@ public ProductImporter(
7072 _categoryService = categoryService ;
7173 _productService = productService ;
7274 _urlRecordService = urlRecordService ;
75+ _productTemplateService = productTemplateService ;
7376 _storeMappingService = storeMappingService ;
7477 _fileDownloadManager = fileDownloadManager ;
7578
@@ -88,7 +91,7 @@ public ProductImporter(
8891 return ( int ? ) null ;
8992 }
9093
91- private int ProcessParentMappings ( IImportExecuteContext context ,
94+ private int ProcessProductMappings ( IImportExecuteContext context ,
9295 ImportRow < Product > [ ] batch ,
9396 Dictionary < int , ImportProductMapping > srcToDestId )
9497 {
@@ -527,12 +530,17 @@ private void ProcessStoreMappings(IImportExecuteContext context, ImportRow<Produ
527530 }
528531 }
529532
530- private int ProcessProducts ( IImportExecuteContext context , ImportRow < Product > [ ] batch , Dictionary < int , ImportProductMapping > srcToDestId )
533+ private int ProcessProducts (
534+ IImportExecuteContext context ,
535+ ImportRow < Product > [ ] batch ,
536+ Dictionary < string , int > templateViewPaths ,
537+ Dictionary < int , ImportProductMapping > srcToDestId )
531538 {
532539 _productRepository . AutoCommitEnabled = true ;
533540
534541 Product lastInserted = null ;
535542 Product lastUpdated = null ;
543+ var defaultTemplateId = templateViewPaths [ "ProductTemplate.Simple" ] ;
536544
537545 foreach ( var row in batch )
538546 {
@@ -579,7 +587,7 @@ private int ProcessProducts(IImportExecuteContext context, ImportRow<Product>[]
579587 context . Result . AddError ( "The 'Name' field is required for new products. Skipping row." , row . GetRowInfo ( ) , "Name" ) ;
580588 continue ;
581589 }
582-
590+
583591 product = new Product ( ) ;
584592 }
585593
@@ -596,34 +604,39 @@ private int ProcessProducts(IImportExecuteContext context, ImportRow<Product>[]
596604 }
597605 }
598606
599- row . SetProperty ( context . Result , product , ( x ) => x . Sku ) ;
600- row . SetProperty ( context . Result , product , ( x ) => x . Gtin ) ;
601- row . SetProperty ( context . Result , product , ( x ) => x . ManufacturerPartNumber ) ;
602607 row . SetProperty ( context . Result , product , ( x ) => x . ProductTypeId , ( int ) ProductType . SimpleProduct ) ;
603608 row . SetProperty ( context . Result , product , ( x ) => x . VisibleIndividually , true ) ;
604609 row . SetProperty ( context . Result , product , ( x ) => x . Name ) ;
605610 row . SetProperty ( context . Result , product , ( x ) => x . ShortDescription ) ;
606611 row . SetProperty ( context . Result , product , ( x ) => x . FullDescription ) ;
607- row . SetProperty ( context . Result , product , ( x ) => x . ProductTemplateId ) ;
612+ row . SetProperty ( context . Result , product , ( x ) => x . AdminComment ) ;
608613 row . SetProperty ( context . Result , product , ( x ) => x . ShowOnHomePage ) ;
609614 row . SetProperty ( context . Result , product , ( x ) => x . HomePageDisplayOrder ) ;
610615 row . SetProperty ( context . Result , product , ( x ) => x . MetaKeywords ) ;
611616 row . SetProperty ( context . Result , product , ( x ) => x . MetaDescription ) ;
612617 row . SetProperty ( context . Result , product , ( x ) => x . MetaTitle ) ;
613618 row . SetProperty ( context . Result , product , ( x ) => x . AllowCustomerReviews , true ) ;
619+ row . SetProperty ( context . Result , product , ( x ) => x . ApprovedRatingSum ) ;
620+ row . SetProperty ( context . Result , product , ( x ) => x . NotApprovedRatingSum ) ;
621+ row . SetProperty ( context . Result , product , ( x ) => x . ApprovedTotalReviews ) ;
622+ row . SetProperty ( context . Result , product , ( x ) => x . NotApprovedTotalReviews ) ;
614623 row . SetProperty ( context . Result , product , ( x ) => x . Published , true ) ;
624+ row . SetProperty ( context . Result , product , ( x ) => x . Sku ) ;
625+ row . SetProperty ( context . Result , product , ( x ) => x . ManufacturerPartNumber ) ;
626+ row . SetProperty ( context . Result , product , ( x ) => x . Gtin ) ;
615627 row . SetProperty ( context . Result , product , ( x ) => x . IsGiftCard ) ;
616628 row . SetProperty ( context . Result , product , ( x ) => x . GiftCardTypeId ) ;
617629 row . SetProperty ( context . Result , product , ( x ) => x . RequireOtherProducts ) ;
618- row . SetProperty ( context . Result , product , ( x ) => x . RequiredProductIds ) ;
630+ row . SetProperty ( context . Result , product , ( x ) => x . RequiredProductIds ) ; // TODO: global scope
619631 row . SetProperty ( context . Result , product , ( x ) => x . AutomaticallyAddRequiredProducts ) ;
620632 row . SetProperty ( context . Result , product , ( x ) => x . IsDownload ) ;
621633 row . SetProperty ( context . Result , product , ( x ) => x . DownloadId ) ;
622634 row . SetProperty ( context . Result , product , ( x ) => x . UnlimitedDownloads , true ) ;
623635 row . SetProperty ( context . Result , product , ( x ) => x . MaxNumberOfDownloads , 10 ) ;
636+ row . SetProperty ( context . Result , product , ( x ) => x . DownloadExpirationDays ) ;
624637 row . SetProperty ( context . Result , product , ( x ) => x . DownloadActivationTypeId , 1 ) ;
625638 row . SetProperty ( context . Result , product , ( x ) => x . HasSampleDownload ) ;
626- row . SetProperty ( context . Result , product , ( x ) => x . SampleDownloadId , ( int ? ) null , ZeroToNull ) ;
639+ row . SetProperty ( context . Result , product , ( x ) => x . SampleDownloadId , ( int ? ) null , ZeroToNull ) ; // TODO: global scope
627640 row . SetProperty ( context . Result , product , ( x ) => x . HasUserAgreement ) ;
628641 row . SetProperty ( context . Result , product , ( x ) => x . UserAgreementText ) ;
629642 row . SetProperty ( context . Result , product , ( x ) => x . IsRecurring ) ;
@@ -635,7 +648,7 @@ private int ProcessProducts(IImportExecuteContext context, ImportRow<Product>[]
635648 row . SetProperty ( context . Result , product , ( x ) => x . AdditionalShippingCharge ) ;
636649 row . SetProperty ( context . Result , product , ( x ) => x . IsEsd ) ;
637650 row . SetProperty ( context . Result , product , ( x ) => x . IsTaxExempt ) ;
638- row . SetProperty ( context . Result , product , ( x ) => x . TaxCategoryId , 1 ) ;
651+ row . SetProperty ( context . Result , product , ( x ) => x . TaxCategoryId , 1 ) ; // TODO: global scope
639652 row . SetProperty ( context . Result , product , ( x ) => x . ManageInventoryMethodId ) ;
640653 row . SetProperty ( context . Result , product , ( x ) => x . StockQuantity , 10000 ) ;
641654 row . SetProperty ( context . Result , product , ( x ) => x . DisplayStockAvailability ) ;
@@ -661,24 +674,30 @@ private int ProcessProducts(IImportExecuteContext context, ImportRow<Product>[]
661674 row . SetProperty ( context . Result , product , ( x ) => x . CustomerEntersPrice ) ;
662675 row . SetProperty ( context . Result , product , ( x ) => x . MinimumCustomerEnteredPrice ) ;
663676 row . SetProperty ( context . Result , product , ( x ) => x . MaximumCustomerEnteredPrice , 1000 ) ;
677+ // HasTierPrices... ignore as long as no tier prices are imported
678+ // LowestAttributeCombinationPrice... ignore as long as no combinations are imported
664679 row . SetProperty ( context . Result , product , ( x ) => x . Weight ) ;
665680 row . SetProperty ( context . Result , product , ( x ) => x . Length ) ;
666681 row . SetProperty ( context . Result , product , ( x ) => x . Width ) ;
667682 row . SetProperty ( context . Result , product , ( x ) => x . Height ) ;
668- row . SetProperty ( context . Result , product , ( x ) => x . DeliveryTimeId ) ;
669- row . SetProperty ( context . Result , product , ( x ) => x . QuantityUnitId ) ;
683+ row . SetProperty ( context . Result , product , ( x ) => x . DisplayOrder ) ;
684+ row . SetProperty ( context . Result , product , ( x ) => x . DeliveryTimeId ) ; // TODO: global scope
685+ row . SetProperty ( context . Result , product , ( x ) => x . QuantityUnitId ) ; // TODO: global scope
670686 row . SetProperty ( context . Result , product , ( x ) => x . BasePriceEnabled ) ;
671687 row . SetProperty ( context . Result , product , ( x ) => x . BasePriceMeasureUnit ) ;
672688 row . SetProperty ( context . Result , product , ( x ) => x . BasePriceAmount ) ;
673689 row . SetProperty ( context . Result , product , ( x ) => x . BasePriceBaseAmount ) ;
674- row . SetProperty ( context . Result , product , ( x ) => x . BundlePerItemPricing ) ;
690+ row . SetProperty ( context . Result , product , ( x ) => x . BundleTitleText ) ;
675691 row . SetProperty ( context . Result , product , ( x ) => x . BundlePerItemShipping ) ;
692+ row . SetProperty ( context . Result , product , ( x ) => x . BundlePerItemPricing ) ;
676693 row . SetProperty ( context . Result , product , ( x ) => x . BundlePerItemShoppingCart ) ;
677- row . SetProperty ( context . Result , product , ( x ) => x . BundleTitleText ) ;
678694 row . SetProperty ( context . Result , product , ( x ) => x . AvailableStartDateTimeUtc ) ;
679695 row . SetProperty ( context . Result , product , ( x ) => x . AvailableEndDateTimeUtc ) ;
680696 row . SetProperty ( context . Result , product , ( x ) => x . LimitedToStores ) ;
681697
698+ var tvp = row . GetDataValue < string > ( "ProductTemplateViewPath" ) ;
699+ product . ProductTemplateId = ( tvp . HasValue ( ) && templateViewPaths . ContainsKey ( tvp ) ? templateViewPaths [ tvp ] : defaultTemplateId ) ;
700+
682701 row . SetProperty ( context . Result , product , ( x ) => x . CreatedOnUtc , UtcNow ) ;
683702 product . UpdatedOnUtc = UtcNow ;
684703
@@ -745,6 +764,10 @@ public void Execute(IImportExecuteContext context)
745764 {
746765 var srcToDestId = new Dictionary < int , ImportProductMapping > ( ) ;
747766
767+ var templateViewPaths = _productTemplateService . GetAllProductTemplates ( )
768+ . GroupBy ( x => x . ViewPath , StringComparer . OrdinalIgnoreCase )
769+ . ToDictionary ( x => x . Key , x => x . First ( ) . Id ) ;
770+
748771 using ( var scope = new DbContextScope ( ctx : _productRepository . Context , autoDetectChanges : false , proxyCreation : false , validateOnSave : false ) )
749772 {
750773 var segmenter = context . GetSegmenter < Product > ( ) ;
@@ -767,7 +790,7 @@ public void Execute(IImportExecuteContext context)
767790 // ===========================================================================
768791 try
769792 {
770- ProcessProducts ( context , batch , srcToDestId ) ;
793+ ProcessProducts ( context , batch , templateViewPaths , srcToDestId ) ;
771794 }
772795 catch ( Exception exception )
773796 {
@@ -894,7 +917,7 @@ public void Execute(IImportExecuteContext context)
894917
895918 try
896919 {
897- ProcessParentMappings ( context , batch , srcToDestId ) ;
920+ ProcessProductMappings ( context , batch , srcToDestId ) ;
898921 }
899922 catch ( Exception exception )
900923 {
0 commit comments