Skip to content

Commit e2e8bd2

Browse files
author
Serhiy Shkolyarenko
committed
Merge remote-tracking branch 'mainline/develop' into bugs
2 parents 5dd556a + fb909a9 commit e2e8bd2

File tree

104 files changed

+2188
-632
lines changed

Some content is hidden

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

104 files changed

+2188
-632
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: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

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/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/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:

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ class Product extends AbstractResource
6666
*/
6767
protected $defaultAttributes;
6868

69+
/**
70+
* @var array
71+
*/
72+
protected $availableCategoryIdsCache = [];
73+
6974
/**
7075
* @param \Magento\Eav\Model\Entity\Context $context
7176
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
@@ -465,18 +470,22 @@ public function getAvailableInCategories($object)
465470
{
466471
// is_parent=1 ensures that we'll get only category IDs those are direct parents of the product, instead of
467472
// fetching all parent IDs, including those are higher on the tree
468-
$select = $this->getConnection()->select()->distinct()->from(
469-
$this->getTable('catalog_category_product_index'),
470-
['category_id']
471-
)->where(
472-
'product_id = ? AND is_parent = 1',
473-
(int)$object->getEntityId()
474-
)->where(
475-
'visibility != ?',
476-
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE
477-
);
478-
479-
return $this->getConnection()->fetchCol($select);
473+
$entityId = (int)$object->getEntityId();
474+
if (!isset($this->availableCategoryIdsCache[$entityId])) {
475+
$this->availableCategoryIdsCache[$entityId] = $this->getConnection()->fetchCol(
476+
$this->getConnection()->select()->distinct()->from(
477+
$this->getTable('catalog_category_product_index'),
478+
['category_id']
479+
)->where(
480+
'product_id = ? AND is_parent = 1',
481+
$entityId
482+
)->where(
483+
'visibility != ?',
484+
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE
485+
)
486+
);
487+
}
488+
return $this->availableCategoryIdsCache[$entityId];
480489
}
481490

482491
/**
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Plugin\Model\Attribute\Backend;
7+
8+
class AttributeValidation
9+
{
10+
/**
11+
* @param \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject
12+
* @param \Closure $proceed
13+
* @param \Magento\Framework\DataObject $attribute
14+
* @return bool
15+
*/
16+
public function aroundValidate(
17+
\Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject,
18+
\Closure $proceed,
19+
\Magento\Framework\DataObject $attribute
20+
) {
21+
$useDefault = $attribute->getUseDefault();
22+
$attrCode = $subject->getAttribute()->getAttributeCode();
23+
if ($useDefault && isset($useDefault[$attrCode])) {
24+
return true;
25+
}
26+
return $proceed($attribute);
27+
}
28+
}

app/code/Magento/Catalog/Test/Unit/Model/Category/Attribute/Backend/SortbyTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ public function beforeSaveDataProvider()
9191
'attribute does not exist' => [
9292
self::DEFAULT_ATTRIBUTE_CODE,
9393
[],
94-
false,
94+
null,
9595
],
9696
'attribute sort by empty' => [
9797
'available_sort_by',
9898
['available_sort_by' => null],
99-
'',
99+
null,
100100
],
101101
'attribute sort by' => [
102102
'available_sort_by',

0 commit comments

Comments
 (0)