Skip to content

Commit 0cc3120

Browse files
author
Oleksii Korshenko
committed
Merge remote-tracking branch 'swat/pr_branch' into mainline-develop
2 parents 5b00736 + dd944ce commit 0cc3120

File tree

10 files changed

+95
-53
lines changed

10 files changed

+95
-53
lines changed

app/code/Magento/CatalogImportExport/Model/Export/Product.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
8585
*/
8686
protected $_indexValueAttributes = [
8787
'status',
88-
'gift_message_available',
8988
];
9089

9190
/**

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
196196
protected $_indexValueAttributes = [
197197
'status',
198198
'tax_class_id',
199-
'gift_message_available',
200199
];
201200

202201
/**

app/code/Magento/CatalogWidget/Block/Product/ProductsList.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88

99
namespace Magento\CatalogWidget\Block\Product;
1010

11+
use Magento\Framework\DataObject\IdentityInterface;
12+
use Magento\Widget\Block\BlockInterface;
13+
1114
/**
1215
* Catalog Products List widget block
1316
* Class ProductsList
1417
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1518
*/
16-
class ProductsList extends \Magento\Catalog\Block\Product\AbstractProduct implements \Magento\Widget\Block\BlockInterface
19+
class ProductsList extends \Magento\Catalog\Block\Product\AbstractProduct implements BlockInterface, IdentityInterface
1720
{
1821
/**
1922
* Default value for products count that will be shown
@@ -327,7 +330,16 @@ public function getPagerHtml()
327330
*/
328331
public function getIdentities()
329332
{
330-
return [\Magento\Catalog\Model\Product::CACHE_TAG];
333+
$identities = [];
334+
if ($this->getProductCollection()) {
335+
foreach ($this->getProductCollection() as $product) {
336+
if ($product instanceof IdentityInterface) {
337+
$identities = array_merge($identities, $product->getIdentities());
338+
}
339+
}
340+
}
341+
342+
return $identities ?: [\Magento\Catalog\Model\Product::CACHE_TAG];
331343
}
332344

333345
/**

app/code/Magento/CatalogWidget/Test/Unit/Block/Product/ProductsListTest.php

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -261,21 +261,10 @@ public function testCreateCollection($pagerEnable, $productsCount, $productsPerP
261261
$this->collectionFactory->expects($this->once())->method('create')->willReturn($collection);
262262
$this->productsList->setData('conditions_encoded', 'some_serialized_conditions');
263263

264-
$conditions = $this->getMockBuilder('\Magento\Rule\Model\Condition\Combine')
265-
->setMethods(['collectValidatedAttributes'])
266-
->disableOriginalConstructor()
267-
->getMock();
268-
$conditions->expects($this->once())->method('collectValidatedAttributes')
269-
->with($collection)
270-
->willReturnSelf();
271-
272264
$this->builder->expects($this->once())->method('attachConditionToCollection')
273-
->with($collection, $conditions)
265+
->with($collection, $this->getConditionsForCollection($collection))
274266
->willReturnSelf();
275267

276-
$this->rule->expects($this->once())->method('loadPost')->willReturnSelf();
277-
$this->rule->expects($this->once())->method('getConditions')->willReturn($conditions);
278-
279268
if ($productsPerPage) {
280269
$this->productsList->setData('products_per_page', $productsPerPage);
281270
} else {
@@ -333,7 +322,44 @@ public function testShowPager()
333322

334323
public function testGetIdentities()
335324
{
336-
$this->assertEquals([\Magento\Catalog\Model\Product::CACHE_TAG], $this->productsList->getIdentities());
325+
$collection = $this->getMockBuilder('\Magento\Catalog\Model\ResourceModel\Product\Collection')
326+
->setMethods([
327+
'addAttributeToSelect',
328+
'getIterator',
329+
])->disableOriginalConstructor()
330+
->getMock();
331+
332+
$product = $this->getMock('Magento\Framework\DataObject\IdentityInterface', ['getIdentities']);
333+
$notProduct = $this->getMock('NotProduct', ['getIdentities']);
334+
$product->expects($this->once())->method('getIdentities')->willReturn(['product_identity']);
335+
$collection->expects($this->once())->method('getIterator')->willReturn(
336+
new \ArrayIterator([$product, $notProduct])
337+
);
338+
$this->productsList->setData('product_collection', $collection);
339+
340+
$this->assertEquals(
341+
['product_identity'],
342+
$this->productsList->getIdentities()
343+
);
344+
}
345+
346+
/**
347+
* @param $collection
348+
* @return \PHPUnit_Framework_MockObject_MockObject
349+
*/
350+
private function getConditionsForCollection($collection)
351+
{
352+
$conditions = $this->getMockBuilder('\Magento\Rule\Model\Condition\Combine')
353+
->setMethods(['collectValidatedAttributes'])
354+
->disableOriginalConstructor()
355+
->getMock();
356+
$conditions->expects($this->once())->method('collectValidatedAttributes')
357+
->with($collection)
358+
->willReturnSelf();
359+
360+
$this->rule->expects($this->once())->method('loadPost')->willReturnSelf();
361+
$this->rule->expects($this->once())->method('getConditions')->willReturn($conditions);
362+
return $conditions;
337363
}
338364

339365
public function testGetTitle()

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();

app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/steps/summary.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ define([
8181
options: options,
8282
images: images,
8383
sku: sku,
84+
name: sku,
8485
quantity: quantity,
8586
price: price,
8687
productId: productId,
@@ -91,6 +92,7 @@ define([
9192
if (productId) {
9293
variation.sku = product.sku;
9394
variation.weight = product.weight;
95+
variation.name = product.name;
9496
gridExisting.push(this.prepareRowForGrid(variation));
9597
} else {
9698
gridNew.push(this.prepareRowForGrid(variation));

app/code/Magento/GiftMessage/Setup/InstallData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
9494
'label' => 'Allow Gift Message',
9595
'input' => 'select',
9696
'class' => '',
97-
'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
97+
'source' => 'Magento\Catalog\Model\Product\Attribute\Source\Boolean',
9898
'global' => true,
9999
'visible' => true,
100100
'required' => false,

app/code/Magento/GiftMessage/Setup/UpgradeData.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,20 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
3535
{
3636
$setup->startSetup();
3737

38+
/** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */
39+
$categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
40+
$entityTypeId = $categorySetup->getEntityTypeId(Product::ENTITY);
41+
$attributeSetId = $categorySetup->getAttributeSetId($entityTypeId, 'Default');
42+
$attribute = $categorySetup->getAttribute($entityTypeId, 'gift_message_available');
43+
3844
if (version_compare($context->getVersion(), '2.0.1', '<')) {
39-
/** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */
40-
$categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
45+
4146
$groupName = 'Gift Options';
4247

4348
if (!$categorySetup->getAttributeGroup(Product::ENTITY, 'Default', $groupName)) {
4449
$categorySetup->addAttributeGroup(Product::ENTITY, 'Default', $groupName, 60);
4550
}
4651

47-
$entityTypeId = $categorySetup->getEntityTypeId(Product::ENTITY);
48-
$attributeSetId = $categorySetup->getAttributeSetId($entityTypeId, 'Default');
49-
$attribute = $categorySetup->getAttribute($entityTypeId, 'gift_message_available');
50-
5152
$categorySetup->addAttributeToGroup(
5253
$entityTypeId,
5354
$attributeSetId,
@@ -57,6 +58,16 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
5758
);
5859
}
5960

61+
if (version_compare($context->getVersion(), '2.1.0', '<')) {
62+
63+
$categorySetup->updateAttribute(
64+
$entityTypeId,
65+
$attribute['attribute_id'],
66+
'source_model',
67+
'Magento\Catalog\Model\Product\Attribute\Source\Boolean'
68+
);
69+
}
70+
6071
$setup->endSetup();
6172
}
6273
}

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)