@@ -3127,4 +3127,73 @@ public function testCheckDoubleImportOfProducts()
3127
3127
$ productsAfterSecondImport = $ this ->productRepository ->getList ($ searchCriteria )->getItems ();
3128
3128
$ this ->assertCount (3 , $ productsAfterSecondImport );
3129
3129
}
3130
+
3131
+ /**
3132
+ * Checks that product related links added for all bunches properly after products import
3133
+ */
3134
+ public function testImportProductsWithLinksInDifferentBunches ()
3135
+ {
3136
+ $ this ->importedProducts = [
3137
+ 'simple1 ' ,
3138
+ 'simple2 ' ,
3139
+ 'simple3 ' ,
3140
+ 'simple4 ' ,
3141
+ 'simple5 ' ,
3142
+ 'simple6 ' ,
3143
+ ];
3144
+ $ importExportData = $ this ->getMockBuilder (Data::class)
3145
+ ->disableOriginalConstructor ()
3146
+ ->getMock ();
3147
+ $ importExportData ->expects ($ this ->atLeastOnce ())
3148
+ ->method ('getBunchSize ' )
3149
+ ->willReturn (5 );
3150
+ $ this ->_model = $ this ->objectManager ->create (
3151
+ \Magento \CatalogImportExport \Model \Import \Product::class,
3152
+ ['importExportData ' => $ importExportData ]
3153
+ );
3154
+ $ linksData = [
3155
+ 'related ' => [
3156
+ 'simple1 ' => '2 ' ,
3157
+ 'simple2 ' => '1 '
3158
+ ]
3159
+ ];
3160
+ $ pathToFile = __DIR__ . '/_files/products_to_import_with_related.csv ' ;
3161
+ $ filesystem = $ this ->objectManager ->create (Filesystem::class);
3162
+
3163
+ $ directory = $ filesystem ->getDirectoryWrite (DirectoryList::ROOT );
3164
+ $ source = $ this ->objectManager ->create (
3165
+ Csv::class,
3166
+ [
3167
+ 'file ' => $ pathToFile ,
3168
+ 'directory ' => $ directory
3169
+ ]
3170
+ );
3171
+ $ errors = $ this ->_model ->setSource ($ source )
3172
+ ->setParameters (
3173
+ [
3174
+ 'behavior ' => Import::BEHAVIOR_APPEND ,
3175
+ 'entity ' => 'catalog_product '
3176
+ ]
3177
+ )
3178
+ ->validateData ();
3179
+
3180
+ $ this ->assertTrue ($ errors ->getErrorsCount () == 0 );
3181
+ $ this ->_model ->importData ();
3182
+
3183
+ $ resource = $ this ->objectManager ->get (ProductResource::class);
3184
+ $ productId = $ resource ->getIdBySku ('simple6 ' );
3185
+ /** @var Product $product */
3186
+ $ product = $ this ->objectManager ->create (Product::class);
3187
+ $ product ->load ($ productId );
3188
+ $ productLinks = [
3189
+ 'related ' => $ product ->getRelatedProducts ()
3190
+ ];
3191
+ $ importedProductLinks = [];
3192
+ foreach ($ productLinks as $ linkType => $ linkedProducts ) {
3193
+ foreach ($ linkedProducts as $ linkedProductData ) {
3194
+ $ importedProductLinks [$ linkType ][$ linkedProductData ->getSku ()] = $ linkedProductData ->getPosition ();
3195
+ }
3196
+ }
3197
+ $ this ->assertEquals ($ linksData , $ importedProductLinks );
3198
+ }
3130
3199
}
0 commit comments