Skip to content
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

Changing attribute from swatch to dropdown deletes swatch options for all attributes #20396

Closed
maderlock opened this issue Jan 18, 2019 · 30 comments
Assignees
Labels
Component: Catalog Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@maderlock
Copy link

Preconditions (*)

  1. Magento 2.2.7 (need to confirm but likely 2.3 still has issue)

Steps to reproduce (*)

  1. Create two configurable attributes (A and B) as text/visual swatches, each with multiple options
  2. Create configurable products for both A and B
  3. Change attribute A to be a dropdown

Expected result (*)

  1. Product configurable on attribute A displays as dropdown
  2. Product configurable on attribute B displays still as swatch

Actual result (*)

  1. Products with both attribute A and B both display as a dropdown
  2. Products configurable on attribute B display a javascript error (need to reconfirm this)

If you look at table eav_attribute_option_swatch, once the attributes are made this is populated with options for both attributes. After changing the type of attribute A back to dropdown this table clears completely, removing both the swatch option data for attribute A and (incorrectly) attribute B.

The cause of this looks to be the fix put in place for #12695. Code was added to clear down the entries for this table when changing an attribute from swatch to dropdown, but there was an error in construction of the SQL meaning that the WHERE statement got partially cleared, so that too much data gets cleared.

Here is the code that causes the issue, from app/code/Magento/Swatches/Model/ResourceModel/Swatch.php:

    public function clearSwatchOptionByOptionIdAndType($optionIDs, $type = null)
    {
        if (count($optionIDs)) {
            foreach ($optionIDs as $optionId) {
                $where = ['option_id' => $optionId];
                if ($type !== null) {
                    $where['type = ?'] = $type;
                }
                $this->getConnection()->delete($this->getMainTable(), $where);
            }
        }
    }

The line that causes the problem is $where = ['option_id' => $optionId];. When the data is passed to the Zend framework, it expects the format to be ['option_id = ?' => optionId]. This is because Zend will look for the '?' to strip out (whilst preparing the SQL, it uses this for data binding). So if the '= ?' is missing Zend will strip out the intended field value. This turns the SQL into a DELETE FROM eav_attribute_option_swatch WHERE (option_id); hence why the table is cleared down.

We have added a plugin on our installation to replace this missing = ? and this seems to resolve it in 2.2.7.

Checking 2.3, the same error is still in the Swatch.php, so we suspect this is still an issue on that version.

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Jan 18, 2019
@magento-engcom-team
Copy link
Contributor

Hi @maderlock. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me $VERSION instance

where $VERSION is version tags (starting from 2.2.0+) or develop branches (for example: 2.3-develop).
For more details, please, review the Magento Contributor Assistant documentation.

@maderlock do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@maderlock
Copy link
Author

@magento-engcom-team give me 2.3-develop instance

@GovindaSharma GovindaSharma self-assigned this Jan 18, 2019
@magento-engcom-team
Copy link
Contributor

Hi @maderlock. Thank you for your request. I'm working on Magento 2.3-develop instance for you

@magento-engcom-team
Copy link
Contributor

Hi @GovindaSharma. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • 6. Add label Issue: Confirmed once verification is complete.

  • 7. Make sure that automatic system confirms that report has been added to the backlog.

@magento-engcom-team
Copy link
Contributor

Hi @maderlock, here is your Magento instance.
Admin access: https://i-20396-2-3-develop.instances.magento-community.engineering/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

@GovindaSharma GovindaSharma added Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Component: Catalog labels Jan 18, 2019
@ghost ghost self-assigned this Jan 18, 2019
@magento-engcom-team
Copy link
Contributor

Hi @engcom-backlog-nazar. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • 6. Add label Issue: Confirmed once verification is complete.

  • 7. Make sure that automatic system confirms that report has been added to the backlog.

@maderlock
Copy link
Author

Got kicked out of the instance as another user logged in. I assume @GovindaSharma or @engcom-backlog-nazar is looking at this, so we will leave this for now.

@surabhisrivastava09 surabhisrivastava09 self-assigned this Jan 18, 2019
@magento-engcom-team
Copy link
Contributor

Hi @Surabhi-Cedcoss. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • 6. Add label Issue: Confirmed once verification is complete.

  • 7. Make sure that automatic system confirms that report has been added to the backlog.

@ghost
Copy link

ghost commented Jan 18, 2019

@maderlock did you check this -> #12695

@maderlock
Copy link
Author

In my description I mention that this problem was caused by the fix for #12695. This bug is the opposite problem.

@ghost
Copy link

ghost commented Jan 18, 2019

@maderlock ok, i'm not read all description :) , just remembered that somewhere we have same issue

@GovindaSharma GovindaSharma removed their assignment Jan 18, 2019
@ghost
Copy link

ghost commented Jan 18, 2019

@maderlock i'm not able to reproduce following steps you described, can you check test instance ?

@maderlock
Copy link
Author

Confirmed reproduced using steps above on 2.3-develop instance.

@ghost
Copy link

ghost commented Jan 18, 2019

@maderlock on vanila instance ?

@ghost
Copy link

ghost commented Jan 18, 2019

@maderlock But you don't set value for you text swatch to default store, how they can be shown? this is non issue.

@ghost ghost closed this as completed Jan 18, 2019
@ghost ghost added the non-issue label Jan 18, 2019
@maderlock
Copy link
Author

Please explain. This displayed entirely correctly until changing back to Dropdown. After I applied my fix the values remained. As far as I understand it there is no need to set a specific value per store.

I am happy to retest with values for the default store, but I am unimpressed at the abrupt closure of this issue.

@maderlock
Copy link
Author

I can confirm that even with values set on the text swatch for the default store, following the above steps the swatch option table is still cleared as described. Please note that you cannot see this change from the admin side.

@ghost
Copy link

ghost commented Jan 18, 2019

@maderlock Because if you change attribute to text swatch you need enter value for this label, this is non issue.
selection_278

@ghost
Copy link

ghost commented Jan 18, 2019

@maderlock after that, text swatch is showing on frontend.
You need to fill admin and default store view
selection_280
selection_279

@maderlock
Copy link
Author

I have re-tested again with entering the values you describe. Problem still occurs as described.

Please follow all steps as described. It may be necessary to clear cache before viewing frontend the after changing attribute A.

@maderlock
Copy link
Author

If you save the text attribute again, yes this will display correctly on the frontend as it will re-populate the eav_attribute_option_swatch table. But it should not be being emptied to start with.

@maderlock
Copy link
Author

If you are uncertain that this is an issue, I recommend looking at the contents of the eav_attribute_option_swatch table before and after changing attribute A back to dropdown. You will notice that before there are values for two attributes, and afterwards there are values for none (rather than just for one).

@ghost
Copy link

ghost commented Jan 18, 2019

@maderlock ok

@ghost ghost reopened this Jan 18, 2019
@ghost
Copy link

ghost commented Jan 18, 2019

@maderlock sorry i'm little bit confused for later issue about it, now clearly and i'm able to reproduce this.
Best regards

@ghost ghost added Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Jan 18, 2019
@magento-engcom-team
Copy link
Contributor

@engcom-backlog-nazar Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-97831, MAGETWO-97832 were created

@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Jan 18, 2019
@ghost ghost removed their assignment Jan 18, 2019
@hostep
Copy link
Contributor

hostep commented Jan 19, 2019

Thanks for the detailed research @maderlock, I can reproduce and your suggested change fixes it. I've created a PR over here: #20421

@magento-engcom-team
Copy link
Contributor

Hi @maderlock. Thank you for your report.
The issue has been fixed in #20421 by @hostep in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.1 release.

@cwpm
Copy link

cwpm commented Feb 6, 2019

We've come across this issue too on 2.2.7 website, can this fixed also be rolled out in 2.2.8 update?

@hostep
Copy link
Contributor

hostep commented Feb 6, 2019

@cwpm: PR for 2.2 exists and was approved 2 days ago: #20745
No idea if it will make it in 2.2.8, but let's hope so :)

@magento-engcom-team
Copy link
Contributor

Hi @maderlock. Thank you for your report.
The issue has been fixed in #20745 by @amol2jcommerce in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.9 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Feb 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Catalog Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

6 participants