Skip to content
Snippets Groups Projects
Commit 929967e2 authored by Sergey Semenov's avatar Sergey Semenov
Browse files

MAGETWO-58393: An error occurs while saving configurable product

parent 9d0c8f9e
No related merge requests found
......@@ -148,10 +148,14 @@ class VariationHandler
\Magento\Catalog\Model\Product $parentProduct,
$postData
) {
$typeId = isset($postData['weight']) && !empty($postData['weight'])
? ProductType::TYPE_SIMPLE
: ProductType::TYPE_VIRTUAL;
$product->setStoreId(
\Magento\Store\Model\Store::DEFAULT_STORE_ID
)->setTypeId(
$postData['weight'] ? ProductType::TYPE_SIMPLE : ProductType::TYPE_VIRTUAL
$typeId
)->setAttributeSetId(
$parentProduct->getNewVariationsAttributeSetId()
);
......
......@@ -8,6 +8,7 @@
namespace Magento\ConfigurableProduct\Test\Unit\Model\Product;
use Magento\Catalog\Model\Product\Type;
use Magento\ConfigurableProduct\Model\Product\VariationHandler;
/**
......@@ -162,23 +163,30 @@ class VariationHandlerTest extends \PHPUnit_Framework_TestCase
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @dataProvider dataProviderTestGenerateSimpleProducts
* @param int|string|null $weight
* @param string $typeId
*/
public function testGenerateSimpleProducts()
public function testGenerateSimpleProducts($weight, $typeId)
{
$productsData = [
6 =>
[
'image' => 'image.jpg',
'name' => 'config-red',
'configurable_attribute' => '{"new_attr":"6"}',
'sku' => 'config-red',
'quantity_and_stock_status' =>
[
'qty' => '',
],
'weight' => '333',
]
[
'image' => 'image.jpg',
'name' => 'config-red',
'configurable_attribute' => '{"new_attr":"6"}',
'sku' => 'config-red',
'quantity_and_stock_status' =>
[
'qty' => '',
],
]
];
// Do not add 'weight' attribute if it's value is null!
if ($weight !== null) {
$productsData[0]['weight'] = $weight;
}
$stockData = [
'manage_stock' => '0',
'use_config_enable_qty_increments' => '1',
......@@ -218,7 +226,7 @@ class VariationHandlerTest extends \PHPUnit_Framework_TestCase
)
->disableOriginalConstructor()
->getMock();
$productTypeMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Type::class)
$productTypeMock = $this->getMockBuilder(Type::class)
->setMethods(['getSetAttributes'])
->disableOriginalConstructor()
->getMock();
......@@ -236,7 +244,7 @@ class VariationHandlerTest extends \PHPUnit_Framework_TestCase
->willReturn('new_attr_set_id');
$this->productFactoryMock->expects($this->once())->method('create')->willReturn($newSimpleProductMock);
$newSimpleProductMock->expects($this->once())->method('setStoreId')->with(0)->willReturnSelf();
$newSimpleProductMock->expects($this->once())->method('setTypeId')->with('simple')->willReturnSelf();
$newSimpleProductMock->expects($this->once())->method('setTypeId')->with($typeId)->willReturnSelf();
$newSimpleProductMock->expects($this->once())
->method('setAttributeSetId')
->with('new_attr_set_id')
......@@ -265,6 +273,27 @@ class VariationHandlerTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(['product_id'], $this->model->generateSimpleProducts($parentProductMock, $productsData));
}
/**
* @return array
*/
public function dataProviderTestGenerateSimpleProducts()
{
return [
[
'weight' => 333,
'type_id' => Type::TYPE_SIMPLE,
],
[
'weight' => '',
'type_id' => Type::TYPE_VIRTUAL,
],
[
'weight' => null,
'type_id' => Type::TYPE_VIRTUAL,
],
];
}
public function testProcessMediaGalleryWithImagesAndGallery()
{
$this->product->expects($this->atLeastOnce())->method('getMediaGallery')->with('images')->willReturn([]);
......
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