-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
base: 2.4-develop
Are you sure you want to change the base?
Grouped product frontend quantity validation added and code refactor #39480
Conversation
Hi @Mohamed-Asar. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
@magento run all tests. |
Failed to run the builds. Please try to re-run them later. |
@magento run all tests |
…into bug/39479-grouped-product-qty-validation
…thub.com/Mohamed-Asar/magento2 into bug/39479-grouped-product-qty-validation
@magento run all tests |
…into bug/39479-grouped-product-qty-validation
@magento run all tests |
@magento run all tests |
@magento run all tests |
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
if ($stockItem->getQtyIncrements() > 0) { | |
if (is_numeric($stockItem->getQtyIncrements()) && $stockItem->getQtyIncrements() > 0) { |
Copilot uses AI. Check for mistakes.
Hi @Mohamed-Asar, Thanks for your Contribution!!. Could you please resolve the Conflicts to proceed further. Thanks. |
@engcom-Bravo I fixed the conflicts, please check |
@magento run all tests |
Hi @Mohamed-Asar, Thanks for the collaboration & contribution! ✔️ QA PassedPreconditions:
Steps to reproduce
Before: ✖️ ![]() ![]() After: ✔️ ![]() ![]() Builds are failed. Hence, moving this PR to Extended Testing. Thanks. |
@magento run all tests |
@magento run all tests |
@magento run Functional Tests B2B, Functional Tests CE, Functional Tests EE, Static Tests, Unit Tests |
Description (*)
Grouped Product Frontend Quantity validation added
Related Pull Requests
Fixed Issues (if relevant)
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 (*)