File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -196,8 +196,23 @@ public function execute()
196
196
: $ this ->getRequest ()->getParam ('attribute_code ' );
197
197
$ attributeCode = $ attributeCode ?: $ this ->generateCode ($ this ->getRequest ()->getParam ('frontend_label ' )[0 ]);
198
198
if (strlen ($ attributeCode ) > 0 ) {
199
+ $ attributeCodeIsValid = true ;
200
+ $ minLength = \Magento \Eav \Model \Entity \Attribute::ATTRIBUTE_CODE_MIN_LENGTH ;
201
+ $ maxLength = \Magento \Eav \Model \Entity \Attribute::ATTRIBUTE_CODE_MAX_LENGTH ;
202
+
203
+ if (strlen ($ attributeCode ) < $ minLength || strlen ($ attributeCode ) > $ maxLength ) {
204
+ $ this ->messageManager ->addErrorMessage (
205
+ __ (
206
+ 'An attribute code must not be less than %1 and more than %2 characters. ' ,
207
+ $ minLength ,
208
+ $ maxLength
209
+ )
210
+ );
211
+ $ attributeCodeIsValid = false ;
212
+ }
213
+
199
214
$ validatorAttrCode = new \Zend_Validate_Regex (
200
- ['pattern ' => '/^[a-zA-Z\x{600}-\x{6FF}] [a-zA-Z\x{600}-\x{6FF}_0-9]{0,30} $/u ' ]
215
+ ['pattern ' => '/^[a-zA-Z]+ [a-zA-Z0-9_] $/u ' ]
201
216
);
202
217
if (!$ validatorAttrCode ->isValid ($ attributeCode )) {
203
218
$ this ->messageManager ->addErrorMessage (
@@ -207,6 +222,10 @@ public function execute()
207
222
$ attributeCode
208
223
)
209
224
);
225
+ $ attributeCodeIsValid = false ;
226
+ }
227
+
228
+ if (!$ attributeCodeIsValid ) {
210
229
return $ this ->returnResult (
211
230
'catalog/*/edit ' ,
212
231
['attribute_id ' => $ attributeId , '_current ' => true ],
You can’t perform that action at this time.
0 commit comments