Skip to content
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

cannot fix/save sku of product with trailing space #3413

Open
medigeek opened this issue Aug 27, 2024 · 2 comments
Open

cannot fix/save sku of product with trailing space #3413

medigeek opened this issue Aug 27, 2024 · 2 comments

Comments

@medigeek
Copy link
Member

medigeek commented Aug 27, 2024

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.

Copy link

m2-assistant bot commented Aug 27, 2024

Hi @medigeek. Thank you for your report.
To speed up processing of this issue, make sure that you provided sufficient information.
Add a comment to assign the issue: @magento I am working on this


Join Magento Community Engineering Slack and ask your questions in #github channel.

@medigeek medigeek changed the title cannot save/modify sku of product with trailing space cannot fix/save sku of product with trailing space Aug 27, 2024
@kulwinders433
Copy link

kulwinders433 commented Sep 19, 2024

Add this code in NoSpaceBeforeAndAfterString.php file

if ($trimValue !== $value) {
$errors[] = __('"%field" can not contain leading or trailing spaces.', ['field' => $fieldName]);

    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants