Skip to content

Commit e364fdc

Browse files
committed
Merge remote-tracking branch 'origin/MC-31879' into 2.4-develop-pr15
2 parents 73f4963 + 82b8ea6 commit e364fdc

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
307307
// Can't add new translated strings in patch release
308308
'invalidLayoutUpdate' => 'Invalid format.',
309309
'insufficientPermissions' => 'Invalid format.',
310+
ValidatorInterface::ERROR_SKU_MARGINAL_WHITESPACES => 'SKU contains marginal whitespaces'
310311
];
311312
//@codingStandardsIgnoreEnd
312313

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ interface RowValidatorInterface extends \Magento\Framework\Validator\ValidatorIn
8787

8888
const ERROR_DUPLICATE_MULTISELECT_VALUES = 'duplicatedMultiselectValues';
8989

90+
const ERROR_SKU_MARGINAL_WHITESPACES = 'skuMarginalWhitespaces';
91+
9092
/**
9193
* Value that means all entities (e.g. websites, groups etc.)
9294
*/

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
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
@@ -72,8 +72,12 @@ protected function textValidation($attrCode, $type)
7272
$val = $this->string->cleanString($this->_rowData[$attrCode]);
7373
if ($type == 'text') {
7474
$valid = $this->string->strlen($val) < Product::DB_MAX_TEXT_LENGTH;
75-
} else if ($attrCode == Product::COL_SKU) {
75+
} elseif ($attrCode == Product::COL_SKU) {
7676
$valid = $this->string->strlen($val) <= SKU::SKU_MAX_LENGTH;
77+
if ($this->string->strlen($val) !== $this->string->strlen(trim($val))) {
78+
$this->_addMessages([RowValidatorInterface::ERROR_SKU_MARGINAL_WHITESPACES]);
79+
return false;
80+
}
7781
} else {
7882
$valid = $this->string->strlen($val) < Product::DB_MAX_VARCHAR_LENGTH;
7983
}
@@ -359,5 +363,7 @@ public function init($context)
359363
foreach ($this->validators as $validator) {
360364
$validator->init($context);
361365
}
366+
367+
return $this;
362368
}
363369
}

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)