@@ -745,7 +745,6 @@ public function __construct(
745
745
->_initTypeModels ()
746
746
->_initSkus ();
747
747
$ this ->validator ->init ($ this );
748
- $ this ->initMediaGalleryResources ();
749
748
}
750
749
751
750
/**
@@ -1292,15 +1291,19 @@ public function saveProductEntity(array $entityRowsIn, array $entityRowsUp)
1292
1291
*/
1293
1292
protected function initMediaGalleryResources ()
1294
1293
{
1295
- $ this ->productEntityTableName = $ this ->getResource ()->getTable ('catalog_product_entity ' );
1296
- $ this ->mediaGalleryTableName = $ this ->getResource ()->getTable ('catalog_product_entity_media_gallery ' );
1297
- $ this ->mediaGalleryValueTableName = $ this ->getResource ()->getTable ('catalog_product_entity_media_gallery_value ' );
1298
- $ this ->mediaGalleryEntityToValueTableName = $ this ->getResource ()->getTable (
1299
- 'catalog_product_entity_media_gallery_value_to_entity '
1300
- );
1301
- $ this ->productEntityLinkField = $ this ->metadataPool
1302
- ->getMetadata (\Magento \Catalog \Api \Data \ProductInterface::class)
1303
- ->getLinkField ();
1294
+ if (null == $ this ->mediaGalleryTableName ) {
1295
+ $ this ->productEntityTableName = $ this ->getResource ()->getTable ('catalog_product_entity ' );
1296
+ $ this ->mediaGalleryTableName = $ this ->getResource ()->getTable ('catalog_product_entity_media_gallery ' );
1297
+ $ this ->mediaGalleryValueTableName = $ this ->getResource ()->getTable (
1298
+ 'catalog_product_entity_media_gallery_value '
1299
+ );
1300
+ $ this ->mediaGalleryEntityToValueTableName = $ this ->getResource ()->getTable (
1301
+ 'catalog_product_entity_media_gallery_value_to_entity '
1302
+ );
1303
+ $ this ->productEntityLinkField = $ this ->metadataPool
1304
+ ->getMetadata (\Magento \Catalog \Api \Data \ProductInterface::class)
1305
+ ->getLinkField ();
1306
+ }
1304
1307
}
1305
1308
1306
1309
/**
@@ -1312,21 +1315,19 @@ protected function initMediaGalleryResources()
1312
1315
protected function getExistingImages ($ bunch )
1313
1316
{
1314
1317
$ result = [];
1315
- $ productSKUs = array_map ('strval ' , array_column ($ bunch , self ::COL_SKU ));
1316
- if (!$ productSKUs ) {
1318
+ if ($ this ->getErrorAggregator ()->hasToBeTerminated ()) {
1317
1319
return $ result ;
1318
1320
}
1319
1321
1320
- $ linkField = $ this ->metadataPool
1321
- ->getMetadata (\Magento \Catalog \Api \Data \ProductInterface::class)
1322
- ->getLinkField ();
1322
+ $ this ->initMediaGalleryResources ();
1323
+ $ productSKUs = array_map ('strval ' , array_column ($ bunch , self ::COL_SKU ));
1323
1324
$ select = $ this ->_connection ->select ()->from (
1324
1325
['mg ' => $ this ->mediaGalleryTableName ],
1325
1326
['value ' => 'mg.value ' ]
1326
1327
)->joinInner (
1327
1328
['mgvte ' => $ this ->mediaGalleryEntityToValueTableName ],
1328
1329
'(mg.value_id = mgvte.value_id) ' ,
1329
- [$ linkField => 'mgvte. ' . $ linkField ]
1330
+ [$ this -> productEntityLinkField => 'mgvte. ' . $ this -> productEntityLinkField ]
1330
1331
)->joinInner (
1331
1332
['pe ' => $ this ->productEntityTableName ],
1332
1333
"(mgvte. {$ this ->productEntityLinkField } = pe. {$ this ->productEntityLinkField }) " ,
@@ -1814,6 +1815,7 @@ protected function _saveMediaGallery(array $mediaGalleryData)
1814
1815
if (empty ($ mediaGalleryData )) {
1815
1816
return $ this ;
1816
1817
}
1818
+ $ this ->initMediaGalleryResources ();
1817
1819
$ productIds = [];
1818
1820
$ imageNames = [];
1819
1821
$ multiInsertData = [];
0 commit comments