-
Notifications
You must be signed in to change notification settings - Fork 29
Duplicate SKU possible if importing products #37
Comments
From @koenner01 on June 29, 2017 14:11 Probably related magento/magento2#8235 |
From @OleksandrBurianyk on July 7, 2017 11:17 Thx for your reporting. We've created intenal ticket MAGETWO-70528 |
Hi @piotrekkaminski and @dmanners I tested this issue in current 2.3-develop. After the 2nd reproduce step I don't get an error. Instead I get a message saying that Magento appended a "-1" at the end of the sku. The same happens after reproduce step 8 (appends a "-2"). However, when you import the product as indicated in the reproduce steps, you end up with 2 different products with the same SKU. Since Magento's behavior when creating the product manually is to append a "-1", should the import process do the same? Or should it throw an error not allowing to save the product as indicated in the description? |
@federivo thank you for looking into this. My gut feeling would be that the admin and import should behave in the same way so that it does not cause confusion for the user. This being said I am open to discussion from @piotrekkaminski and @PieterCappelle on this matter and would be interested to see what the others would think. |
After the great investigation @federivo would you consider taking this on as your first task in this project? Of course with my help when you need it. |
@dmanners sure! |
In my opinion the SKU should never be changed automatic. 99% of all imports are connected with SAP or ERP. When you edit SKU you lose the connection with SAP or ERP. A space is also a character. It's bad, yes. I hate it. But it's a character. Just like SKU "ABCDEF" is possible should The behaviour inside admin is also wrong in my opinion. When you create product with existing SKU Magento should throw exception in frontend and tell you to edit the SKU. Just my 2 cents of course :) |
Hi there, I would recommend to throw an exception and display to the user that a SKU with the same name already exists. |
@PieterCappelle and @pointia thank you for the feedback on this issue. |
For reference, this is the email I sent to the import/export project team, trying to clarify what the next steps should be: =========== Hi all! These are the problems I found and the next steps I think we should take to move this forward. Problem 1 - The import process allows you to create products with leading and trailing spaces but the admin panel does not. This leads to issues like:
Problem 2 - Import process and admin panel have different behavior. Having the import process behave in a way and the admin save process behave differently is confusing and causes issues like the ones described above. We agreed in our weekly calls that it would make more sense to have both processes behave the same regarding sku management. If Magento agreees with this statement, we need help in making a decision on which way would be the most convenient (to allow leading and trailing spaces in skus or not).
Problem 3 - Admin panel save process modifies the sku when the desired sku is already in use. As commented above, when you enter an sku that already exists in DB in the create product section, Magento appends a dash + a sequence number calculated to be unique. Per our weekly meetings, this seems to be an odd behavior causing unexpected data saved in the DB. Our thesis is that it would be better to validate uniqueness and present an error message back to the user. Next steps:
I hope this clarifies a bit the big picture. Happy to hear feedback on the diagnostic as well as the next steps to get to a resolution. |
Per Feb 16 import/export meeting - We identified 2 issues that have been raised by this:
Should the import process behave the same as the product creation in admin panel? Decision: Yes. Should Magento allow leading/trailing spaces? Decision: Yes, they are valid characters and after discussing the decision is that Magento should accept them as valid characters in SKUs.
Magento modifies the SKU when it detects that you are trying to save an already existing SKU. It will append a "-1" to the SKU to preserve uniqueness. We discussed and agreed that this behavior should be changed so the user is notified of the repeated SKU. @dmanners said that he will talk this through with a Magento product owner. This part was moved to a separate issue: #101 |
@piotrekkaminski could you have a look through the point 2 of the comment from @federivo .
|
For reference: @piotrekkaminski agreed that when trying to save an existing sku in the admin panel, the desired behavior is to return an error to the user instead of modifying the sku to be unique |
Update zend-soap to the version that supports PHP 7.2 - ver. 2.7.0 composer.lock already has zend-soap in version 2.7.0, this information was missing in composer.json.
…pgrade Update zend-soap #37
@springerin has agreed to help out with this task, while we figure out what to do with her current task. Work to be done here is as follows. SKUs and leading/trailing spaces Should the import process behave the same as the product creation in admin panel? Decision: Yes. Should Magento allow leading/trailing spaces? Decision: Yes, they are valid characters and after discussing the decision is that Magento should accept them as valid characters in SKUs. At the end of this task leading and trailing spaces should be allowed for a sku via the admin, import, and API processes. |
Hello. |
Hello. In our quest for SKU happiness I've been doing some testing. Here's what I've found so far: TESTS:
Then Edit "ABC" and change just something like the description. A Save will append a "-1" to the end of the SKU.
Reason: The product being updated has a lower entity_id and Magento's checkAttributeUniqueValue will find this first and assume it's fine.
Reason: The product being updated has a higher entity_id and Magento's checkAttributeUniqueValue will find the other first and return false = not unique. EXAMINING in more detail Test 10 above: SELECT This will return both entity_id's because mySQL strips out trailing spaces when using the = comparison operator. The first entity_id returned matches the current product being saved so it accepts it as okay. But we know the current SKU in the DB is "DEF " and FINDINGS: SELECT This will also return a SKU with 'DEF ' because mySQL strips out trailing spaces. Oops!
POSSIBLE SOLUTIONS: a) checkAttributeUniqueValue (Eav/Model/Entity/AbstractEntity.php) Inside if ($attributeBackend->getType() === 'static') {
->where('length(' . $attribute->getAttributeCode() . ') = :length') I'm not sure what affect this will have on all other static attribute checks though. Does SKU need to have it's own special entity check function? Worth discussing in next meeting. NEXT UP:
We need to return a failure if another exact SKU has been found. Magento Ref: the desired behavior is to return an error to the user instead of modifying the sku to be unique. Thanks, |
From our meeting today David quite rightly pointed out that in POSSIBLE SOLUTIONS above, the LIKE comparison operator may also solve our problem: a) In checkAttributeUniqueValue (Eav/Model/Entity/AbstractEntity.php) we have this query example: SELECT catalog_product_entity.entity_id FROM catalog_product_entity WHERE (sku like 'DEF ') I've just done some tests and it works well. SKU happiness is very much heading down it's own path in terms of uniqueness and not sure it quite fits into the generic checkAttributeUniqueValue in AbstractEntity.php anymore. Thanks, |
MAGETWO-91762: [Magento Cloud] - MYSQL Message queue is fetching mess…
to fix thi issue just replace function protected function _generateUniqueSku($object) with protected function _generateUniqueSku($object)
inside file vendor/magento/module-catalog/Model/Product/Attribute/Backend/Sku.php |
From @pointia on June 28, 2017 8:10
It is possible in Magento to save a product with a sku that has a leading or trailing whitespace. This can lead to duplicate skus when you import products without the leading or trailing slash.
Preconditions
Steps to reproduce
Expected result
Actual result
Copied from original issue: magento/magento2#10080
Per Feb 16 import/export meeting:
SKUs and leading/trailing spaces
We will make the necessary changes to allow leading and trailing spaces in SKUs in the product edit section of the admin panel. This way Magento won't update the incorrect product when having 2 SKUs like "ABC" and "ABC ".
The text was updated successfully, but these errors were encountered: