1414using SmartStore . Utilities ;
1515using System . Text ;
1616using SmartStore . Core . Domain . Seo ;
17+ using SmartStore . Core . Domain . Media ;
1718
1819namespace SmartStore . Services . ExportImport
1920{
@@ -32,6 +33,7 @@ public partial class ImportManager : IImportManager
3233 private readonly IRepository < Product > _rsProduct ;
3334 private readonly IRepository < ProductCategory > _rsProductCategory ;
3435 private readonly IRepository < ProductManufacturer > _rsProductManufacturer ;
36+ private readonly IRepository < Picture > _rsPicture ;
3537 private readonly IRepository < ProductPicture > _rsProductPicture ;
3638 private readonly IRepository < UrlRecord > _rsUrlRecord ;
3739
@@ -46,6 +48,7 @@ public ImportManager(
4648 IRepository < Product > rsProduct ,
4749 IRepository < ProductCategory > rsProductCategory ,
4850 IRepository < ProductManufacturer > rsProductManufacturer ,
51+ IRepository < Picture > rsPicture ,
4952 IRepository < ProductPicture > rsProductPicture ,
5053 IRepository < UrlRecord > rsUrlRecord )
5154 {
@@ -61,6 +64,7 @@ public ImportManager(
6164 this . _rsProductManufacturer = rsProductManufacturer ;
6265 this . _rsProductPicture = rsProductPicture ;
6366 this . _rsUrlRecord = rsUrlRecord ;
67+ this . _rsPicture = rsPicture ;
6468 }
6569
6670 public virtual string CreateTextReport ( ImportResult result )
@@ -611,8 +615,8 @@ private void ProcessProductPictures(ICollection<ImportRow<Product>> batch, Impor
611615 if ( picture . IsEmpty ( ) || ! File . Exists ( picture ) )
612616 continue ;
613617
614- var currentPictures = _rsProductPicture . TableUntracked . Where ( x => x . ProductId == row . Entity . Id ) ;
615- var pictureBinary = FindEqualPicture ( picture , currentPictures ) ;
618+ var currentPictures = _rsProductPicture . Expand ( _rsProductPicture . TableUntracked , x => x . Picture ) . Where ( x => x . ProductId == row . Entity . Id ) . Select ( x => x . Picture ) . ToList ( ) ;
619+ var pictureBinary = FindEqualPicture ( picture , currentPictures ) ;
616620
617621 if ( pictureBinary != null && pictureBinary . Length > 0 )
618622 {
@@ -677,15 +681,15 @@ private void ProcessProductPictures(ICollection<ImportRow<Product>> batch, Impor
677681 /// <param name="path">The picture to find a duplicate for</param>
678682 /// <param name="productPictures">The sequence of product pictures to seek within for duplicates</param>
679683 /// <returns>The picture binary for <c>path</c> when no picture equals in the sequence, <c>null</c> otherwise.</returns>
680- private byte [ ] FindEqualPicture ( string path , IEnumerable < ProductPicture > productPictures )
684+ private byte [ ] FindEqualPicture ( string path , IEnumerable < Picture > productPictures )
681685 {
682686 try
683687 {
684688 var myBuffer = File . ReadAllBytes ( path ) ;
685689
686- foreach ( var pictureMap in productPictures . Where ( x => x . Id > 0 ) )
690+ foreach ( var picture in productPictures )
687691 {
688- var otherBuffer = _pictureService . LoadPictureBinary ( pictureMap . Picture ) ;
692+ var otherBuffer = _pictureService . LoadPictureBinary ( picture ) ;
689693 using ( var myStream = new MemoryStream ( myBuffer ) )
690694 {
691695 using ( var otherStream = new MemoryStream ( otherBuffer ) )
0 commit comments