diff --git a/app/code/Magento/Catalog/Model/ProductRepository.php b/app/code/Magento/Catalog/Model/ProductRepository.php index fefeafe46e1c4..fcb3c89711452 100644 --- a/app/code/Magento/Catalog/Model/ProductRepository.php +++ b/app/code/Magento/Catalog/Model/ProductRepository.php @@ -10,6 +10,7 @@ use Magento\Catalog\Api\Data\ProductExtension; use Magento\Catalog\Api\Data\ProductInterface; use Magento\Catalog\Model\Product\Gallery\MimeTypeExtensionMap; +use Magento\Catalog\Model\Product\Type; use Magento\Catalog\Model\ProductRepository\MediaGalleryProcessor; use Magento\Catalog\Model\ResourceModel\Product\Collection; use Magento\Eav\Model\Entity\Attribute\Exception as AttributeException; @@ -28,6 +29,7 @@ use Magento\Framework\Exception\StateException; use Magento\Framework\Exception\TemporaryState\CouldNotSaveException as TemporaryCouldNotSaveException; use Magento\Framework\Exception\ValidatorException; +use Magento\Catalog\Api\ProductRepositoryInterface; /** * @inheritdoc @@ -35,7 +37,7 @@ * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.TooManyFields) */ -class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterface +class ProductRepository implements ProductRepositoryInterface { /** * @var \Magento\Catalog\Api\ProductCustomOptionRepositoryInterface @@ -534,6 +536,10 @@ public function save(ProductInterface $product, $saveOptions = false) } } catch (NoSuchEntityException $e) { $existingProduct = null; + + if ($product->getTypeId() === null) { + $product->setTypeId(Type::DEFAULT_TYPE); + } } $productDataArray = $this->extensibleDataObjectConverter @@ -737,6 +743,7 @@ private function getMediaGalleryProcessor() private function getCollectionProcessor() { if (!$this->collectionProcessor) { + // phpstan:ignore ProductCollectionProcessor not found. $this->collectionProcessor = \Magento\Framework\App\ObjectManager::getInstance()->get( // phpstan:ignore "Class Magento\Catalog\Model\Api\SearchCriteria\ProductCollectionProcessor not found." \Magento\Catalog\Model\Api\SearchCriteria\ProductCollectionProcessor::class diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php index 1fcfe79f39478..80c55d8dae579 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php @@ -34,6 +34,7 @@ * * @magentoAppIsolation enabled * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) */ class ProductRepositoryInterfaceTest extends WebapiAbstract { @@ -210,6 +211,7 @@ public function productCreationProvider() */ private function loadWebsiteByCode($websiteCode) { + $website = null; $websiteRepository = Bootstrap::getObjectManager()->get(WebsiteRepository::class); try { $website = $websiteRepository->get($websiteCode); @@ -381,6 +383,21 @@ public function testCreate($product) $this->deleteProduct($product[ProductInterface::SKU]); } + /** + * Verify that product creation is success with type_id null + * + * @dataProvider productCreationProvider + */ + public function testSaveProductWithNonExistType($product): void + { + $product[ProductInterface::TYPE_ID] = null; + $response = $this->saveProduct($product); + $this->assertArrayHasKey(ProductInterface::PRICE, $response); + $this->assertArrayHasKey(ProductInterface::TYPE_ID, $response); + $this->assertArrayHasKey(ProductInterface::VISIBILITY, $response); + $this->deleteProduct($product[ProductInterface::SKU]); + } + /** * @param array $fixtureProduct * diff --git a/setup/performance-toolkit/benchmark.jmx b/setup/performance-toolkit/benchmark.jmx index fef19b05deafd..3b2c995a7b77f 100644 --- a/setup/performance-toolkit/benchmark.jmx +++ b/setup/performance-toolkit/benchmark.jmx @@ -26774,7 +26774,8 @@ if (testLabel "product": { "sku": "psku-test-${__time()}-${__threadNum}-${__Random(1,1000000)}", "name": "Product_${__time()}-${__threadNum}-${__Random(1,1000000)}", - "attributeSetId": 4 + "attributeSetId": 4, + "price": "3.62" } } =