Skip to content

Bundle products options input validation #29256

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

michalderlatka
Copy link
Contributor

Description (*)

Validates input for radio and select type options.

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes Bundle product with option type radio and dropdown can be added to the cart with multiple choices #26110

Manual testing scenarios (*)

Follow instructions from related issue

Questions or comments

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)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Jul 24, 2020

Hi @michalderlatka. Thank you for your contribution
Here is 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

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, 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, please 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

@michalderlatka
Copy link
Contributor Author

@magento run all tests

@michalderlatka michalderlatka added PAP Partners acceleration program Project: GraphQL labels Jul 24, 2020
@michalderlatka michalderlatka force-pushed the 26110_bundle_product_options_fix branch from 59d831a to 71bdba5 Compare July 24, 2020 11:26
@michalderlatka
Copy link
Contributor Author

@magento run all tests

* @return void
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function validateRadioAndSelectOptions($optionsCollection, $options): void
Copy link
Contributor

Choose a reason for hiding this comment

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

don't add protected, use private


if (is_array($optionsCollection->getItems())) {
foreach ($optionsCollection->getItems() as $option) {
if (($option->getType() == 'radio' || $option->getType() == 'select') &&
Copy link
Contributor

Choose a reason for hiding this comment

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

that is a big condition, can you move that to a method with a meaningful name?

/**
* Validate Options for Radio and Select input types
*
* @param \Magento\Bundle\Model\ResourceModel\Option\Collection $optionsCollection
Copy link
Contributor

Choose a reason for hiding this comment

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

do "use Magento\Bundle\Model\ResourceModel\Option\Collection" and only use "Collection"

@lbajsarowicz
Copy link
Contributor

Hi @michalderlatka . Nice to see another contributor from Poland.
Please review the Maintainer comments and feel free to share your thoughts.

@michalderlatka michalderlatka force-pushed the 26110_bundle_product_options_fix branch from 71bdba5 to 28e20d9 Compare July 30, 2020 10:39
@michalderlatka
Copy link
Contributor Author

@magento run all tests

@michalderlatka
Copy link
Contributor Author

@magento run static tests

@cpartica
Copy link
Contributor

cpartica commented Aug 3, 2020

@magento run all tests

Copy link
Contributor

@cpartica cpartica left a comment

Choose a reason for hiding this comment

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

Some static fails, but also some possible performance problems:

PHP Code Sniffer detected 2 violation(s):

FILE: /var/www/html/app/code/Magento/Bundle/Model/Product/Type.php

FOUND 1 ERROR AND 4 WARNINGS AFFECTING 5 LINES

398 | WARNING | [ ] Function's nesting level (6) exceeds 5;
| | consider refactoring the function
535 | ERROR | [x] Tags visual alignment must be consistent
1194 | WARNING | [ ] Empty FUNCTION statement detected
1212 | WARNING | [ ] array_merge(...) is used in a loop and is a
| | resources greedy construction.
1393 | WARNING | [ ] array_merge(...) is used in a loop and is a
| | resources greedy construction.

PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY

The following files incorrectly reuse fixtures:
/var/www/html/dev/tests/integration/testsuite/Magento/Bundle/_files/product_with_multiple_options_radio_select.php
/var/www/html/dev/tests/integration/testsuite/Magento/Bundle/_files/product_with_multiple_options_radio_select_rollback.php
Please use Magento\TestFramework\Workaround\Override\Fixture\Resolver::requireDataFixture
Failed asserting that 2 matches expected 0.

@@ -459,12 +461,12 @@ public function getOptionsIds($product)
* Retrieve bundle option collection
*
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Bundle\Model\ResourceModel\Option\Collection
Copy link
Contributor

Choose a reason for hiding this comment

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

SVC is failing because of this, but I will approve it, it's a false positive

@@ -887,7 +894,7 @@ public function getSelectionsByIds($selectionIds, $product)
*
* @param array $optionIds
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Bundle\Model\ResourceModel\Option\Collection
Copy link
Contributor

Choose a reason for hiding this comment

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

SVC is failing because of this, but I will approve it, it's a false positive

@michalderlatka
Copy link
Contributor Author

@magento run all tests

@michalderlatka
Copy link
Contributor Author

@magento run Functional Tests B2B

@michalderlatka michalderlatka requested a review from cpartica August 7, 2020 14:26
@cpartica
Copy link
Contributor

@magento run Functional Tests B2B

@cpartica
Copy link
Contributor

@magento run Functional Tests EE

@magento-engcom-team magento-engcom-team merged commit 5e832f3 into magento:2.4-develop Aug 11, 2020
@m2-assistant
Copy link

m2-assistant bot commented Aug 11, 2020

Hi @michalderlatka, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Bundle product with option type radio and dropdown can be added to the cart with multiple choices
4 participants