cannot fix/save sku of product with trailing space
- Dominant language
- PHP
- Stars
- 357
- Forks
- 262
- PR merge metrics
- No merged PRs in 30d
Description
### Preconditions (*)
1. magento 2.4.7-p2
2. magento/inventory-metapackage 1.2.7-p2
3. magento/module-inventory 1.2.5
### Steps to reproduce (*)
The issue happens when you already have products pre-existing before the magento inventory leading/trailing space validation check.
The validation system doesn't allow you to change/fix product skus with pre-existing products with space characters.
1. disable/comment out the validation check in `Model/Validators/NoSpaceBeforeAndAfterString.php`
2. create a product with trailing space character
3. re-enable the validation check in `Model/Validators/NoSpaceBeforeAndAfterString.php`
4. try to modify/remove the space from the sku of the product and save
### Expected result (*)
1. expecting successful product save
2. successfully able to change the leading/trailing space characters
### Actual result (*)
While saving you see the error: `The stock item was unable to be saved. Please try again.`
In the logs this error comes up: `Validation Failed: "sku" can not contain leading or trailing spaces.`
Contributor guide
Research direction
Start with Model/Validators/NoSpaceBeforeAndAfterString.php and reproduce the issue using the listed Magento Inventory versions: create a SKU with a trailing space while validation is disabled, then re-enable it and save after removing the space. Done means the existing product can be saved with its SKU corrected and the validation error no longer blocks the save.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100