-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re saving product attribute #11617
Re saving product attribute #11617
Conversation
$attributeId = $this->getRequest()->getParam('attribute_id'); | ||
$attributeCode = $this->getRequest()->getParam('attribute_code') | ||
?: $this->generateCode($this->getRequest()->getParam('frontend_label')[0]); | ||
if($attributeId){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove @codingStandardsIgnoreFile
in the top of file, such formatting violates PSR-2 but it is not checked until there is an annotation.
$model->load($attributeId); | ||
$attributeCode = $model->getAttributeCode(); | ||
}else{ | ||
$attributeCode = $this->getRequest()->getParam('attribute_code') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we actually passing attribute_code
in some scenarios in current implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After of this, in this function checks if the attributeCode is valid or not using Zend_Validate_Regex. I think that this I can improve it in the next commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, is attribute_code
present in UI or it is only auto-generated and then displayed as disabled field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ok, just checked admin may enter attribute code manually when creating new attribute.
CollectionFactory $groupCollectionFactory, | ||
FilterManager $filterManager, | ||
Product $productHelper, | ||
LayoutFactory $layoutFactory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for cleanup 👍
@orlangur can you check this PR with the new changes please? |
@raumatbel sure, just need some time to understand the whole logic of the method, will have time for review in 5-7 hours. |
@@ -127,8 +143,10 @@ public function execute() | |||
$attributeId = $this->getRequest()->getParam('attribute_id'); | |||
$attributeCode = $this->getRequest()->getParam('attribute_code') | |||
?: $this->generateCode($this->getRequest()->getParam('frontend_label')[0]); | |||
if (strlen($attributeCode) > 0) { | |||
$validatorAttrCode = new \Zend_Validate_Regex(['pattern' => '/^[a-z\x{600}-\x{6FF}][a-z\x{600}-\x{6FF}_0-9]{0,30}$/u']); | |||
if (!$attributeId && strlen($attributeCode) > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it would be safer to validate attribute code even for existing attributes like it was before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically here is the appropriate logic change as to me: #6770 (comment)
We just should not obtain attribute code from request or generate it for already existing attributes.
3895d64
to
20f81d3
Compare
@orlangur Codacy has failed by an error in the name of parameter of Magento. That name has not been modified by me. |
@raumatbel surely, Codacy can be ignored safely. Changes looks good to me, I first was concerned about the Please squash them into single commit. |
Yes @orlangur. I have moved the model to up. I have not used repository as in the example to don't add new param in the constructor. Done in 1 commit. Also, I have changed |
912a5b3
to
c8ddf6b
Compare
Description
To re save product attribute, the attribute code is not retrieve correctly.
Fixed Issues (if relevant)