Skip to content

Commit 8d1e555

Browse files
committed
Merge remote-tracking branch 'origin/MC-31594' into 2.3-develop-pr38
2 parents 8c1dfb4 + 09902ec commit 8d1e555

File tree

2 files changed

+20
-2
lines changed
  • app/code/Magento/CatalogImportExport/Model/Import/Product
  • dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import

2 files changed

+20
-2
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product/Validator.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
use Magento\Catalog\Model\Product\Attribute\Backend\Sku;
1111

1212
/**
13-
* Class Validator
13+
* Product import model validator
1414
*
1515
* @api
1616
* @since 100.0.2
1717
*/
1818
class Validator extends AbstractValidator implements RowValidatorInterface
1919
{
20+
private const ERROR_SKU_MARGINAL_WHITESPACES = "Sku contains marginal whitespaces";
21+
2022
/**
2123
* @var RowValidatorInterface[]|AbstractValidator[]
2224
*/
@@ -72,8 +74,12 @@ protected function textValidation($attrCode, $type)
7274
$val = $this->string->cleanString($this->_rowData[$attrCode]);
7375
if ($type == 'text') {
7476
$valid = $this->string->strlen($val) < Product::DB_MAX_TEXT_LENGTH;
75-
} else if ($attrCode == Product::COL_SKU) {
77+
} elseif ($attrCode == Product::COL_SKU) {
7678
$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+
}
7783
} else {
7884
$valid = $this->string->strlen($val) < Product::DB_MAX_VARCHAR_LENGTH;
7985
}
@@ -359,5 +365,7 @@ public function init($context)
359365
foreach ($this->validators as $validator) {
360366
$validator->init($context);
361367
}
368+
369+
return $this;
362370
}
363371
}

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,6 +2416,16 @@ public function validateRowDataProvider()
24162416
'behavior' => Import::BEHAVIOR_REPLACE,
24172417
'expectedResult' => true,
24182418
],
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+
],
24192429
];
24202430
}
24212431

0 commit comments

Comments
 (0)