- 
                Notifications
    You must be signed in to change notification settings 
- Fork 9.4k
12073: ProductRepository fails to load product with camelcase SKU #12169
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
          
     Closed
      
      
    
  
     Closed
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            36 changes: 36 additions & 0 deletions
          
          36 
        
  dev/tests/integration/testsuite/Magento/Catalog/Model/ProductRepositoryTest.php
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
|  | ||
| namespace Magento\Catalog\Model; | ||
|  | ||
| use Magento\TestFramework\Helper\Bootstrap; | ||
|  | ||
| /** | ||
| * Test for Magento\Catalog\Model\ProductRepository | ||
| */ | ||
| class ProductRepositoryTest extends \PHPUnit\Framework\TestCase | ||
| { | ||
| /** | ||
| * @var ProductRepository | ||
| */ | ||
| protected $model; | ||
|  | ||
| protected function setUp() | ||
| { | ||
| $this->model = Bootstrap::getObjectManager()->create(ProductRepository::class); | ||
| } | ||
|  | ||
| /** | ||
| * @magentoDataFixture Magento/Catalog/_files/product_simple_camel_case_sku.php | ||
| * @expectedException \Magento\Framework\Exception\NoSuchEntityException | ||
| */ | ||
| public function testGet() | ||
| { | ||
| $product = $this->model->get('camelcaseproduct'); | ||
|  | ||
| $this->assertEquals('CamelCaseProduct', $product->getSku()); | ||
| } | ||
| } | 
        
          
          
            42 changes: 42 additions & 0 deletions
          
          42 
        
  dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_camel_case_sku.php
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
|  | ||
| \Magento\TestFramework\Helper\Bootstrap::getInstance()->reinitialize(); | ||
|  | ||
| /** @var \Magento\TestFramework\ObjectManager $objectManager */ | ||
| $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); | ||
|  | ||
| /** @var $product \Magento\Catalog\Model\Product */ | ||
| $product = $objectManager->create(\Magento\Catalog\Model\Product::class); | ||
| $product->isObjectNew(true); | ||
| $product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) | ||
| ->setId(1) | ||
| ->setAttributeSetId(4) | ||
| ->setWebsiteIds([1]) | ||
| ->setName('Simple Product') | ||
| ->setSku('CamelCaseProduct') | ||
| ->setPrice(10) | ||
| ->setWeight(1) | ||
| ->setShortDescription("Short description") | ||
| ->setTaxClassId(0) | ||
| ->setDescription('Description with <b>html tag</b>') | ||
| ->setMetaTitle('meta title') | ||
| ->setMetaKeyword('meta keyword') | ||
| ->setMetaDescription('meta description') | ||
| ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH) | ||
| ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) | ||
| ->setStockData( | ||
| [ | ||
| 'use_config_manage_stock' => 1, | ||
| 'qty' => 100, | ||
| 'is_qty_decimal' => 0, | ||
| 'is_in_stock' => 1, | ||
| ] | ||
| ); | ||
|  | ||
| /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepositoryFactory */ | ||
| $productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); | ||
| $productRepository->save($product); | 
        
          
          
            26 changes: 26 additions & 0 deletions
          
          26 
        
  ...s/integration/testsuite/Magento/Catalog/_files/product_simple_camel_case_sku_rollback.php
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
|  | ||
| use Magento\Framework\Exception\NoSuchEntityException; | ||
|  | ||
| \Magento\TestFramework\Helper\Bootstrap::getInstance()->getInstance()->reinitialize(); | ||
|  | ||
| /** @var \Magento\Framework\Registry $registry */ | ||
| $registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class); | ||
|  | ||
| $registry->unregister('isSecureArea'); | ||
| $registry->register('isSecureArea', true); | ||
|  | ||
| /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ | ||
| $productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() | ||
| ->get(\Magento\Catalog\Api\ProductRepositoryInterface::class); | ||
| try { | ||
| $product = $productRepository->get('CamelCaseProduct', false, null, true); | ||
| $productRepository->delete($product); | ||
| } catch (NoSuchEntityException $e) { | ||
| } | ||
| $registry->unregister('isSecureArea'); | ||
| $registry->register('isSecureArea', false); | 
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
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 code completely duplicates previous condition.
What is this issue all about? I see a
trimbut don't see anystrtolowerin logic like$this->instances[$product->getSku()][$cacheKey] = $product;.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.
@orlangur, ok, let me explain. We have product with sku "Test". We try to use "get" method of repository to get product with sku "test". Method resourceModel->getIdBySku($sku) will return to us id of "Test" and in $this->instances it put the sku "Test". So after trim we are checking if we have $this->instances["test"] and we don't have it, because we have $this->instances["Test"].
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.
How? https://3v4l.org/smbkn
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.
@orlangur, what how? Trimming isn't my logic). It was before my changes. I only check if product sku("Test") is the same as requested sku("test"). And if it isn't the same exception will be thrown.
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.
Ok, let me reword. Why product is stored with lower-cased SKU in the first place?
We must find a root cause so that exception will be thrown from line 240 instead of adding more exceptions throwing.