-
Notifications
You must be signed in to change notification settings - Fork 9.4k
12073 product repo get different sku case #14019
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
12073 product repo get different sku case #14019
Conversation
- Then use lowercase sku in get() method which references the instances array via array key this way we make sure no matter which case is used to get the product we get it correctly - This makes sense as the DB is case insensitive but the PHP is not and currently would throw undefined index if trying to get product with sku: test and passing tESt to get()
|
Hi @josh-carter, putting this PR on hold as hope to get fix done in scope of #12169 (slightly different approach: product is cached exactly with the same SKU how it was requested instead of |
|
@orlangur Ok cool, my thoughts would be, it saves multiple loading of the same product and keeps functionality correct. |
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.
Hi @josh-carter, let's continue in this PR :)
Please rework implementation of cacheProduct in cb3b5d1#diff-ff4893a5628d34910295bae32fbcddfdL241 so that code behavior remain unchanged.
Just change implementation of cacheProduct in such a way that we pass both productId and sku instead of obtaining them from product instance.
Another case is that MySQL does not distinguish not just lower/upper case but also е and ё, o and ö, a and ã and so on. Thus there is no need to complicate implementation with strtolower or other approaches for key normalization.
|
@orlangur Ok that's cool with me. I'll get it updated and get this ready for review. |
- Lets us pass the searched for SKU and use as instance key
- This is no longer called everytime we call the get() method because we pass the sku searched for when using the cacheProduct method()
- New line at end of ProductRepository - Remove unused local variable in ProductRepositoryTest
| * @return void | ||
| */ | ||
| private function cacheProduct($cacheKey, \Magento\Catalog\Api\Data\ProductInterface $product) | ||
| private function cacheProduct($cacheKey, \Magento\Catalog\Api\Data\ProductInterface $product, $sku = null) |
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.
See: cb3b5d1#diff-ff4893a5628d34910295bae32fbcddfdL241
Please pass productId instead of product instance in both cases. Don't add default parameter and some logic into cacheProduct, pass both product ID and SKU.
| $this->assertEquals($this->productMock, $this->model->get($sku, true)); | ||
| } | ||
|
|
||
| public function testGetBySkuWithSpace() |
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.
This test does not seem to test initial case anymore. Please change so that it actually checks trimmed SKU.
| $this->resourceModelMock->expects($this->once())->method('getIdBySku')->with($differentCasedSku) | ||
| ->will($this->returnValue('test_id')); | ||
| $this->productMock->expects($this->once())->method('load')->with('test_id'); | ||
| $this->productMock->expects($this->once())->method('getId')->willReturn('test_id'); |
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.
Same here: it looks like we don't check getting product by 'test_sku' anymore.
|
Facing this same issue. How would I go about patching a Magento 2.2.3 install to fix this? |
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.
I would suggest covering this with different type of test, for instance api-functional.
|
@josh-carter , I am closing this PR now due to inactivity. |
|
Sorry @josh-carter, my bad, I was supposed to help you with test here, I remember we started a talk in Slack. Will do it this week. |
|
@orlangur I'm reopening then, to keep track of it |
|
|
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.
Nowadays all changes must be applied to 2.3-develop first (see https://devdocs.magento.com/guides/v2.3/contributor-guide/contributing.html#rules). Please prepare a new pull request, this one should be on hold until the latter is merged.
|
Closing due to inactivity. Feel free to reach me out anytime later if you wish to continue work on this pull request and it will be reopened. |
Description
Take an example Product with SKU
test_skuIn ProductRepository currently, if we're using get() and pass the SKU
TesT_SKuwe would get an undefined index as described inside #12073.However It makes sense to be able to retrieve product using different cased SKU as the database is case insensitive and SKU is unique. But the PHP is case sensitive, therefore, to fix the problem we can lowercase the SKU in the PHP code.
Fixed Issues (if relevant)
Manual testing scenarios
test_skuProductRepository::get('tESt_sKu')Contribution checklist