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

Attribute repository resets sourceModel for new attributes #10814

Closed
adi3009 opened this issue Sep 7, 2017 · 12 comments
Closed

Attribute repository resets sourceModel for new attributes #10814

adi3009 opened this issue Sep 7, 2017 · 12 comments
Labels
Component: Catalog Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P3 May be fixed according to the position in the backlog. Progress: done 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 Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. stale issue

Comments

@adi3009
Copy link

adi3009 commented Sep 7, 2017

When creating a new product attribute through code, product attribute repository save method resets source model to null or something else. Therefore a new attribute is created with an empty option (in case of select or multiselect input type). This happens only for new attributes not when updating exiting attributes.

Expected Result

It is expected that when some data is set on a model, repository should not change or reset it.

Preconditions

Magento Version 2.1.7 CE and EE

Product Attribute Repository

Example Code

Steps to reproduce

  • Copy Example/Catalog module into app/code directory.

  • Install module

    ./bin/magento module:enable "Example_Catalog"
    ./bin/magento setup:upgrade
    ./bin/magento setup:di:compile
    
  • Run command to create an example product attribute

    ./bin/magento example:catalog:create_attribute
    

Actual Result

  • In magento admin panel you should see attribute example_attribute_code of input type select having just an empty option.

  • Run the command again and you should see the attribute has options from source model.

@orlangur
Copy link
Contributor

orlangur commented Sep 7, 2017

$attribute->setSourceModel(
                $this->productHelper->getAttributeSourceModelByInputType($attribute->getFrontendInput())
            );

looks perfectly valid to me as you cannot have different source models for the same frontend_input. Just use another frontend_input and map source model properly.

@adi3009
Copy link
Author

adi3009 commented Sep 8, 2017

@orlangur I've updated the example code. I think the repository should only set source model if not set already.

@orlangur
Copy link
Contributor

orlangur commented Sep 8, 2017

Again:

  • is Magento using different source models for the same frontend input internally?
  • what is the problem in mapping your source model with frontend input properly?

@adi3009
Copy link
Author

adi3009 commented Sep 8, 2017

Yes

  • Magento uses different source models for several product attributes, e.g. product status (frontend_input is select) etc.
  • The problem is in save method of repository where it sets a source model without checking if a source model already set on attribute model data, it does this only for new attributes not when saving existing attribute.

@orlangur
Copy link
Contributor

orlangur commented Sep 8, 2017

Ok, thanks for the detailed explanation, it looks like \Magento\Catalog\Helper\Product::getAttributeInputTypes is just a partial implementation currently.

So, you just need a regular new select/multiselect but with custom source model.

Not sure it should be treated as bug report or a feature request, so, leaving without such label for now.

@magento-engcom-team magento-engcom-team added Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed and removed G1 Passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels Sep 11, 2017
@okorshenko okorshenko added the Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed label Sep 14, 2017
@magento-engcom-team
Copy link
Contributor

@adi3009 thank you for your bug report.
We've created internal ticket MAGETWO-75299 to track progress on the issue

@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 Sep 19, 2017
@nmalevanec nmalevanec assigned nmalevanec and unassigned nmalevanec Dec 6, 2017
@okorshenko
Copy link
Contributor

Hi @adi3009
The issue has been fixed and delivered in 2.2-develop branch. Will be available with upcoming patch release.

@okorshenko okorshenko added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Dec 13, 2017
@adi3009
Copy link
Author

adi3009 commented Jun 14, 2018

Hi @okorshenko, @orlangur

Is this fixed and released, I can replicate the issue in 2.2.4

@orlangur orlangur reopened this Jun 14, 2018
@orlangur orlangur removed the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Jun 14, 2018
@adi3009
Copy link
Author

adi3009 commented Aug 21, 2018

can also replicate in 2.2.5

@ghost ghost self-assigned this Jan 3, 2019
@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 3, 2019
@magento-engcom-team
Copy link
Contributor

@engcom-backlog-tomash Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-97417, MAGETWO-97418 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 3, 2019
@ghost ghost removed their assignment Jan 4, 2019
@ghost ghost removed Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed 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 labels Oct 20, 2020
@magento-engcom-team magento-engcom-team added Priority: P3 May be fixed according to the position in the backlog. Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. labels Nov 30, 2020
@stale
Copy link

stale bot commented Feb 15, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Catalog Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P3 May be fixed according to the position in the backlog. Progress: done 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 Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. stale issue
Projects
Development

No branches or pull requests

6 participants