Skip to content

Commit a54e648

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-58393' into BUGS
2 parents 1535e70 + 929967e commit a54e648

File tree

2 files changed

+49
-16
lines changed

2 files changed

+49
-16
lines changed

app/code/Magento/ConfigurableProduct/Model/Product/VariationHandler.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,14 @@ protected function fillSimpleProductData(
148148
\Magento\Catalog\Model\Product $parentProduct,
149149
$postData
150150
) {
151+
$typeId = isset($postData['weight']) && !empty($postData['weight'])
152+
? ProductType::TYPE_SIMPLE
153+
: ProductType::TYPE_VIRTUAL;
154+
151155
$product->setStoreId(
152156
\Magento\Store\Model\Store::DEFAULT_STORE_ID
153157
)->setTypeId(
154-
$postData['weight'] ? ProductType::TYPE_SIMPLE : ProductType::TYPE_VIRTUAL
158+
$typeId
155159
)->setAttributeSetId(
156160
$parentProduct->getNewVariationsAttributeSetId()
157161
);

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/VariationHandlerTest.php

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Magento\ConfigurableProduct\Test\Unit\Model\Product;
1010

11+
use Magento\Catalog\Model\Product\Type;
1112
use Magento\ConfigurableProduct\Model\Product\VariationHandler;
1213

1314
/**
@@ -162,23 +163,30 @@ public function testPrepareAttributeSet()
162163

163164
/**
164165
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
166+
* @dataProvider dataProviderTestGenerateSimpleProducts
167+
* @param int|string|null $weight
168+
* @param string $typeId
165169
*/
166-
public function testGenerateSimpleProducts()
170+
public function testGenerateSimpleProducts($weight, $typeId)
167171
{
168172
$productsData = [
169-
6 =>
170-
[
171-
'image' => 'image.jpg',
172-
'name' => 'config-red',
173-
'configurable_attribute' => '{"new_attr":"6"}',
174-
'sku' => 'config-red',
175-
'quantity_and_stock_status' =>
176-
[
177-
'qty' => '',
178-
],
179-
'weight' => '333',
180-
]
173+
[
174+
'image' => 'image.jpg',
175+
'name' => 'config-red',
176+
'configurable_attribute' => '{"new_attr":"6"}',
177+
'sku' => 'config-red',
178+
'quantity_and_stock_status' =>
179+
[
180+
'qty' => '',
181+
],
182+
]
181183
];
184+
185+
// Do not add 'weight' attribute if it's value is null!
186+
if ($weight !== null) {
187+
$productsData[0]['weight'] = $weight;
188+
}
189+
182190
$stockData = [
183191
'manage_stock' => '0',
184192
'use_config_enable_qty_increments' => '1',
@@ -218,7 +226,7 @@ public function testGenerateSimpleProducts()
218226
)
219227
->disableOriginalConstructor()
220228
->getMock();
221-
$productTypeMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Type::class)
229+
$productTypeMock = $this->getMockBuilder(Type::class)
222230
->setMethods(['getSetAttributes'])
223231
->disableOriginalConstructor()
224232
->getMock();
@@ -236,7 +244,7 @@ public function testGenerateSimpleProducts()
236244
->willReturn('new_attr_set_id');
237245
$this->productFactoryMock->expects($this->once())->method('create')->willReturn($newSimpleProductMock);
238246
$newSimpleProductMock->expects($this->once())->method('setStoreId')->with(0)->willReturnSelf();
239-
$newSimpleProductMock->expects($this->once())->method('setTypeId')->with('simple')->willReturnSelf();
247+
$newSimpleProductMock->expects($this->once())->method('setTypeId')->with($typeId)->willReturnSelf();
240248
$newSimpleProductMock->expects($this->once())
241249
->method('setAttributeSetId')
242250
->with('new_attr_set_id')
@@ -265,6 +273,27 @@ public function testGenerateSimpleProducts()
265273
$this->assertEquals(['product_id'], $this->model->generateSimpleProducts($parentProductMock, $productsData));
266274
}
267275

276+
/**
277+
* @return array
278+
*/
279+
public function dataProviderTestGenerateSimpleProducts()
280+
{
281+
return [
282+
[
283+
'weight' => 333,
284+
'type_id' => Type::TYPE_SIMPLE,
285+
],
286+
[
287+
'weight' => '',
288+
'type_id' => Type::TYPE_VIRTUAL,
289+
],
290+
[
291+
'weight' => null,
292+
'type_id' => Type::TYPE_VIRTUAL,
293+
],
294+
];
295+
}
296+
268297
public function testProcessMediaGalleryWithImagesAndGallery()
269298
{
270299
$this->product->expects($this->atLeastOnce())->method('getMediaGallery')->with('images')->willReturn([]);

0 commit comments

Comments
 (0)