Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/code/Magento/Catalog/Model/Product/Attribute/Backend/Sku.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ protected function _generateUniqueSku($object)
public function beforeSave($object)
{
$this->_generateUniqueSku($object);
$this->trimValue($object);
return parent::beforeSave($object);
}

Expand Down Expand Up @@ -127,4 +128,17 @@ protected function _getLastSimilarAttributeValueIncrement($attribute, $object)
$data = $connection->fetchOne($select, $bind);
return abs((int)str_replace($value, '', $data));
}

/**
* @param Product $object
* @return void
*/
private function trimValue($object)
{
$attrCode = $this->getAttribute()->getAttributeCode();
$value = $object->getData($attrCode);
if ($value) {
$object->setData($attrCode, trim($value));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ protected function customizeNameListeners(array $meta)
$skuPath . static::META_CONFIG_PATH,
$meta,
[
'autoImportIfEmpty' => true
'autoImportIfEmpty' => true,
'validation' => ['no-marginal-whitespace' => true]
]
);

Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Ui/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Keyword,Keyword
"Letters, numbers, spaces or underscores only please","Letters, numbers, spaces or underscores only please"
"Letters only please","Letters only please"
"No white space please","No white space please"
"No marginal white space please","No marginal white space please"
"Your ZIP-code must be in the range 902xx-xxxx to 905-xx-xxxx","Your ZIP-code must be in the range 902xx-xxxx to 905-xx-xxxx"
"A positive or negative non-decimal number please","A positive or negative non-decimal number please"
"The specified vehicle identification number (VIN) is invalid.","The specified vehicle identification number (VIN) is invalid."
Expand Down
6 changes: 6 additions & 0 deletions app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ define([
},
$.mage.__('No white space please')
],
'no-marginal-whitespace': [
function (value) {
return !/^\s+|\s+$/i.test(value);
},
$.mage.__('No marginal white space please')
],
'zip-range': [
function (value) {
return /^90[2-5]-\d{2}-\d{4}$/.test(value);
Expand Down
1 change: 1 addition & 0 deletions lib/web/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Submit,Submit
"Letters, numbers, spaces or underscores only please","Letters, numbers, spaces or underscores only please"
"Letters only please","Letters only please"
"No white space please","No white space please"
"No marginal white space please","No marginal white space please"
"Your ZIP-code must be in the range 902xx-xxxx to 905-xx-xxxx","Your ZIP-code must be in the range 902xx-xxxx to 905-xx-xxxx"
"A positive or negative non-decimal number please","A positive or negative non-decimal number please"
"The specified vehicle identification number (VIN) is invalid.","The specified vehicle identification number (VIN) is invalid."
Expand Down
6 changes: 6 additions & 0 deletions lib/web/mage/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@
},
$.mage.__('No white space please')
],
'no-marginal-whitespace': [
function (value, element) {
return this.optional(element) || !/^\s+|\s+$/i.test(value);
},
$.mage.__('No marginal white space please')
],
'zip-range': [
function (value, element) {
return this.optional(element) || /^90[2-5]-\d{2}-\d{4}$/.test(value);
Expand Down