-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Updating attribute option data through API will set unwanted source_model on the attribute #13156
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
Comments
Added bonus is that the storeview values for the options are also not rendered because the _getOptionValuesCollection function in Magento\Eav\Block\Adminhtml\Attribute\Edit\Options\Options only fetches the option values for 1 storeId (which in most cases is also not the correct one) |
@koenner01, thank you for your report. |
For the folks interested in this problem, we've received a patch from the Cloud support a while ago (MDVA-8298) which fixes this problem, apply to the diff --git a/Model/Entity/Attribute/AbstractAttribute.php b/Model/Entity/Attribute/AbstractAttribute.php
index 19877a51c48..68a4e1dbe7b 100644
--- a/Model/Entity/Attribute/AbstractAttribute.php
+++ b/Model/Entity/Attribute/AbstractAttribute.php
@@ -585,9 +585,9 @@ abstract class AbstractAttribute extends \Magento\Framework\Model\AbstractExtens
{
if (empty($this->_source)) {
if (!$this->getSourceModel()) {
- $this->setSourceModel($this->_getDefaultSourceModel());
+ $this->_source = $this->_getDefaultSourceModel();
}
- $source = $this->_universalFactory->create($this->getSourceModel());
+ $source = $this->_universalFactory->create($this->_source);
if (!$source) {
throw new LocalizedException(
__( UPDATE: this patch caused new problems, best not to apply until there is a better solution which works in all cases. |
Here is a new and proper patch which I just created and tested pretty well and has no downsides (apply to diff --git a/Model/Entity/Attribute/AbstractAttribute.php b/Model/Entity/Attribute/AbstractAttribute.php
index 0c97c7f5e27..401fdc7037e 100644
--- a/Model/Entity/Attribute/AbstractAttribute.php
+++ b/Model/Entity/Attribute/AbstractAttribute.php
@@ -585,9 +585,11 @@ abstract class AbstractAttribute extends \Magento\Framework\Model\AbstractExtens
{
if (empty($this->_source)) {
if (!$this->getSourceModel()) {
- $this->setSourceModel($this->_getDefaultSourceModel());
+ $this->_source = $this->_getDefaultSourceModel();
+ } else {
+ $this->_source = $this->getSourceModel();
}
- $source = $this->_universalFactory->create($this->getSourceModel());
+ $source = $this->_universalFactory->create($this->_source);
if (!$source) {
throw new LocalizedException(
__( I'll create a PR for this later. And you might need to run the following query on your database, to remove the source_model again: UPDATE `eav_attribute` SET `source_model` = NULL WHERE `source_model` = 'Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Table' AND `frontend_input` = 'multiselect'; Be sure to first test this query first on a harmless environment, not directly on a production server! |
Hi @koenner01. Thank you for your report. The fix will be available with the upcoming 2.3.1 release. |
Hi @koenner01. Thank you for your report. The fix will be available with the upcoming 2.2.8 release. |
When updating an eav attribute's options through the API, the source_model of the attribute will be set to 'Magento\Eav\Model\Entity\Attribute\Source\Table'. Not only is this unwanted, it also completely destroys the ability to update this attribute's options through the backend.
Preconditions
Steps to reproduce
Create a new multiselect product attribute programmatically through an install script. Make sure to set the is_user_defined to 0 as we don't want te be able to delete this attribute.
Notice how the source_model of the eav_attribute is nice and empty in the database and how you can manage the attribute options manually in the backend
Add a new option manually through the backend for example 'I love Magento' and save the attribute
Expected result
Actual result
Why is it that the flow in the backend of adding a new option is not EXACTLY the same as adding a new option through the api. I can understand that there would be frontend validation etc. in the backend and the save controller for the attribute, but in the end they should both use the repository in the same way...
#magentomagic
The text was updated successfully, but these errors were encountered: