-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Grouped product frontend quantity validation added and code refactor #39480
Open
Mohamed-Asar
wants to merge
11
commits into
magento:2.4-develop
Choose a base branch
from
Mohamed-Asar:bug/39479-grouped-product-qty-validation
base: 2.4-develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+175
−55
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f990b58
Grouped product frontend quantity validation added and code refactor
Mohamed-Asar 5f2b740
Merge branch '2.4-develop' into bug/39479-grouped-product-qty-validation
Mohamed-Asar 52bd8e8
Merge branch '2.4-develop' of https://github.com/Mohamed-Asar/magento…
Mohamed-Asar 94fadc8
Ignore item qty validation if zero qty entered in grouped product
Mohamed-Asar 9ac7ef5
Merge branch 'bug/39479-grouped-product-qty-validation' of https://gi…
Mohamed-Asar eea8ae5
Merge branch '2.4-develop' of https://github.com/Mohamed-Asar/magento…
Mohamed-Asar a192377
Unit test & static test cases issues fixed
Mohamed-Asar ceb8597
Static test fixed
Mohamed-Asar 3e0c5a7
Indent issue fixed
Mohamed-Asar 4213997
Merge branch '2.4-develop' into bug/39479-grouped-product-qty-validation
engcom-Hotel 1ca6c6d
Code review changes
Mohamed-Asar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
app/code/Magento/CatalogInventory/Model/Product/QuantityValidator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* Copyright 2024 Adobe | ||
* All Rights Reserved. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogInventory\Model\Product; | ||
|
||
use Magento\CatalogInventory\Api\StockRegistryInterface; | ||
|
||
class QuantityValidator | ||
{ | ||
/** | ||
* @param StockRegistryInterface $stockRegistry | ||
*/ | ||
public function __construct( | ||
private readonly StockRegistryInterface $stockRegistry | ||
) { | ||
} | ||
|
||
/** | ||
* To get quantity validators | ||
* | ||
* @param int $productId | ||
* @param int|null $websiteId | ||
* | ||
* @return array | ||
*/ | ||
public function getData(int $productId, int|null $websiteId): array | ||
{ | ||
$stockItem = $this->stockRegistry->getStockItem($productId, $websiteId); | ||
|
||
$params = []; | ||
$validators = []; | ||
$params['minAllowed'] = $stockItem->getMinSaleQty(); | ||
if ($stockItem->getMaxSaleQty()) { | ||
$params['maxAllowed'] = $stockItem->getMaxSaleQty(); | ||
} | ||
if ($stockItem->getQtyIncrements() > 0) { | ||
$params['qtyIncrements'] = (float) $stockItem->getQtyIncrements(); | ||
} | ||
$validators['validate-item-quantity'] = $params; | ||
|
||
return $validators; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
app/code/Magento/GroupedProduct/ViewModel/ValidateQuantity.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Copyright 2024 Adobe | ||
* All Rights Reserved. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\GroupedProduct\ViewModel; | ||
|
||
use Magento\CatalogInventory\Model\Product\QuantityValidator; | ||
use Magento\Framework\Serialize\Serializer\Json; | ||
use Magento\Framework\View\Element\Block\ArgumentInterface; | ||
|
||
/** | ||
* ViewModel for Grouped Products Block | ||
*/ | ||
class ValidateQuantity implements ArgumentInterface | ||
{ | ||
/** | ||
* @param Json $serializer | ||
* @param QuantityValidator $productQuantityValidator | ||
*/ | ||
public function __construct( | ||
private readonly Json $serializer, | ||
private readonly QuantityValidator $productQuantityValidator, | ||
) { | ||
} | ||
|
||
/** | ||
* To get the quantity validators | ||
* | ||
* @param int $productId | ||
* @param int|null $websiteId | ||
* | ||
* @return string | ||
*/ | ||
public function getQuantityValidators(int $productId, int|null $websiteId): string | ||
{ | ||
return $this->serializer->serialize( | ||
array_merge( | ||
['validate-grouped-qty' => '#super-product-table'], | ||
$this->productQuantityValidator->getData($productId, $websiteId) | ||
) | ||
); | ||
} | ||
} |
14 changes: 9 additions & 5 deletions
14
app/code/Magento/GroupedProduct/view/frontend/layout/catalog_product_view_type_grouped.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 7 additions & 3 deletions
10
app/code/Magento/Wishlist/view/frontend/layout/wishlist_index_configure_type_grouped.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
interface StockRegistryInterface has been deprecated. Please use alternate.
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.
@engcom-Hotel The alternative for that interface is the MSI module. However, some users might have the MSI module disabled, can i use that ?
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.
Yes @Mohamed-Asar you can use that. BTW its not recommended to disable the MSI module.
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.
@engcom-Hotel MSI module is not included in this repo. how do i proceed ?
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.
Please refer to this repo: https://github.com/magento/inventory