11
11
use Magento \Catalog \Api \Data \ProductInterface ;
12
12
use Magento \CatalogImportExport \Model \Import \Product as ImportProduct ;
13
13
use Magento \Framework \EntityManager \MetadataPool ;
14
+ use Magento \Framework \Exception \LocalizedException ;
14
15
15
16
/**
16
17
* Importing configurable products
@@ -32,6 +33,8 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ
32
33
33
34
const ERROR_DUPLICATED_VARIATIONS = 'duplicatedVariations ' ;
34
35
36
+ const ERROR_UNIDENTIFIABLE_VARIATION = 'unidentifiableVariation ' ;
37
+
35
38
/**
36
39
* Validation failure message template definitions
37
40
*
@@ -42,6 +45,7 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ
42
45
self ::ERROR_INVALID_OPTION_VALUE => 'Invalid option value for attribute "%s" ' ,
43
46
self ::ERROR_INVALID_WEBSITE => 'Invalid website code for super attribute ' ,
44
47
self ::ERROR_DUPLICATED_VARIATIONS => 'SKU %s contains duplicated variations ' ,
48
+ self ::ERROR_UNIDENTIFIABLE_VARIATION => 'Configurable variation "%s" is unidentifiable ' ,
45
49
];
46
50
47
51
/**
@@ -469,13 +473,14 @@ protected function _processSuperData()
469
473
* @param array $rowData
470
474
*
471
475
* @return array
476
+ * @throws LocalizedException
472
477
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
473
478
* @SuppressWarnings(PHPMD.NPathComplexity)
474
479
*/
475
480
protected function _parseVariations ($ rowData )
476
481
{
477
482
$ additionalRows = [];
478
- if (! isset ($ rowData ['configurable_variations ' ])) {
483
+ if (empty ($ rowData ['configurable_variations ' ])) {
479
484
return $ additionalRows ;
480
485
}
481
486
$ variations = explode (ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR , $ rowData ['configurable_variations ' ]);
@@ -488,7 +493,8 @@ protected function _parseVariations($rowData)
488
493
$ nameAndValue = explode (ImportProduct::PAIR_NAME_VALUE_SEPARATOR , $ nameAndValue );
489
494
if (!empty ($ nameAndValue )) {
490
495
$ value = isset ($ nameAndValue [1 ]) ? trim ($ nameAndValue [1 ]) : '' ;
491
- $ fieldName = trim ($ nameAndValue [0 ]);
496
+ // Ignoring field names' case.
497
+ $ fieldName = strtolower (trim ($ nameAndValue [0 ]));
492
498
if ($ fieldName ) {
493
499
$ fieldAndValuePairs [$ fieldName ] = $ value ;
494
500
}
@@ -509,8 +515,18 @@ protected function _parseVariations($rowData)
509
515
$ additionalRow = [];
510
516
$ position += 1 ;
511
517
}
518
+ } else {
519
+ throw new LocalizedException (
520
+ __ (
521
+ sprintf (
522
+ $ this ->_messageTemplates [self ::ERROR_UNIDENTIFIABLE_VARIATION ],
523
+ $ variation
524
+ )
525
+ )
526
+ );
512
527
}
513
528
}
529
+
514
530
return $ additionalRows ;
515
531
}
516
532
@@ -821,7 +837,14 @@ protected function configurableInBunch($bunch)
821
837
public function isRowValid (array $ rowData , $ rowNum , $ isNewProduct = true )
822
838
{
823
839
$ error = false ;
824
- $ dataWithExtraVirtualRows = $ this ->_parseVariations ($ rowData );
840
+ try {
841
+ $ dataWithExtraVirtualRows = $ this ->_parseVariations ($ rowData );
842
+ } catch (LocalizedException $ exception ) {
843
+ $ this ->_entityModel ->addRowError ($ exception ->getMessage (), $ rowNum );
844
+
845
+ return false ;
846
+ }
847
+
825
848
$ skus = [];
826
849
$ rowData ['price ' ] = isset ($ rowData ['price ' ]) && $ rowData ['price ' ] ? $ rowData ['price ' ] : '0.00 ' ;
827
850
if (!empty ($ dataWithExtraVirtualRows )) {
@@ -845,6 +868,7 @@ public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
845
868
}
846
869
$ error |= !parent ::isRowValid ($ option , $ rowNum , $ isNewProduct );
847
870
}
871
+
848
872
return !$ error ;
849
873
}
850
874
0 commit comments