Skip to content
Snippets Groups Projects
Commit fa6782f3 authored by nmalevanec's avatar nmalevanec
Browse files

6486: magento/magento2#6486: Unable to save certain product properties via Rest API

parent 506d5004
Branches
No related merge requests found
......@@ -329,6 +329,9 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
unset($productData['media_gallery']);
if ($createNew) {
$product = $this->productFactory->create();
if (!isset($productData['product_type'])) {
$product->setTypeId(Product\Type::TYPE_SIMPLE);
}
if ($this->storeManager->hasSingleStore()) {
$product->setWebsiteIds([$this->storeManager->getStore(true)->getWebsiteId()]);
}
......
......@@ -303,6 +303,32 @@ class ProductRepositoryInterfaceTest extends WebapiAbstract
}
}
/**
* Test that Product Repository can correctly create simple product, if product type not specified in request.
*
* @return void
*/
public function testCreateWithoutSpecifiedType()
{
$price = 3.62;
$weight = 12.2;
$sku = 'simple_product_without_specified_type';
$product = [
'sku' => '' . $sku . '',
'name' => 'Simple Product Without Specified Type',
'price' => $price,
'weight' => $weight,
'attribute_set_id' => 4,
];
$response = $this->saveProduct($product);
$this->assertSame($sku, $response[ProductInterface::SKU]);
$this->assertSame(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE, $response[ProductInterface::TYPE_ID]);
$this->assertSame($price, $response[ProductInterface::PRICE]);
$this->assertSame($weight, $response[ProductInterface::WEIGHT]);
//Clean up.
$this->deleteProduct($product[ProductInterface::SKU]);
}
/**
* @param array $fixtureProduct
*
......
......@@ -49,4 +49,25 @@ class ProductRepositoryTest extends \PHPUnit\Framework\TestCase
$updatedProduct->load($productId);
self::assertSame($newSku, $updatedProduct->getSku());
}
/**
* Check Product Repository able to correctly create product without specified type.
*
* @magentoDbIsolation enabled
*/
public function testCreateWithoutSpecifiedType()
{
/** @var Product $product */
$product = Bootstrap::getObjectManager()->get(ProductFactory::class)->create();
$product->setName('Simple without specified type');
$product->setSku('simple_without_specified_type');
$product->setPrice(1.12);
$product->setWeight(1.23);
$product->setAttributeSetId(4);
$product = $this->productRepository->save($product);
self::assertSame('1.1200', $product->getPrice());
self::assertSame('1.2300', $product->getWeight());
self::assertSame('simple', $product->getTypeId());
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment