@@ -226,6 +226,10 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity i
226
226
ValidatorInterface::ERROR_SUPER_PRODUCTS_SKU_NOT_FOUND => 'Product with specified super products SKU not found ' ,
227
227
ValidatorInterface::ERROR_MEDIA_DATA_INCOMPLETE => 'Media data is incomplete ' ,
228
228
ValidatorInterface::ERROR_INVALID_WEIGHT => 'Product weight is invalid ' ,
229
+ ValidatorInterface::ERROR_EXCEEDED_MAX_LENGTH => 'Attribute %s exceeded max length ' ,
230
+ ValidatorInterface::ERROR_INVALID_ATTRIBUTE_TYPE => 'Value for \'%s \' attribute contains incorrect value, acceptable values are in %s format ' ,
231
+ ValidatorInterface::ERROR_DUPLICATE_UNIQUE_ATTRIBUTE => 'Duplicated unique attribute ' ,
232
+ ValidatorInterface::ERROR_INVALID_ATTRIBUTE_OPTION => 'Value for \'%s \' attribute contains incorrect value, see acceptable values on settings specified for Admin ' ,
229
233
];
230
234
231
235
/**
@@ -236,8 +240,6 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity i
236
240
protected $ _fieldsMap = [
237
241
'image ' => 'base_image ' ,
238
242
'image_label ' => "base_image_label " ,
239
- 'image ' => 'base_image ' ,
240
- 'image_label ' => 'base_image_label ' ,
241
243
'thumbnail ' => 'thumbnail_image ' ,
242
244
'thumbnail_label ' => 'thumbnail_image_label ' ,
243
245
self ::COL_MEDIA_IMAGE => 'additional_images ' ,
@@ -670,53 +672,17 @@ public function __construct(
670
672
* @param array $attrParams Attribute params
671
673
* @param array $rowData Row data
672
674
* @param int $rowNum
673
- *
674
- * @return boolean
675
- *
676
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
675
+ * @return bool
677
676
*/
678
677
public function isAttributeValid ($ attrCode , array $ attrParams , array $ rowData , $ rowNum )
679
678
{
680
- switch ($ attrParams ['type ' ]) {
681
- case 'varchar ' :
682
- $ val = $ this ->string ->cleanString ($ rowData [$ attrCode ]);
683
- $ valid = $ this ->string ->strlen ($ val ) < self ::DB_MAX_VARCHAR_LENGTH ;
684
- break ;
685
- case 'decimal ' :
686
- $ val = trim ($ rowData [$ attrCode ]);
687
- $ valid = is_numeric ($ val );
688
- break ;
689
- case 'select ' :
690
- case 'multiselect ' :
691
- $ valid = isset ($ attrParams ['options ' ][strtolower ($ rowData [$ attrCode ])]);
692
- break ;
693
- case 'int ' :
694
- $ val = trim ($ rowData [$ attrCode ]);
695
- $ valid = (string )(int )$ val === $ val ;
696
- break ;
697
- case 'datetime ' :
698
- $ val = trim ($ rowData [$ attrCode ]);
699
- $ valid = strtotime ($ val ) !== false ;
700
- break ;
701
- case 'text ' :
702
- $ val = $ this ->string ->cleanString ($ rowData [$ attrCode ]);
703
- $ valid = $ this ->string ->strlen ($ val ) < self ::DB_MAX_TEXT_LENGTH ;
704
- break ;
705
- default :
706
- $ valid = true ;
707
- break ;
708
- }
709
-
710
- if (!$ valid ) {
711
- $ this ->addRowError (__ ("Please correct the value for '%s'. " ), $ rowNum , $ attrCode );
712
- } elseif (!empty ($ attrParams ['is_unique ' ])) {
713
- if (isset ($ this ->_uniqueAttributes [$ attrCode ][$ rowData [$ attrCode ]]) && ($ this ->_uniqueAttributes [$ attrCode ][$ rowData [$ attrCode ]] != $ rowData [self ::COL_SKU ])) {
714
- $ this ->addRowError (__ ("Duplicate Unique Attribute for '%s' " ), $ rowNum , $ attrCode );
715
- return false ;
679
+ if (!$ this ->validator ->isAttributeValid ($ attrCode , $ attrParams , $ rowData )) {
680
+ foreach ($ this ->validator ->getMessages () as $ message ) {
681
+ $ this ->addRowError ($ message , $ rowNum , $ attrCode );
716
682
}
717
- $ this -> _uniqueAttributes [ $ attrCode ][ $ rowData [ $ attrCode ]] = $ rowData [ self :: COL_SKU ] ;
683
+ return false ;
718
684
}
719
- return ( bool ) $ valid ;
685
+ return true ;
720
686
}
721
687
722
688
/**
@@ -1571,16 +1537,7 @@ protected function _saveProducts()
1571
1537
}
1572
1538
}
1573
1539
foreach ($ storeIds as $ storeId ) {
1574
- if ('multiselect ' == $ attribute ->getFrontendInput ()) {
1575
- if (!isset ($ attributes [$ attrTable ][$ rowSku ][$ attrId ][$ storeId ])) {
1576
- $ attributes [$ attrTable ][$ rowSku ][$ attrId ][$ storeId ] = '' ;
1577
- } else {
1578
- $ attributes [$ attrTable ][$ rowSku ][$ attrId ][$ storeId ] .= ', ' ;
1579
- }
1580
- $ attributes [$ attrTable ][$ rowSku ][$ attrId ][$ storeId ] .= $ attrValue ;
1581
- } else {
1582
- $ attributes [$ attrTable ][$ rowSku ][$ attrId ][$ storeId ] = $ attrValue ;
1583
- }
1540
+ $ attributes [$ attrTable ][$ rowSku ][$ attrId ][$ storeId ] = $ attrValue ;
1584
1541
}
1585
1542
// restore 'backend_model' to avoid 'default' setting
1586
1543
$ attribute ->setBackendModel ($ backModel );
@@ -2310,4 +2267,16 @@ public function getParam($name)
2310
2267
{
2311
2268
return isset ($ this ->_parameters [$ name ]) ? $ this ->_parameters [$ name ] : null ;
2312
2269
}
2270
+
2271
+ /**
2272
+ * @param string $name
2273
+ * @return mixed
2274
+ */
2275
+ public function retrieveProductTypeByName ($ name )
2276
+ {
2277
+ if (isset ($ this ->_productTypeModels [$ name ])) {
2278
+ return $ this ->_productTypeModels [$ name ];
2279
+ }
2280
+ return null ;
2281
+ }
2313
2282
}
0 commit comments