Skip to content

Commit 17881e4

Browse files
author
Olexandr Lysenko
committed
Merge branch 'develop' into MAGETWO-58237
2 parents 0bc3a16 + 73bf648 commit 17881e4

File tree

95 files changed

+4388
-955
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+4388
-955
lines changed

app/code/Magento/Backend/etc/adminhtml/system.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
<resource>Magento_Config::config_general</resource>
199199
<group id="country" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
200200
<label>Country Options</label>
201-
<field id="allow" translate="label" type="multiselect" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
201+
<field id="allow" translate="label" type="multiselect" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
202202
<label>Allow Countries</label>
203203
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
204204
<can_be_empty>1</can_be_empty>

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Categories;
99
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
1010
use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection;
11+
use Magento\Framework\App\CacheInterface;
1112
use Magento\Framework\DB\Helper as DbHelper;
1213
use Magento\Framework\UrlInterface;
1314
use Magento\Store\Model\Store;
@@ -112,4 +113,38 @@ public function testModifyMeta()
112113

113114
$this->assertArrayHasKey($groupCode, $this->getModel()->modifyMeta($meta));
114115
}
116+
117+
public function testModifyMetaWithCaching()
118+
{
119+
$this->arrayManagerMock->expects($this->exactly(2))
120+
->method('findPath')
121+
->willReturn(true);
122+
$cacheManager = $this->getMockBuilder(CacheInterface::class)
123+
->getMockForAbstractClass();
124+
$cacheManager->expects($this->once())
125+
->method('load')
126+
->with(Categories::CATEGORY_TREE_ID . '_');
127+
$cacheManager->expects($this->once())
128+
->method('save');
129+
130+
$modifier = $this->createModel();
131+
$cacheContextProperty = new \ReflectionProperty(
132+
Categories::class,
133+
'cacheManager'
134+
);
135+
$cacheContextProperty->setAccessible(true);
136+
$cacheContextProperty->setValue($modifier, $cacheManager);
137+
138+
$groupCode = 'test_group_code';
139+
$meta = [
140+
$groupCode => [
141+
'children' => [
142+
'category_ids' => [
143+
'sortOrder' => 10,
144+
],
145+
],
146+
],
147+
];
148+
$modifier->modifyMeta($meta);
149+
}
115150
}

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,25 @@
77

88
use Magento\Catalog\Model\Locator\LocatorInterface;
99
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\App\CacheInterface;
1012
use Magento\Framework\DB\Helper as DbHelper;
1113
use Magento\Catalog\Model\Category as CategoryModel;
1214
use Magento\Framework\UrlInterface;
1315
use Magento\Framework\Stdlib\ArrayManager;
1416

1517
/**
1618
* Data provider for categories field of product page
19+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1720
*/
1821
class Categories extends AbstractModifier
1922
{
23+
/**#@+
24+
* Category tree cache id
25+
*/
26+
const CATEGORY_TREE_ID = 'CATALOG_PRODUCT_CATEGORY_TREE';
27+
/**#@-*/
28+
2029
/**
2130
* @var CategoryCollectionFactory
2231
*/
@@ -29,6 +38,7 @@ class Categories extends AbstractModifier
2938

3039
/**
3140
* @var array
41+
* @deprecated
3242
*/
3343
protected $categoriesTrees = [];
3444

@@ -47,6 +57,11 @@ class Categories extends AbstractModifier
4757
*/
4858
protected $arrayManager;
4959

60+
/**
61+
* @var CacheInterface
62+
*/
63+
private $cacheManager;
64+
5065
/**
5166
* @param LocatorInterface $locator
5267
* @param CategoryCollectionFactory $categoryCollectionFactory
@@ -68,6 +83,21 @@ public function __construct(
6883
$this->arrayManager = $arrayManager;
6984
}
7085

86+
/**
87+
* Retrieve cache interface
88+
*
89+
* @return CacheInterface
90+
* @deprecated
91+
*/
92+
private function getCacheManager()
93+
{
94+
if (!$this->cacheManager) {
95+
$this->cacheManager = ObjectManager::getInstance()
96+
->get(CacheInterface::class);
97+
}
98+
return $this->cacheManager;
99+
}
100+
71101
/**
72102
* {@inheritdoc}
73103
*/
@@ -254,8 +284,9 @@ protected function customizeCategoriesField(array $meta)
254284
*/
255285
protected function getCategoriesTree($filter = null)
256286
{
257-
if (isset($this->categoriesTrees[$filter])) {
258-
return $this->categoriesTrees[$filter];
287+
$categoryTree = $this->getCacheManager()->load(self::CATEGORY_TREE_ID . '_' . $filter);
288+
if ($categoryTree) {
289+
return unserialize($categoryTree);
259290
}
260291

261292
$storeId = $this->locator->getStore()->getId();
@@ -307,9 +338,16 @@ protected function getCategoriesTree($filter = null)
307338
$categoryById[$category->getId()]['label'] = $category->getName();
308339
$categoryById[$category->getParentId()]['optgroup'][] = &$categoryById[$category->getId()];
309340
}
341+
342+
$this->getCacheManager()->save(
343+
serialize($categoryById[CategoryModel::TREE_ROOT_ID]['optgroup']),
344+
self::CATEGORY_TREE_ID . '_' . $filter,
345+
[
346+
\Magento\Catalog\Model\Category::CACHE_TAG,
347+
\Magento\Framework\App\Cache\Type\Block::CACHE_TAG
348+
]
349+
);
310350

311-
$this->categoriesTrees[$filter] = $categoryById[CategoryModel::TREE_ROOT_ID]['optgroup'];
312-
313-
return $this->categoriesTrees[$filter];
351+
return $categoryById[CategoryModel::TREE_ROOT_ID]['optgroup'];
314352
}
315353
}

app/code/Magento/Catalog/view/frontend/templates/product/widget/link/link_inline.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
// @codingStandardsIgnoreFile
88
?>
9-
<div class="widget block block-product-link-inline">
9+
<span class="widget block block-product-link-inline">
1010
<a <?php /* @escapeNotVerified */ echo $block->getLinkAttributes() ?>><span><?php echo $block->escapeHtml($block->getLabel()) ?></span></a>
11-
</div>
11+
</span>

app/code/Magento/Cms/view/frontend/templates/widget/link/link_inline.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* See COPYING.txt for license details.
55
*/
66
?>
7-
<div class="widget block block-cms-link-inline">
7+
<span class="widget block block-cms-link-inline">
88
<a <?php /* @escapeNotVerified */ echo $block->getLinkAttributes() ?>>
99
<span><?php echo $block->escapeHtml($block->getLabel()) ?></span>
1010
</a>
11-
</div>
11+
</span>

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)