-
Notifications
You must be signed in to change notification settings - Fork 9.4k
2.2 develop 11032 Unable to add new options to swatch attribute #11628
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
2.2 develop 11032 Unable to add new options to swatch attribute #11628
Conversation
gonna fix what failed this weekend. |
fix unused parameters
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.
There are a couple of comments that should be addressed, also I am still not 100% sure about this PR if it is the "correct" way to fix this bug.
/** | ||
* @var Config | ||
*/ | ||
protected $eavConfig; |
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.
since we have a new class here the default is to stay away from protected in properties and functions. Recommended is private unless the method is needed outside the class.
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.
fixed
SwatchHelper $swatchHelper, | ||
OptionCollection $attrOptionCollectionFactory | ||
) { | ||
$this->eavConfig = $eavConfig; |
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.
spacing looks a bit off here
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.
fixed
$optionKey = self::PREFIX_OPTION . $isSwatch; | ||
$swatchKey = self::PREFIX_SWATCH . $isSwatch; | ||
|
||
if (!empty($isSwatch) && $attribute->getData($optionKey) === null |
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.
Could you maybe update this to look as follows for readability:
if (
!empty($isSwatch)
&& $attribute->getData($optionKey) === null
&& $attribute->getData($swatchKey) === null
) {
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.
fixed
{ | ||
$options = $this->getOptionsByAttributeIdWithSortOrder($attributeId); | ||
$attributeData = $this->getOptionsForSwatch($options, $optionKey); | ||
return $attributeData; |
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.
You could just return $this->getOptionsForSwatch($options, $optionKey);
here rather than set $attributeData
.
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.
fixed
protected function getStoreLabels($optionId) | ||
{ | ||
$optionCollection = $this->optionCollection->create(); | ||
$connection = $optionCollection->getConnection(); |
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.
Again spacing seems a bit off
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.
fixed
) { | ||
$this->eavConfig = $eavConfig; | ||
$this->swatchHelper = $swatchHelper; | ||
$this->optionCollection = $attrOptionCollectionFactory; |
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.
Technically at this point this is the factory still right? Might be good to keep that obvious in the naming of the property.
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.
fixed
* | ||
* @return null|string | ||
*/ | ||
protected function isSwatch($attribute) |
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.
The naming of this method is a bit confusing to me. is
would suggest to me that it will return a boolean but it actually returns a mix of string and null. I think it might be a bit more readable if there was two methods, 1 for returning a boolean and one for getting the swatch type or something like that.
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.
fixed
* | ||
* @return array | ||
*/ | ||
protected function getStoreLabels($optionId) |
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.
Part of me thinks that both this method and getOptionsByAttributeIdWithSortOrder
should not be in the plugin but in another class.
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.
fixed for getOptionsByAttributeWithSortOrder but still to be fixed for storeLabels
* | ||
* @return array | ||
*/ | ||
protected function getOptionsForSwatch($options, $optionKey) |
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.
we can make sure an array is passed in here with array $options
if it is always going to be an array.
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.
fixed
@springerin the following API test is failing. |
sure I will check it out today and let you know. |
locally tested with the last updates and still green for me. Waiting for more info to reproduce the error. |
@springerin it seems that this has now be fixed by #12036. Using the |
ProductAttributeOptionManagementInterface#add() doesn't do anything.
Description
On the beforeBeforeSave(Attribute $attribute) in the case of a swatch attribute, expects an array with key swatchtext / swatchvisual ( first in case of textswatch, second in case of visualswatch) that overwrites the option array originally given, so if this is empty, it will be emptied as well. So I added a plugin that right before doing this, creates the expected array that will be used later for the creation of the actual option.
Fixed Issues (if relevant)
Manual testing scenarios
{ "option": { "label": "new color", "value": "", "sort_order": 0, "is_default": true, "store_labels": [ { "store_id": 0, "label": "new color" }, { "store_id": 1, "label": "new color" } ] } }
Contribution checklist