Skip to content

Commit 6f634d2

Browse files
committed
Merge branch 'develop' of github.corp.magento.com:magento2/magento2ce into MAGETWO-47395
2 parents 2b342c7 + 02b9466 commit 6f634d2

File tree

119 files changed

+2398
-753
lines changed

Some content is hidden

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

119 files changed

+2398
-753
lines changed

app/code/Magento/Backend/view/adminhtml/templates/system/search.phtml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,19 @@
2727
</form>
2828
<script data-template="search-suggest" type="text/x-magento-template">
2929
<ul class="search-global-menu">
30-
<% if (data.items.length) { %>
30+
<li class="item">
31+
<a href="<?php /* @escapeNotVerified */ echo $block->getURL('catalog/product/index/'); ?>?search=<%- data.term%>" class="title">"<%- data.term%>" in Products</a>
32+
</li>
33+
<li class="item">
34+
<a href="<?php /* @escapeNotVerified */ echo $block->getURL('sales/order/index/'); ?>?search=<%- data.term%>" class="title">"<%- data.term%>" in Orders</a>
35+
</li>
36+
<li class="item">
37+
<a href="<?php /* @escapeNotVerified */ echo $block->getURL('customer/index/index/'); ?>?search=<%- data.term%>" class="title">"<%- data.term%>" in Customers</a>
38+
</li>
39+
<li class="item">
40+
<a href="<?php /* @escapeNotVerified */ echo $block->getURL('cms/page/index/'); ?>?search=<%- data.term%>" class="title">"<%- data.term%>" in Pages</a>
41+
</li>
42+
<% if (data.items.length) { %>
3143
<% _.each(data.items, function(value){ %>
3244
<li class="item"
3345
<%- data.optionData(value) %>

app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function execute()
100100

101101
$data['general'] = $this->getRequest()->getPostValue();
102102
$isNewCategory = !isset($data['general']['entity_id']);
103-
$data = $this->stringToBoolConverting($this->stringToBoolInputs, $data);
103+
$data = $this->stringToBoolConverting($data);
104104
$data = $this->imagePreprocessing($data);
105105
$storeId = isset($data['general']['store_id']) ? $data['general']['store_id'] : null;
106106
$parentId = isset($data['general']['parent']) ? $data['general']['parent'] : null;
@@ -121,11 +121,9 @@ public function execute()
121121
foreach ($generalPost['use_config'] as $attributeCode => $attributeValue) {
122122
if ($attributeValue) {
123123
$useConfig[] = $attributeCode;
124+
$category->setData($attributeCode, null);
124125
}
125126
}
126-
foreach ($useConfig as $attributeCode) {
127-
$category->setData($attributeCode, null);
128-
}
129127
}
130128

131129
$category->setAttributeSetId($category->getDefaultAttributeSetId());
@@ -148,7 +146,7 @@ public function execute()
148146
if (isset($generalPost['use_default']) && !empty($generalPost['use_default'])) {
149147
foreach ($generalPost['use_default'] as $attributeCode => $attributeValue) {
150148
if ($attributeValue) {
151-
$category->setData($attributeCode, false);
149+
$category->setData($attributeCode, null);
152150
}
153151
}
154152
}
@@ -234,8 +232,7 @@ public function imagePreprocessing($data)
234232
{
235233
if (!isset($_FILES) || (isset($_FILES['image']) && $_FILES['image']['name'] === '' )) {
236234
unset($data['general']['image']);
237-
if (
238-
isset($data['general']['savedImage']['delete']) &&
235+
if (isset($data['general']['savedImage']['delete']) &&
239236
$data['general']['savedImage']['delete']
240237
) {
241238
$data['general']['image']['delete'] = $data['general']['savedImage']['delete'];
@@ -247,17 +244,20 @@ public function imagePreprocessing($data)
247244
/**
248245
* Converting inputs from string to boolean
249246
*
250-
* @param array $stringToBoolInputs
251247
* @param array $data
248+
* @param array $stringToBoolInputs
252249
*
253250
* @return array
254251
*/
255-
public function stringToBoolConverting($stringToBoolInputs, $data)
252+
public function stringToBoolConverting($data, $stringToBoolInputs = null)
256253
{
254+
if (null === $stringToBoolInputs) {
255+
$stringToBoolInputs = $this->stringToBoolInputs;
256+
}
257257
foreach ($stringToBoolInputs as $key => $value) {
258258
if (is_array($value)) {
259259
if (isset($data[$key])) {
260-
$data[$key] = $this->stringToBoolConverting($value, $data[$key]);
260+
$data[$key] = $this->stringToBoolConverting($data[$key], $value);
261261
}
262262
} else {
263263
if (isset($data[$value])) {

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function initialize(\Magento\Catalog\Model\Product $product)
160160

161161
foreach ($useDefaults as $attributeCode => $useDefaultState) {
162162
if ($useDefaultState) {
163-
$product->setData($attributeCode, false);
163+
$product->setData($attributeCode, null);
164164
}
165165
}
166166

app/code/Magento/Catalog/Model/Category.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,9 @@ public function getStoreIds()
571571
public function getStoreId()
572572
{
573573
if ($this->hasData('store_id')) {
574-
return $this->_getData('store_id');
574+
return (int)$this->_getData('store_id');
575575
}
576-
return $this->_storeManager->getStore()->getId();
576+
return (int)$this->_storeManager->getStore()->getId();
577577
}
578578

579579
/**
@@ -1261,6 +1261,7 @@ public function toFlatArray()
12611261
}
12621262

12631263
//@codeCoverageIgnoreStart
1264+
12641265
/**
12651266
* Set parent category ID
12661267
*

app/code/Magento/Catalog/Model/Category/Attribute/Backend/Sortby.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ public function beforeSave($object)
9696
if (!is_array($data)) {
9797
$data = [];
9898
}
99-
$object->setData($attributeCode, join(',', $data));
99+
$object->setData($attributeCode, implode(',', $data) ?: null);
100100
}
101101
if (!$object->hasData($attributeCode)) {
102-
$object->setData($attributeCode, false);
102+
$object->setData($attributeCode, null);
103103
}
104104
return $this;
105105
}

app/code/Magento/Catalog/Model/Category/DataProvider.php

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
use Magento\Eav\Model\Config;
1212
use Magento\Eav\Model\Entity\Type;
1313
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
14+
use Magento\Store\Model\Store;
1415
use Magento\Store\Model\StoreManagerInterface;
1516
use Magento\Ui\Component\Form\Field;
1617
use Magento\Ui\DataProvider\EavValidationRules;
18+
use Magento\Catalog\Model\CategoryFactory;
19+
use Magento\Framework\Exception\NoSuchEntityException;
1720

1821
/**
1922
* Class DataProvider
@@ -22,6 +25,11 @@
2225
*/
2326
class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
2427
{
28+
/**
29+
* @var string
30+
*/
31+
protected $requestScopeFieldName = 'store';
32+
2533
/**
2634
* @var array
2735
*/
@@ -86,8 +94,7 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
8694
/**
8795
* @var \Magento\Framework\App\RequestInterface
8896
*/
89-
private $request;
90-
97+
protected $request;
9198

9299
/**
93100
* @var Config
@@ -100,7 +107,12 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
100107
private $storeManager;
101108

102109
/**
103-
* Constructor
110+
* @var CategoryFactory
111+
*/
112+
private $categoryFactory;
113+
114+
/**
115+
* DataProvider constructor
104116
*
105117
* @param string $name
106118
* @param string $primaryFieldName
@@ -111,9 +123,9 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
111123
* @param \Magento\Framework\Registry $registry
112124
* @param Config $eavConfig
113125
* @param \Magento\Framework\App\RequestInterface $request
126+
* @param CategoryFactory $categoryFactory
114127
* @param array $meta
115128
* @param array $data
116-
* @throws \Magento\Framework\Exception\LocalizedException
117129
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
118130
*/
119131
public function __construct(
@@ -126,6 +138,7 @@ public function __construct(
126138
\Magento\Framework\Registry $registry,
127139
Config $eavConfig,
128140
\Magento\Framework\App\RequestInterface $request,
141+
CategoryFactory $categoryFactory,
129142
array $meta = [],
130143
array $data = []
131144
) {
@@ -136,6 +149,7 @@ public function __construct(
136149
$this->registry = $registry;
137150
$this->storeManager = $storeManager;
138151
$this->request = $request;
152+
$this->categoryFactory = $categoryFactory;
139153
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
140154
$this->meta = $this->prepareMeta($this->meta);
141155
}
@@ -282,7 +296,7 @@ protected function addUseConfigSettings($categoryData)
282296
protected function addUseDefaultSettings($category, $categoryData)
283297
{
284298
if ($category->getExistsStoreValueFlag('url_key') ||
285-
$category->getStoreId() === \Magento\Store\Model\Store::DEFAULT_STORE_ID
299+
$category->getStoreId() === Store::DEFAULT_STORE_ID
286300
) {
287301
$categoryData['use_default']['url_key'] = false;
288302
} else {
@@ -296,10 +310,25 @@ protected function addUseDefaultSettings($category, $categoryData)
296310
* Get current category
297311
*
298312
* @return Category
313+
* @throws NoSuchEntityException
299314
*/
300315
public function getCurrentCategory()
301316
{
302-
return $this->registry->registry('category');
317+
$category = $this->registry->registry('category');
318+
if ($category) {
319+
return $category;
320+
}
321+
$requestId = $this->request->getParam($this->requestFieldName);
322+
$requestScope = $this->request->getParam($this->requestScopeFieldName, Store::DEFAULT_STORE_ID);
323+
if ($requestId) {
324+
$category = $this->categoryFactory->create();
325+
$category->setStoreId($requestScope);
326+
$category->load($requestId);
327+
if (!$category->getId()) {
328+
throw NoSuchEntityException::singleField('id', $requestId);
329+
}
330+
}
331+
return $category;
303332
}
304333

305334
/**
@@ -349,7 +378,6 @@ protected function filterFields($categoryData)
349378
public function getDefaultMetaData($result)
350379
{
351380
$result['parent']['default'] = (int)$this->request->getParam('parent');
352-
$result['is_anchor']['default'] = false;
353381
$result['use_config.available_sort_by']['default'] = true;
354382
$result['use_config.default_sort_by']['default'] = true;
355383
$result['use_config.filter_price_range']['default'] = true;
@@ -418,14 +446,14 @@ protected function getFieldsMap()
418446
[
419447
'custom_use_parent_settings',
420448
'custom_apply_to_products',
449+
'custom_design',
421450
'page_layout',
422451
'custom_layout_update',
423452
],
424453
'schedule_design_update' =>
425454
[
426455
'custom_design_from',
427456
'custom_design_to',
428-
'custom_design',
429457
],
430458
'category_view_optimization' =>
431459
[

app/code/Magento/Catalog/Model/CategoryRepository.php

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
use Magento\Framework\Exception\StateException;
1313
use Magento\Catalog\Api\Data\CategoryInterface;
1414

15+
/**
16+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
17+
*/
1518
class CategoryRepository implements \Magento\Catalog\Api\CategoryRepositoryInterface
1619
{
1720
/**
@@ -50,61 +53,55 @@ class CategoryRepository implements \Magento\Catalog\Api\CategoryRepositoryInter
5053
* @param \Magento\Catalog\Model\CategoryFactory $categoryFactory
5154
* @param \Magento\Catalog\Model\ResourceModel\Category $categoryResource
5255
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
56+
* @param \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter
5357
* @param \Magento\Framework\Model\Entity\MetadataPool $metadataPool
5458
*/
5559
public function __construct(
5660
\Magento\Catalog\Model\CategoryFactory $categoryFactory,
5761
\Magento\Catalog\Model\ResourceModel\Category $categoryResource,
5862
\Magento\Store\Model\StoreManagerInterface $storeManager,
59-
\Magento\Framework\Model\Entity\MetadataPool $metadataPool
63+
\Magento\Framework\Model\Entity\MetadataPool $metadataPool,
64+
\Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter
6065
) {
6166
$this->categoryFactory = $categoryFactory;
6267
$this->categoryResource = $categoryResource;
6368
$this->storeManager = $storeManager;
6469
$this->metadataPool = $metadataPool;
70+
$this->extensibleDataObjectConverter = $extensibleDataObjectConverter;
6571
}
6672

6773
/**
6874
* {@inheritdoc}
6975
*/
7076
public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)
7177
{
72-
$existingData = $category->toFlatArray();
73-
74-
/** 'available_sort_by' should be set separately because fields of array type are destroyed by toFlatArray() */
75-
$existingData['available_sort_by'] = $category->getAvailableSortBy();
78+
$storeId = (int)$this->storeManager->getStore()->getId();
79+
$existingData = $this->extensibleDataObjectConverter
80+
->toNestedArray($category, [], 'Magento\Catalog\Api\Data\CategoryInterface');
81+
$existingData = array_diff_key($existingData, array_flip(['path', 'level', 'parent_id']));
82+
$existingData['store_id'] = $storeId;
7683

7784
if ($category->getId()) {
7885
$metadata = $this->metadataPool->getMetadata(
7986
CategoryInterface::class
8087
);
8188

82-
$existingCategory = $this->get($category->getId());
83-
84-
$existingData[$metadata->getLinkField()] = $existingCategory->getData(
89+
$category = $this->get($category->getId(), $storeId);
90+
$existingData[$metadata->getLinkField()] = $category->getData(
8591
$metadata->getLinkField()
8692
);
8793

8894
if (isset($existingData['image']) && is_array($existingData['image'])) {
8995
$existingData['image_additional_data'] = $existingData['image'];
9096
unset($existingData['image']);
9197
}
92-
$existingData['id'] = $existingCategory->getId();
93-
$existingData['parent_id'] = $existingCategory->getParentId();
94-
$existingData['path'] = $existingCategory->getPath();
95-
$existingData['is_active'] = $existingCategory->getIsActive();
96-
$existingData['include_in_menu'] =
97-
isset($existingData['include_in_menu']) ? (bool)$existingData['include_in_menu'] : false;
98-
$category->setData($existingData);
9998
} else {
10099
$parentId = $category->getParentId() ?: $this->storeManager->getStore()->getRootCategoryId();
101-
$parentCategory = $this->get($parentId);
102-
$existingData['include_in_menu'] =
103-
isset($existingData['include_in_menu']) ? (bool)$existingData['include_in_menu'] : false;
104-
/** @var $category Category */
105-
$category->setData($existingData);
106-
$category->setPath($parentCategory->getPath());
100+
$parentCategory = $this->get($parentId, $storeId);
101+
$existingData['path'] = $parentCategory->getPath();
102+
$existingData['parent_id'] = $parentId;
107103
}
104+
$category->addData($existingData);
108105
try {
109106
$this->validateCategory($category);
110107
$this->categoryResource->save($category);
@@ -118,7 +115,7 @@ public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)
118115
);
119116
}
120117
unset($this->instances[$category->getId()]);
121-
return $category;
118+
return $this->get($category->getId(), $storeId);
122119
}
123120

124121
/**

app/code/Magento/Catalog/Model/ResourceModel/AbstractResource.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ protected function _isApplicableAttribute($object, $attribute)
9999
protected function _isCallableAttributeInstance($instance, $method, $args)
100100
{
101101
if ($instance instanceof \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
102-
&& ($method == 'beforeSave' || $method = 'afterSave')
102+
&& ($method == 'beforeSave' || $method == 'afterSave')
103103
) {
104104
$attributeCode = $instance->getAttribute()->getAttributeCode();
105105
if (isset($args[0]) && $args[0] instanceof \Magento\Framework\DataObject && $args[0]->getData($attributeCode) === false) {
@@ -467,19 +467,6 @@ protected function _getOrigObject($object)
467467
return $origObject;
468468
}
469469

470-
/**
471-
* Check is attribute value empty
472-
*
473-
* @param AbstractAttribute $attribute
474-
* @param mixed $value
475-
* @return bool
476-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
477-
*/
478-
protected function _isAttributeValueEmpty(AbstractAttribute $attribute, $value)
479-
{
480-
return $value === false;
481-
}
482-
483470
/**
484471
* Return if attribute exists in original data array.
485472
* Checks also attribute's store scope:

0 commit comments

Comments
 (0)