-
Notifications
You must be signed in to change notification settings - Fork 256
magento/magento2#38154: Getting success message after sending invalid SKU for the inventory/source-items API #3448
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: develop
Are you sure you want to change the base?
Conversation
… SKU for the inventory/source-items API - added validation for existing SKUs on request processing
|
@magento run all tests |
engcom-Hotel
left a comment
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.
… SKU for the inventory/source-items API - reverted copyright change - added $productRepository initialisation via Object Manager if null
|
@magento run all tests |
engcom-Hotel
left a comment
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.
Thank you @MaximLogic for making the changes!
It seems some automated tests are failing due to the PR changes, please fix those.
Description (*)
According to issue magento/magento2#38154, the
/rest/V1/inventory/source-itemsPOST API endpoint was accepting requests with non-existent SKUs and returning 200 OK status code without any validation errors. InInventory\Model\SourceItem\Validator\SkuValidator, validation only checked if SKU is not empty and doesn't have leading/trailing spaces, but didn't verify if a product with that SKU actually exists in the catalog.I've added
validateSkuExists()method intoInventory\Model\SourceItem\Validator\SkuValidator, that tries to load product by given SKU,and in case of failure, it catchesNoSuchEntityExceptionand returns validation error "Product with SKU <given_sku> does not exist."Fixed Issues (if relevant)
Prerequisites: Have Magento installed with magento/inventory-metapackage and at least one product in store (e.g., SKU "24-MB01")
Manual testing scenarios (*)
Expected result: API returns 400 Bad Request status, Error message:
{"message":"Validation Failed","errors":[{"message":"Product with SKU \"sfasdfasd\" does not exist.","parameters":[]}]}Contribution checklist (*)