Skip to content

Commit

Permalink
added check for attribute code length and error message
Browse files Browse the repository at this point in the history
  • Loading branch information
rajneesh1dev committed Feb 6, 2019
1 parent b3d9a05 commit 5a9a9e6
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,26 @@ public function execute()
? $model->getAttributeCode()
: $this->getRequest()->getParam('attribute_code');
$attributeCode = $attributeCode ?: $this->generateCode($this->getRequest()->getParam('frontend_label')[0]);
$maxLength = \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH;
$minLength = \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MIN_LENGTH;
if (strlen($attributeCode) > $maxLength) {
$this->messageManager->addErrorMessage(
__(
'Attribute code "%1" length should not greater than "%2" characters.' ,
$attributeCode,
$maxLength
)
);
return $this->returnResult(
'catalog/*/edit',
['attribute_id' => $attributeId, '_current' => true],
['error' => true]
);
}
if (strlen($attributeCode) > 0) {
$pattern = sprintf('/^[a-zA-Z\x{600}-\x{6FF}][a-zA-Z\x{600}-\x{6FF}_0-9]{%s,%s}$/u', $minLength , $maxLength);
$validatorAttrCode = new \Zend_Validate_Regex(
['pattern' => '/^[a-zA-Z\x{600}-\x{6FF}][a-zA-Z\x{600}-\x{6FF}_0-9]{0,30}$/u']
['pattern' => $pattern]
);
if (!$validatorAttrCode->isValid($attributeCode)) {
$this->messageManager->addErrorMessage(
Expand Down

0 comments on commit 5a9a9e6

Please sign in to comment.