Skip to content

Commit 792e1f3

Browse files
committed
Merge branch 'MAGETWO-54257' into pr_branch
2 parents 2e511ed + e8b279c commit 792e1f3

File tree

3 files changed

+22
-29
lines changed

3 files changed

+22
-29
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ class VariationHandler
2929
/** @var \Magento\Catalog\Model\ProductFactory */
3030
protected $productFactory;
3131

32-
/** @var \Magento\CatalogInventory\Api\StockConfigurationInterface */
32+
/**
33+
* @var \Magento\CatalogInventory\Api\StockConfigurationInterface
34+
* @deprecated
35+
*/
3336
protected $stockConfiguration;
3437

3538
/**
@@ -168,14 +171,10 @@ protected function fillSimpleProductData(
168171

169172
$keysFilter = ['item_id', 'product_id', 'stock_id', 'type_id', 'website_id'];
170173
$postData['stock_data'] = array_diff_key((array)$parentProduct->getStockData(), array_flip($keysFilter));
171-
$postData['stock_data']['manage_stock'] = $postData['quantity_and_stock_status']['qty'] === '' ? 0 : 1;
172174
if (!isset($postData['stock_data']['is_in_stock'])) {
173175
$stockStatus = $parentProduct->getQuantityAndStockStatus();
174176
$postData['stock_data']['is_in_stock'] = $stockStatus['is_in_stock'];
175177
}
176-
$configDefaultValue = $this->stockConfiguration->getManageStock($product->getStoreId());
177-
$postData['stock_data']['use_config_manage_stock'] = $postData['stock_data']['manage_stock'] ==
178-
$configDefaultValue ? 1 : 0;
179178
$postData = $this->processMediaGallery($product, $postData);
180179
$postData['status'] = isset($postData['status'])
181180
? $postData['status']

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,6 @@ public function testGenerateSimpleProducts()
254254
$parentProductMock->expects($this->once())
255255
->method('getQuantityAndStockStatus')
256256
->willReturn(['is_in_stock' => 1]);
257-
$newSimpleProductMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
258-
$this->stockConfiguration->expects($this->once())
259-
->method('getManageStock')
260-
->with('store_id')
261-
->willReturn(1);
262257
$newSimpleProductMock->expects($this->once())->method('addData')->willReturnSelf();
263258
$parentProductMock->expects($this->once())->method('getWebsiteIds')->willReturn('website_id');
264259
$newSimpleProductMock->expects($this->once())->method('setWebsiteIds')->with('website_id')->willReturnSelf();

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/VariationHandlerTest.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,36 @@
88

99
namespace Magento\ConfigurableProduct\Model\Product;
1010

11+
use Magento\TestFramework\Helper\Bootstrap;
12+
1113
/**
1214
* @magentoAppIsolation enabled
1315
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
1416
*/
1517
class VariationHandlerTest extends \PHPUnit_Framework_TestCase
1618
{
17-
/**
18-
* Object under test
19-
*
20-
* @var \Magento\ConfigurableProduct\Model\Product\VariationHandler
21-
*/
22-
protected $_model;
19+
/** @var \Magento\ConfigurableProduct\Model\Product\VariationHandler */
20+
private $_model;
2321

24-
/**
25-
* @var \Magento\Catalog\Model\Product
26-
*/
27-
protected $_product;
22+
/** @var \Magento\Catalog\Model\Product */
23+
private $_product;
24+
25+
/** @var \Magento\CatalogInventory\Api\StockRegistryInterface */
26+
private $stockRegistry;
2827

2928
protected function setUp()
3029
{
31-
$this->_product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
30+
$this->_product = Bootstrap::getObjectManager()->create(
3231
'Magento\Catalog\Model\Product'
3332
);
3433
$this->_product->load(1);
35-
// fixture
3634

37-
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
35+
$this->_model = Bootstrap::getObjectManager()->create(
3836
'Magento\ConfigurableProduct\Model\Product\VariationHandler'
3937
);
4038
// prevent fatal errors by assigning proper "singleton" of type instance to the product
4139
$this->_product->setTypeInstance($this->_model);
40+
$this->stockRegistry = Bootstrap::getObjectManager()->get('Magento\CatalogInventory\Api\StockRegistryInterface');
4241
}
4342

4443
/**
@@ -52,15 +51,17 @@ public function testGenerateSimpleProducts($productsData)
5251
$generatedProducts = $this->_model->generateSimpleProducts($this->_product, $productsData);
5352
$this->assertEquals(3, count($generatedProducts));
5453
foreach ($generatedProducts as $productId) {
54+
$stockItem = $this->stockRegistry->getStockItem($productId);
5555
/** @var $product \Magento\Catalog\Model\Product */
56-
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
56+
$product = Bootstrap::getObjectManager()->create(
5757
'Magento\Catalog\Model\Product'
5858
);
5959
$product->load($productId);
6060
$this->assertNotNull($product->getName());
6161
$this->assertNotNull($product->getSku());
6262
$this->assertNotNull($product->getPrice());
6363
$this->assertNotNull($product->getWeight());
64+
$this->assertEquals('1', $stockItem->getIsInStock());
6465
}
6566
}
6667

@@ -71,14 +72,12 @@ public function testGenerateSimpleProducts($productsData)
7172
*/
7273
public function testGenerateSimpleProductsWithPartialData($productsData)
7374
{
74-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
75-
/** @var \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry */
76-
$stockRegistry = $objectManager->get('Magento\CatalogInventory\Api\StockRegistryInterface');
7775
$this->_product->setNewVariationsAttributeSetId(4);
7876
$generatedProducts = $this->_model->generateSimpleProducts($this->_product, $productsData);
77+
$parentStockItem = $this->stockRegistry->getStockItem($this->_product->getId());
7978
foreach ($generatedProducts as $productId) {
80-
$stockItem = $stockRegistry->getStockItem($productId);
81-
$this->assertEquals('0', $stockItem->getManageStock());
79+
$stockItem = $this->stockRegistry->getStockItem($productId);
80+
$this->assertEquals($parentStockItem->getManageStock(), $stockItem->getManageStock());
8281
$this->assertEquals('1', $stockItem->getIsInStock());
8382
}
8483
}

0 commit comments

Comments
 (0)