Skip to content

Fix adding an option with label '0' #34578

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

Conversation

mbijnsdorp
Copy link
Contributor

Description (*)

When adding an option to an attribute programmatically via \Magento\Eav\Model\Entity\Attribute\OptionManagement::add, it's not possible to use the label '0' for the option.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

Fix adding an attribute option to a product with the label '0'
@m2-assistant
Copy link

m2-assistant bot commented Nov 8, 2021

Hi @mbijnsdorp. Thank you for your contribution
Here are some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here

ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.

For more details, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@mbijnsdorp
Copy link
Contributor Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@mbijnsdorp
Copy link
Contributor Author

@magento run Functional Tests B2B

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@ihor-sviziev ihor-sviziev added the Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. label Nov 9, 2021
Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mbijnsdorp,
Your changes look good to me.
Could you cover your changes with some automated tests?

@mbijnsdorp
Copy link
Contributor Author

Hi @ihor-sviziev,
I'm inexperienced when it comes to writing tests. I could adjust the label of the add method https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/OptionManagementTest.php#L68, but that wouldn't make it very obvious. Would you suggest a similar method to that one?

@ihor-sviziev ihor-sviziev added Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests help wanted labels Nov 9, 2021
@eduard13
Copy link
Contributor

eduard13 commented Nov 9, 2021

Hi @mbijnsdorp, thank you for your contribution. The existing test you mentioned, is a good place to cover your case. I'd suggest adding a simple dataProvider, that will provide different options labels to the add method. Something like in the following Unit Test.

* @dataProvider methodDataProvider
*/
public function testMethodWithNoSuchEntityException($method): void
{
$this->customerMetadata->expects(
$this->any()
)->method(
'getAttributeMetadata'
)->willThrowException(
new NoSuchEntityException(
__(
'No such entity with %fieldName = %fieldValue',
['fieldName' => 'field', 'fieldValue' => 'value']
)
)
);
$this->assertFalse($this->_block->{$method}());
}
/**
* @return array
*/
public function methodDataProvider(): array
{
return [
'showPrefix' => ['showPrefix'],
'isPrefixRequired' => ['isPrefixRequired'],
'showMiddlename' => ['showMiddlename'],
'isMiddlenameRequired' => ['isMiddlenameRequired'],
'showSuffix' => ['showSuffix'],
'isSuffixRequired' => ['isSuffixRequired']
];
}

Please let me know if you have any questions.

Thank you.

@mbijnsdorp
Copy link
Contributor Author

Hi @eduard13, thank you for the pointers. I've updated the test with a data provider based on the given example. Please let me know if it requires any other changes.

@mbijnsdorp
Copy link
Contributor Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@mbijnsdorp
Copy link
Contributor Author

@magento run Unit Tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@mbijnsdorp
Copy link
Contributor Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@ihor-sviziev
Copy link
Contributor

@magento run Functional Tests CE, Functional Tests EE

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

Apply suggestions from code review
@ihor-sviziev
Copy link
Contributor

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@ihor-sviziev ihor-sviziev added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: test coverage and removed Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests help wanted labels Nov 12, 2021
@mbijnsdorp
Copy link
Contributor Author

@ihor-sviziev Could you also add the partner Youwe label?

@ihor-sviziev
Copy link
Contributor

@sidolov @sivaschenko, could you check why the partner label wasn't applied?

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbijnsdorp, great job! Thank you for your contribution!
✔ Approved

@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-9343 has been created to process this Pull Request

@magento-engcom-team
Copy link
Contributor

@mbijnsdorp thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository.

@sidolov
Copy link
Contributor

sidolov commented Nov 12, 2021

@ihor-sviziev label wasn't added because @mbijnsdorp is not a part of Youwe team on the GitHub

@engcom-Dash
Copy link
Contributor

engcom-Dash commented Jan 12, 2022

✔️ QA Passed

Manual testing scenario:

  1. Add the code to add product attribute manually with label ‘0’ at the listing page of product by adding a custom function addOption() in ListProduct.php block (app/code/Magento/Catalog/Block/Product/ListProduct.php) and calling the function on page in list.phtml (app/code/Magento/Catalog/view/frontend/templates/product/list.phtml) (screenshot below)

Screenshot 2022-01-12 at 12 41 04 PM

  1. Run the code on the magento server

Before: ✖️ Exception is throwing with message ‘The attribute option label is empty. Enter the value and try again.’

Screenshot 2022-01-12 at 12 44 01 PM

After: ✔️ The code run successfully without expection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: bug fix Award: test coverage Component: Eav Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: accept Release Line: 2.4 Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants