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,16 +33,24 @@ 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
*
38
41
* @var array
39
42
*/
40
43
protected $ _messageTemplates = [
41
- self ::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER => 'Attribute with code "%s" is not super ' ,
42
- self ::ERROR_INVALID_OPTION_VALUE => 'Invalid option value for attribute "%s" ' ,
43
- self ::ERROR_INVALID_WEBSITE => 'Invalid website code for super attribute ' ,
44
- self ::ERROR_DUPLICATED_VARIATIONS => 'SKU %s contains duplicated variations ' ,
44
+ self ::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER =>
45
+ 'Attribute with code "%s" is not super ' ,
46
+ self ::ERROR_INVALID_OPTION_VALUE =>
47
+ 'Invalid option value for attribute "%s" ' ,
48
+ self ::ERROR_INVALID_WEBSITE =>
49
+ 'Invalid website code for super attribute ' ,
50
+ self ::ERROR_DUPLICATED_VARIATIONS =>
51
+ 'SKU %s contains duplicated variations ' ,
52
+ self ::ERROR_UNIDENTIFIABLE_VARIATION =>
53
+ 'Configurable variation "%s" is unidentifiable ' ,
45
54
];
46
55
47
56
/**
@@ -470,13 +479,14 @@ protected function _processSuperData()
470
479
* @param array $rowData
471
480
*
472
481
* @return array
482
+ * @throws LocalizedException
473
483
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
474
484
* @SuppressWarnings(PHPMD.NPathComplexity)
475
485
*/
476
486
protected function _parseVariations ($ rowData )
477
487
{
478
488
$ additionalRows = [];
479
- if (! isset ($ rowData ['configurable_variations ' ])) {
489
+ if (empty ($ rowData ['configurable_variations ' ])) {
480
490
return $ additionalRows ;
481
491
}
482
492
$ variations = explode (ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR , $ rowData ['configurable_variations ' ]);
@@ -489,7 +499,8 @@ protected function _parseVariations($rowData)
489
499
$ nameAndValue = explode (ImportProduct::PAIR_NAME_VALUE_SEPARATOR , $ nameAndValue );
490
500
if (!empty ($ nameAndValue )) {
491
501
$ value = isset ($ nameAndValue [1 ]) ? trim ($ nameAndValue [1 ]) : '' ;
492
- $ fieldName = trim ($ nameAndValue [0 ]);
502
+ // Ignoring field names' case.
503
+ $ fieldName = strtolower (trim ($ nameAndValue [0 ]));
493
504
if ($ fieldName ) {
494
505
$ fieldAndValuePairs [$ fieldName ] = $ value ;
495
506
}
@@ -510,8 +521,19 @@ protected function _parseVariations($rowData)
510
521
$ additionalRow = [];
511
522
$ position += 1 ;
512
523
}
524
+ } else {
525
+ $ errorCode = self ::ERROR_UNIDENTIFIABLE_VARIATION ;
526
+ throw new LocalizedException (
527
+ __ (
528
+ sprintf (
529
+ $ this ->_messageTemplates [$ errorCode ],
530
+ $ variation
531
+ )
532
+ )
533
+ );
513
534
}
514
535
}
536
+
515
537
return $ additionalRows ;
516
538
}
517
539
@@ -822,7 +844,14 @@ protected function configurableInBunch($bunch)
822
844
public function isRowValid (array $ rowData , $ rowNum , $ isNewProduct = true )
823
845
{
824
846
$ error = false ;
825
- $ dataWithExtraVirtualRows = $ this ->_parseVariations ($ rowData );
847
+ try {
848
+ $ dataWithExtraVirtualRows = $ this ->_parseVariations ($ rowData );
849
+ } catch (LocalizedException $ exception ) {
850
+ $ this ->_entityModel ->addRowError ($ exception ->getMessage (), $ rowNum );
851
+
852
+ return false ;
853
+ }
854
+
826
855
$ skus = [];
827
856
$ rowData ['price ' ] = isset ($ rowData ['price ' ]) && $ rowData ['price ' ] ? $ rowData ['price ' ] : '0.00 ' ;
828
857
if (!empty ($ dataWithExtraVirtualRows )) {
@@ -846,6 +875,7 @@ public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
846
875
}
847
876
$ error |= !parent ::isRowValid ($ option , $ rowNum , $ isNewProduct );
848
877
}
878
+
849
879
return !$ error ;
850
880
}
851
881
0 commit comments