diff --git a/InventoryCatalog/Model/ResourceModel/GetProductTypesBySkus.php b/InventoryCatalog/Model/ResourceModel/GetProductTypesBySkus.php index bfafd5710318..7a3db5c4e765 100644 --- a/InventoryCatalog/Model/ResourceModel/GetProductTypesBySkus.php +++ b/InventoryCatalog/Model/ResourceModel/GetProductTypesBySkus.php @@ -66,7 +66,7 @@ public function execute(array $skus): array */ private function getResultKey(string $sku, array $productSkuList): string { - $key = array_search(strtolower($sku), array_map('strtolower', $productSkuList)); + $key = array_search(strtolower($sku), array_map('strtolower', $productSkuList), true); if ($key !== false) { $sku = (string)$productSkuList[$key]; } diff --git a/InventoryCatalog/Test/Integration/GetProductTypesBySkusTest.php b/InventoryCatalog/Test/Integration/GetProductTypesBySkusTest.php index 0e196a477041..b87010663b56 100644 --- a/InventoryCatalog/Test/Integration/GetProductTypesBySkusTest.php +++ b/InventoryCatalog/Test/Integration/GetProductTypesBySkusTest.php @@ -7,6 +7,8 @@ namespace Magento\InventoryCatalog\Test\Integration; +use Magento\InventoryCatalog\Model\Cache\ProductTypesBySkusStorage; +use Magento\InventoryCatalog\Model\ResourceModel\GetProductTypesBySkus; use Magento\InventoryCatalogApi\Model\GetProductTypesBySkusInterface; use Magento\TestFramework\Helper\Bootstrap; use PHPUnit\Framework\TestCase; @@ -21,6 +23,11 @@ class GetProductTypesBySkusTest extends TestCase */ private $getProductTypesBySkus; + /** + * @var ProductTypesBySkusStorage + */ + private $productTypesBySkuCacheStorage; + /** * @inheritdoc */ @@ -29,6 +36,7 @@ protected function setUp(): void parent::setUp(); $this->getProductTypesBySkus = Bootstrap::getObjectManager()->get(GetProductTypesBySkusInterface::class); + $this->productTypesBySkuCacheStorage = Bootstrap::getObjectManager()->get(ProductTypesBySkusStorage::class); } /** @@ -57,4 +65,23 @@ public function testExecuteWithNotExistedSkus() self::assertEquals(['simple_sku' => 'simple'], $this->getProductTypesBySkus->execute($skus)); } + + /** + * @magentoDataFixture Magento_InventoryCatalog::Test/_files/products_types_numeric_skus.php + */ + public function testExecuteWithSimilairNumericSkus() + { + $skus = ['35.420', '35.4200', '35.42000']; + + $expectedOutput = [ + '35.420' => 'bundle', + '35.4200' => 'configurable', + '35.42000' => 'downloadable' + ]; + + // Clean cache so the product types come from GetProductTypesBySkus directly + $this->productTypesBySkuCacheStorage->clean(); + + self::assertEquals($expectedOutput, $this->getProductTypesBySkus->execute($skus)); + } } diff --git a/InventoryCatalog/Test/_files/products_types_numeric_skus.php b/InventoryCatalog/Test/_files/products_types_numeric_skus.php new file mode 100644 index 000000000000..401d445b9469 --- /dev/null +++ b/InventoryCatalog/Test/_files/products_types_numeric_skus.php @@ -0,0 +1,55 @@ +get(ProductRepositoryInterface::class); +/** @var ProductInterfaceFactory $productFactory */ +$productFactory = $objectManager->get(ProductInterfaceFactory::class); + +$productTypes = [ + Bundle::TYPE_CODE => ['price_view' => 1, 'price_type' => Price::PRICE_TYPE_FIXED], + Configurable::TYPE_CODE => [], + Downloadable::TYPE_DOWNLOADABLE => [], + Grouped::TYPE_CODE => [], + Simple::TYPE_SIMPLE => [], + Simple::TYPE_VIRTUAL => [], +]; + +$i = 1; +foreach ($productTypes as $productType => $additionalProductData) { + $attrProductData = [ + 'attribute_set_id' => 4, + 'type_id' => $productType, + 'name' => $productType . '_name', + 'sku' => '35.42' . str_repeat('0', $i), + 'price' => 10, + 'visibility' => Visibility::VISIBILITY_BOTH, + 'status' => Status::STATUS_ENABLED, + ]; + + if (!empty($additionalProductData)) { + $attrProductData = array_merge($attrProductData, $additionalProductData); + } + + /** @var $product ProductInterface */ + $product = $productFactory->create(['data' => $attrProductData]); + $productRepository->save($product); + $i++; +} diff --git a/InventoryCatalog/Test/_files/products_types_numeric_skus_rollback.php b/InventoryCatalog/Test/_files/products_types_numeric_skus_rollback.php new file mode 100644 index 000000000000..c098fafcd7de --- /dev/null +++ b/InventoryCatalog/Test/_files/products_types_numeric_skus_rollback.php @@ -0,0 +1,43 @@ +get(Registry::class); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + +/** @var ProductRepositoryInterface $productRepository */ +$productRepository = $objectManager->get(ProductRepositoryInterface::class); +/** @var SearchCriteriaBuilder $searchCriteriaBuilder */ +$searchCriteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class); + +$searchCriteria = $searchCriteriaBuilder->addFilter('sku', '35.42%', 'like')->create(); +$searchResults = $productRepository->getList($searchCriteria); + +foreach ($searchResults->getItems() as $product) { + try { + $productRepository->delete($product); + } catch (NoSuchEntityException $exception) { + //Product already removed + } +} + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false);