Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/code/Magento/Catalog/Model/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,14 +29,15 @@
use Magento\Framework\Exception\StateException;
use Magento\Framework\Exception\TemporaryState\CouldNotSaveException as TemporaryCouldNotSaveException;
use Magento\Framework\Exception\ValidatorException;
use Magento\Catalog\Api\ProductRepositoryInterface;

/**
* @inheritdoc
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyFields)
*/
class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterface
class ProductRepository implements ProductRepositoryInterface
{
/**
* @var \Magento\Catalog\Api\ProductCustomOptionRepositoryInterface
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*
* @magentoAppIsolation enabled
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class ProductRepositoryInterfaceTest extends WebapiAbstract
{
Expand Down Expand Up @@ -210,6 +211,7 @@ public function productCreationProvider()
*/
private function loadWebsiteByCode($websiteCode)
{
$website = null;
$websiteRepository = Bootstrap::getObjectManager()->get(WebsiteRepository::class);
try {
$website = $websiteRepository->get($websiteCode);
Expand Down Expand Up @@ -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
*
Expand Down
3 changes: 2 additions & 1 deletion setup/performance-toolkit/benchmark.jmx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
Expand Down