Repository navigation
Conversation
|
Hi @shin4141. 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. |
| */ | ||
| public function validateEntityValue(object $entity, string $propertyName, $value): void | ||
| { | ||
| if ($entity instanceof CartItemInterface |
There was a problem hiding this comment.
it's probably safer to check item against \Magento\Quote\Model\Quote\Item\AbstractItem as multishipping carts may accept address items that do not implement CartItemInterface
|
Thanks for pointing out the address item type. The proposed follow-up checks both |
|
@magento run all tests |
| <type name="Magento\Framework\Webapi\Validator\CompositeServiceInputValidator"> | ||
| <arguments> | ||
| <argument name="validators" xsi:type="array"> | ||
| <item name="cartItemQtyValidator" xsi:type="object">Magento\Quote\Model\Webapi\CartItemQtyValidator</item> |
There was a problem hiding this comment.
this area config will remove validators registered by global di.xml
worth take that into account as was done in this PR: https://github.com/magento/magento2/pull/40742/changes where all validators were moved to module level global area
| sortOrder="100" /> | ||
| </type> | ||
| <type name="Magento\Framework\Webapi\Validator\CompositeServiceInputValidator"> | ||
| <plugin name="cartItemQtyValidator" type="Magento\Quote\Model\Webapi\CartItemQtyValidator" /> |
There was a problem hiding this comment.
To clarify my earlier comment, I meant following the relocation used in merged #40742, rather than introducing a plugin around the composite.
Please move the existing entityArrayValidator and searchCriteriaValidator registrations from app/etc/di.xml into Magento_Webapi/etc/di.xml
Then register cartItemQtyValidator through the validators argument in Magento_Quote/etc/di.xml.
All entries would then merge at the module-global stage.
| * @return void | ||
| * @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
| */ | ||
| public function beforeValidateEntityValue( |
There was a problem hiding this comment.
Please remove the plugin registration and beforeValidateEntityValue(), keeping the class as a validator implementation as mentioned in previous comment.
|
@magento run all tests |
|
@magento run WebAPI Tests |
There was a problem hiding this comment.
The fix rejects non-positive quantities
Baseline a385d02 / PR changes 6ea04c8, independently installed
With a salable simple product and a fresh guest cart, POST quantities 0 and -2, then check persisted items; use a separate positive request as control:
| Supporting valid-cart check | Baseline | PR changes |
|---|---|---|
| POST 0 / -2 | Accepted; saved qty 1 | Quantity error; no item |
| POST 3 | Saved qty 3 | Saved qty 3 |
PR regression results:
Magento\Quote\Api\GuestCartItemRepositoryTest::testUpdateItemRejectsZeroQtyWithoutChangingExistingItem: baseline FAIL because no validation error occurs; PR PASS, preserving qty 3.Magento\Quote\Api\GuestCartItemRepositoryTest::testAddItemRejectsNonPositiveQty, datasetszero/negative: baseline FAIL because cart-not-found lacksqty; PR PASS (2 cases, 6 assertions).
The PR's composite checks also pass, including the existing input limits.
Description (*)
REST cart item input is validated before
Quote\Item::setQty()can normalize a non-positive value to 1. This keeps the existing quote item behavior used by other cart flows and makes invalid REST quantities return a validation error.The new REST functional cases cover guest cart POST with 0 and -2, and PUT with 0 after a successful update to quantity 3. The PUT case verifies the stored quantity remains 3.
Related Pull Requests
None.
Fixed Issues (if relevant)
Manual testing scenarios (*)
qty: 0. Expect HTTP 400 withqtyidentified as invalid, and no item added.qty: -2. Expect the same result.qty: 3, then PUT that item withqty: 0. Expect HTTP 400; GET the cart items and confirm the quantity remains 3.Tests
2.4-developat5b3d233df732d5c573cb93e78576b9b86278573d: before the change, all three invalid requests returned HTTP 200 and saved quantity 1. After the change, all three return HTTP 400; the rejected PUT leaves quantity 3.GuestCartItemRepositoryTest.php: 19 of 20 passed locally. The remaining stock fixture case expectsThere are no source items with the in stock status, while this local vanilla installation returnsProduct Simple Product One is out of stock.for its positive quantity request. This case does not exercise the new non-positive quantity validation. CI remains the authoritative check for that environment difference.Questions or comments
This addresses the reported S3 functional inconsistency. It does not change
Quote\Item::_prepareQty()or global quote item quantity semantics.Contribution checklist (*)