File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
app/code/Magento/CatalogImportExport/Model/Import/Product
dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 10
10
use Magento \Catalog \Model \Product \Attribute \Backend \Sku ;
11
11
12
12
/**
13
- * Class Validator
13
+ * Product import model validator
14
14
*
15
15
* @api
16
16
* @since 100.0.2
17
17
*/
18
18
class Validator extends AbstractValidator implements RowValidatorInterface
19
19
{
20
+ private const ERROR_SKU_MARGINAL_WHITESPACES = "Sku contains marginal whitespaces " ;
21
+
20
22
/**
21
23
* @var RowValidatorInterface[]|AbstractValidator[]
22
24
*/
@@ -72,8 +74,12 @@ protected function textValidation($attrCode, $type)
72
74
$ val = $ this ->string ->cleanString ($ this ->_rowData [$ attrCode ]);
73
75
if ($ type == 'text ' ) {
74
76
$ valid = $ this ->string ->strlen ($ val ) < Product::DB_MAX_TEXT_LENGTH ;
75
- } else if ($ attrCode == Product::COL_SKU ) {
77
+ } elseif ($ attrCode == Product::COL_SKU ) {
76
78
$ valid = $ this ->string ->strlen ($ val ) <= SKU ::SKU_MAX_LENGTH ;
79
+ if ($ this ->string ->strlen ($ val ) !== $ this ->string ->strlen (trim ($ val ))) {
80
+ $ this ->_addMessages ([self ::ERROR_SKU_MARGINAL_WHITESPACES ]);
81
+ return false ;
82
+ }
77
83
} else {
78
84
$ valid = $ this ->string ->strlen ($ val ) < Product::DB_MAX_VARCHAR_LENGTH ;
79
85
}
@@ -359,5 +365,7 @@ public function init($context)
359
365
foreach ($ this ->validators as $ validator ) {
360
366
$ validator ->init ($ context );
361
367
}
368
+
369
+ return $ this ;
362
370
}
363
371
}
Original file line number Diff line number Diff line change @@ -2416,6 +2416,16 @@ public function validateRowDataProvider()
2416
2416
'behavior ' => Import::BEHAVIOR_REPLACE ,
2417
2417
'expectedResult ' => true ,
2418
2418
],
2419
+ [
2420
+ 'row ' => ['sku ' => 'sku with whitespace ' ,
2421
+ 'name ' => 'Test ' ,
2422
+ 'product_type ' => 'simple ' ,
2423
+ '_attribute_set ' => 'Default ' ,
2424
+ 'price ' => 10.20 ,
2425
+ ],
2426
+ 'behavior ' => Import::BEHAVIOR_ADD_UPDATE ,
2427
+ 'expectedResult ' => false ,
2428
+ ],
2419
2429
];
2420
2430
}
2421
2431
You can’t perform that action at this time.
0 commit comments