Skip to content

Grouped product frontend quantity validation added and code refactor #39480

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

Open
wants to merge 32 commits into
base: 2.4-develop
Choose a base branch
from

Conversation

Mohamed-Asar
Copy link
Contributor

Description (*)

Grouped Product Frontend Quantity validation added

Related Pull Requests

Fixed Issues (if relevant)

  1. Grouped Product Frontend Quantity Validations are Missing #39479
  2. Magento 2.4.7 minAllowed missing product order qty  #39142

Manual testing scenarios (*)

1.Create a Grouped Product and associate it with child products.
2. Set the following quantity properties for one of the child products:
- Minimum Qty Allowed in Shopping Cart: 2
- Maximum Qty Allowed in Shopping Cart: 10
- Qty Increments: 2
3.Open the Product Detail Page (PDP) of the Grouped Product and test invalid quantities for the selected child product (e.g., 1, 3, or 11) to confirm that invalid inputs are restricted.

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)

Copy link

m2-assistant bot commented Dec 15, 2024

Hi @Mohamed-Asar. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ 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 Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@m2-github-services m2-github-services added Partner: Ziffity partners-contribution Pull Request is created by Magento Partner labels Dec 15, 2024
@m2-community-project m2-community-project bot added Progress: pending review Priority: P2 A defect with this priority could have functionality issues which are not to expectations. labels Dec 15, 2024
@Mohamed-Asar
Copy link
Contributor Author

@magento run all tests.

Copy link

Failed to run the builds. Please try to re-run them later.

@Mohamed-Asar
Copy link
Contributor Author

@magento run all tests

@Mohamed-Asar
Copy link
Contributor Author

@magento run all tests

@Mohamed-Asar
Copy link
Contributor Author

@magento run all tests

@Mohamed-Asar
Copy link
Contributor Author

@magento run all tests

@Mohamed-Asar
Copy link
Contributor Author

@magento run all tests

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces frontend quantity validation for grouped products and refactors the related code. Key changes include:

  • Adding a bypass for validation when the quantity is zero in the validation JavaScript.
  • Introducing a new ValidateQuantity ViewModel and updating layout XML files and product view templates accordingly.
  • Refactoring the CatalogInventory quantity validator and updating associated tests and plugins.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/web/mage/validation.js Added early return logic for zero quantity based on a data attribute.
app/code/Magento/Wishlist/view/frontend/layout/wishlist_index_configure_type_grouped.xml Updated layout to inject the ValidateQuantity ViewModel.
app/code/Magento/GroupedProduct/view/frontend/templates/product/view/type/grouped.phtml Updated template to use the new ViewModel and a dedicated escaper for output.
app/code/Magento/GroupedProduct/view/frontend/layout/catalog_product_view_type_grouped.xml Similar layout XML updates for grouped products.
app/code/Magento/GroupedProduct/ViewModel/ValidateQuantity.php Introduced new ViewModel to encapsulate quantity validation data.
app/code/Magento/CatalogInventory/Model/Product/QuantityValidator.php Refactored logic to retrieve quantity validation parameters.
app/code/Magento/CatalogInventory/Block/Plugin/ProductView.php Updated plugin to use the new QuantityValidator.
app/code/Magento/CatalogInventory/Test/Unit/Model/Product/QuantityValidatorTest.php Updated unit tests for the quantity validation logic.
app/code/Magento/CatalogInventory/Test/Unit/Block/Plugin/ProductViewTest.php Removed outdated test file; ensure test coverage is maintained elsewhere.
app/code/Magento/Catalog/Test/Mftf/Test/AdminAddInStockProductToTheCartTest.xml Adjusted test quantities to align with the new validation requirements.
Comments suppressed due to low confidence (2)

app/code/Magento/CatalogInventory/Test/Unit/Block/Plugin/ProductViewTest.php:1

  • [nitpick] Ensure that the removal of the ProductViewTest file does not create any gaps in test coverage for the ProductView functionality.
Entire file removed

app/code/Magento/GroupedProduct/view/frontend/templates/product/view/type/grouped.phtml:11

  • The variable '$escaper' is annotated but not initialized. Consider initializing it (e.g., via $block->getEscaper()) to avoid potential undefined variable errors.
* @var $escaper \Magento\Framework\Escaper

@@ -1643,6 +1643,9 @@ define([
isQtyIncrementsValid = typeof params.qtyIncrements === 'undefined' ||
resolveModulo(qty, $.mage.parseNumber(params.qtyIncrements)) === 0.0;

if ($(element).data('no-validation-for-zero-qty') === true && qty === 0) {
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider adding an inline comment to explain the purpose of the 'no-validation-for-zero-qty' data attribute for future maintainability and clarity.

Copilot uses AI. Check for mistakes.

if ($stockItem->getMaxSaleQty()) {
$params['maxAllowed'] = $stockItem->getMaxSaleQty();
}
if ($stockItem->getQtyIncrements() > 0) {
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider explicitly verifying that the return value of getQtyIncrements() is numeric before performing the comparison to ensure type safety.

Suggested change
if ($stockItem->getQtyIncrements() > 0) {
if (is_numeric($stockItem->getQtyIncrements()) && $stockItem->getQtyIncrements() > 0) {

Copilot uses AI. Check for mistakes.

@engcom-Bravo
Copy link
Contributor

Hi @Mohamed-Asar,

Thanks for your Contribution!!.

Could you please resolve the Conflicts to proceed further.

Thanks.

@engcom-Bravo engcom-Bravo moved this from Ready for Testing to Changes Requested in Community Dashboard May 28, 2025
@Mohamed-Asar
Copy link
Contributor Author

@engcom-Bravo I fixed the conflicts, please check

@engcom-Hotel
Copy link
Contributor

@magento run all tests

@ct-prd-projects-boards-automation ct-prd-projects-boards-automation bot moved this from Review in Progress to Ready for Testing in Community Dashboard May 29, 2025
@engcom-Bravo engcom-Bravo self-assigned this May 30, 2025
@engcom-Bravo engcom-Bravo moved this from Ready for Testing to Testing in Progress in Community Dashboard May 30, 2025
@engcom-Bravo
Copy link
Contributor

engcom-Bravo commented May 30, 2025

Hi @Mohamed-Asar,

Thanks for the collaboration & contribution!

✔️ QA Passed

Preconditions:

  • Install fresh Magento 2.4-develop

Steps to reproduce

  • Create a Grouped Product and associate it with child products.

  • Set the following quantity properties for one of the child products:

    • Minimum Qty Allowed in Shopping Cart: 2
    • Maximum Qty Allowed in Shopping Cart: 10
    • Qty Increments: 2
  • .Open the Product Detail Page (PDP) of the Grouped Product and test invalid quantities for the selected child product (e.g., 1, 3, or 11) to confirm that invalid inputs are restricted.

Before: ✖️ 

Screenshot 2025-05-30 at 12 13 47 pm Screenshot 2025-05-30 at 12 18 42 pm

After: ✔️

Screenshot 2025-05-30 at 1 50 03 pm Screenshot 2025-05-30 at 1 52 18 pm

Builds are failed. Hence, moving this PR to Extended Testing.

Thanks.

@engcom-Bravo engcom-Bravo moved this from Testing in Progress to Extended testing (optional) in Community Dashboard May 30, 2025
@engcom-Dash engcom-Dash self-assigned this May 30, 2025
@engcom-Dash
Copy link
Contributor

@magento run all tests

@engcom-Dash
Copy link
Contributor

@magento run all tests

@engcom-Dash
Copy link
Contributor

@magento run Functional Tests B2B, Functional Tests CE, Functional Tests EE, Static Tests, Unit Tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Partner: Ziffity partners-contribution Pull Request is created by Magento Partner Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: ready for testing Project: Community Picked PRs upvoted by the community
Projects
Status: Extended testing (optional)
Development

Successfully merging this pull request may close these issues.

7 participants