Skip to content

Commit 6a33737

Browse files
authored
Merge pull request #1325 from magento-south/PRS
Fixed issues: - MAGETWO-57753 [GitHub] Product attribute creation fails with REST API #6213 - MAGETWO-67444 Ensure all tools support PHP 7 type hinting required by Technical Guidelines - MAGETWO-56538 [GitHub] Minicart does not synchronise across multiple devices #5524 - MAGETWO-60339 The layered navigation does not filter products correctly, with enabled elasticsearch
2 parents 47361f8 + 4c4c62c commit 6a33737

File tree

37 files changed

+834
-194
lines changed

37 files changed

+834
-194
lines changed

app/code/Magento/Catalog/Api/Data/EavAttributeInterface.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,30 @@ public function getIsVisibleInGrid();
139139
*/
140140
public function getIsFilterableInGrid();
141141

142+
/**
143+
* Set is attribute used in grid
144+
*
145+
* @param bool|null $isUsedInGrid
146+
* @return $this
147+
*/
148+
public function setIsUsedInGrid($isUsedInGrid);
149+
150+
/**
151+
* Set is attribute visible in grid
152+
*
153+
* @param bool|null $isVisibleInGrid
154+
* @return $this
155+
*/
156+
public function setIsVisibleInGrid($isVisibleInGrid);
157+
158+
/**
159+
* Set is attribute filterable in grid
160+
*
161+
* @param bool|null $isFilterableInGrid
162+
* @return $this
163+
*/
164+
public function setIsFilterableInGrid($isFilterableInGrid);
165+
142166
/**
143167
* Set whether it is used in search results layered navigation
144168
*

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,4 +361,31 @@ public function setScope($scope)
361361
return $this;
362362
}
363363
}
364+
365+
/**
366+
* @inheritdoc
367+
*/
368+
public function setIsUsedInGrid($isUsedInGrid)
369+
{
370+
$this->setData(self::IS_USED_IN_GRID, $isUsedInGrid);
371+
return $this;
372+
}
373+
374+
/**
375+
* @inheritdoc
376+
*/
377+
public function setIsVisibleInGrid($isVisibleInGrid)
378+
{
379+
$this->setData(self::IS_VISIBLE_IN_GRID, $isVisibleInGrid);
380+
return $this;
381+
}
382+
383+
/**
384+
* @inheritdoc
385+
*/
386+
public function setIsFilterableInGrid($isFilterableInGrid)
387+
{
388+
$this->setData(self::IS_FILTERABLE_IN_GRID, $isFilterableInGrid);
389+
return $this;
390+
}
364391
}

app/code/Magento/Catalog/Model/ResourceModel/Eav/Attribute.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,4 +848,31 @@ public function __wakeup()
848848
$this->_productFlatIndexerHelper = $objectManager->get(\Magento\Catalog\Helper\Product\Flat\Indexer::class);
849849
$this->attrLockValidator = $objectManager->get(LockValidatorInterface::class);
850850
}
851+
852+
/**
853+
* @inheritdoc
854+
*/
855+
public function setIsUsedInGrid($isUsedInGrid)
856+
{
857+
$this->setData(self::IS_USED_IN_GRID, $isUsedInGrid);
858+
return $this;
859+
}
860+
861+
/**
862+
* @inheritdoc
863+
*/
864+
public function setIsVisibleInGrid($isVisibleInGrid)
865+
{
866+
$this->setData(self::IS_VISIBLE_IN_GRID, $isVisibleInGrid);
867+
return $this;
868+
}
869+
870+
/**
871+
* @inheritdoc
872+
*/
873+
public function setIsFilterableInGrid($isFilterableInGrid)
874+
{
875+
$this->setData(self::IS_FILTERABLE_IN_GRID, $isFilterableInGrid);
876+
return $this;
877+
}
851878
}

app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,20 @@ private function generateRequest($attributeType, $container, $useFulltext)
7878
if ($attribute->getData($attributeType)) {
7979
if (!in_array($attribute->getAttributeCode(), ['price', 'category_ids'], true)) {
8080
$queryName = $attribute->getAttributeCode() . '_query';
81-
8281
$request['queries'][$container]['queryReference'][] = [
83-
'clause' => 'should',
82+
'clause' => 'must',
8483
'ref' => $queryName,
8584
];
8685
$filterName = $attribute->getAttributeCode() . self::FILTER_SUFFIX;
8786
$request['queries'][$queryName] = [
8887
'name' => $queryName,
8988
'type' => QueryInterface::TYPE_FILTER,
90-
'filterReference' => [['ref' => $filterName]],
89+
'filterReference' => [
90+
[
91+
'clause' => 'must',
92+
'ref' => $filterName,
93+
]
94+
],
9195
];
9296
$bucketName = $attribute->getAttributeCode() . self::BUCKET_SUFFIX;
9397
$generator = $this->generatorResolver->getGeneratorForType($attribute->getBackendType());
@@ -100,14 +104,7 @@ private function generateRequest($attributeType, $container, $useFulltext)
100104
// Some fields have their own specific handlers
101105
continue;
102106
}
103-
104-
// Match search by custom price attribute isn't supported
105-
if ($useFulltext && $attribute->getFrontendInput() !== 'price') {
106-
$request['queries']['search']['match'][] = [
107-
'field' => $attribute->getAttributeCode(),
108-
'boost' => $attribute->getSearchWeight() ?: 1,
109-
];
110-
}
107+
$request = $this->processPriceAttribute($useFulltext, $attribute, $request);
111108
}
112109

113110
return $request;
@@ -148,10 +145,9 @@ private function generateAdvancedSearchRequest()
148145
//same fields have special semantics
149146
continue;
150147
}
151-
152148
$queryName = $attribute->getAttributeCode() . '_query';
153149
$request['queries']['advanced_search_container']['queryReference'][] = [
154-
'clause' => 'should',
150+
'clause' => 'must',
155151
'ref' => $queryName,
156152
];
157153
switch ($attribute->getBackendType()) {
@@ -164,9 +160,12 @@ private function generateAdvancedSearchRequest()
164160
$request['queries'][$queryName] = [
165161
'name' => $queryName,
166162
'type' => QueryInterface::TYPE_FILTER,
167-
'filterReference' => [['ref' => $filterName]],
163+
'filterReference' => [
164+
[
165+
'ref' => $filterName,
166+
],
167+
],
168168
];
169-
170169
$request['filters'][$filterName] = [
171170
'type' => FilterInterface::TYPE_TERM,
172171
'name' => $filterName,
@@ -194,7 +193,11 @@ private function generateAdvancedSearchRequest()
194193
$request['queries'][$queryName] = [
195194
'name' => $queryName,
196195
'type' => QueryInterface::TYPE_FILTER,
197-
'filterReference' => [['ref' => $filterName]],
196+
'filterReference' => [
197+
[
198+
'ref' => $filterName,
199+
],
200+
],
198201
];
199202
$request['filters'][$filterName] = [
200203
'field' => $attribute->getAttributeCode(),
@@ -209,9 +212,12 @@ private function generateAdvancedSearchRequest()
209212
$request['queries'][$queryName] = [
210213
'name' => $queryName,
211214
'type' => QueryInterface::TYPE_FILTER,
212-
'filterReference' => [['ref' => $filterName]],
215+
'filterReference' => [
216+
[
217+
'ref' => $filterName,
218+
],
219+
],
213220
];
214-
215221
$request['filters'][$filterName] = [
216222
'type' => FilterInterface::TYPE_TERM,
217223
'name' => $filterName,
@@ -223,4 +229,25 @@ private function generateAdvancedSearchRequest()
223229

224230
return $request;
225231
}
232+
233+
/**
234+
* Modify request for price attribute.
235+
*
236+
* @param bool $useFulltext
237+
* @param Attribute $attribute
238+
* @param array $request
239+
* @return array
240+
*/
241+
private function processPriceAttribute($useFulltext, $attribute, $request)
242+
{
243+
// Match search by custom price attribute isn't supported
244+
if ($useFulltext && $attribute->getFrontendInput() !== 'price') {
245+
$request['queries']['search']['match'][] = [
246+
'field' => $attribute->getAttributeCode(),
247+
'boost' => $attribute->getSearchWeight() ?: 1,
248+
];
249+
}
250+
251+
return $request;
252+
}
226253
}

app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGeneratorTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ public function testGenerate($countResult, $attributeOptions)
170170
$this->countVal($result['catalog_view_container']['queries']),
171171
'Queries count for "catalog_view_container" doesn\'t match'
172172
);
173+
foreach ($result as $key => $value) {
174+
if (isset($value['queries'][$key]['queryReference'])) {
175+
foreach ($value['queries'][$key]['queryReference'] as $reference) {
176+
$this->assertEquals(
177+
'must',
178+
$reference['clause']
179+
);
180+
}
181+
}
182+
}
173183
}
174184

175185
/**

app/code/Magento/Cms/Model/ResourceModel/Block/Grid/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Collection extends BlockCollection implements SearchResultInterface
3131
* @param string $eventObject
3232
* @param string $resourceModel
3333
* @param string $model
34-
* @param string|null $connection
34+
* @param \Magento\Framework\DB\Adapter\AdapterInterface|string|null $connection
3535
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
3636
*
3737
* @SuppressWarnings(PHPMD.ExcessiveParameterList)

app/code/Magento/Cms/Model/ResourceModel/Page/Grid/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Collection extends PageCollection implements SearchResultInterface
2828
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
2929
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
3030
* @param mixed|null $mainTable
31-
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $eventPrefix
31+
* @param string $eventPrefix
3232
* @param mixed $eventObject
3333
* @param mixed $resourceModel
3434
* @param string $model

app/code/Magento/Config/Controller/Adminhtml/System/AbstractConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ abstract class AbstractConfig extends \Magento\Backend\App\AbstractAction
3434
/**
3535
* @param \Magento\Backend\App\Action\Context $context
3636
* @param \Magento\Config\Model\Config\Structure $configStructure
37-
* @param $sectionChecker - deprecated
37+
* @param mixed $sectionChecker - deprecated
3838
*/
3939
public function __construct(
4040
\Magento\Backend\App\Action\Context $context,

app/code/Magento/Customer/Block/CustomerData.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,23 @@
1010
*/
1111
class CustomerData extends \Magento\Framework\View\Element\Template
1212
{
13+
/**
14+
* @var array
15+
*/
16+
private $expirableSectionNames;
17+
1318
/**
1419
* @param \Magento\Framework\View\Element\Template\Context $context
1520
* @param array $data
21+
* @param array $expirableSectionNames
1622
*/
1723
public function __construct(
1824
\Magento\Framework\View\Element\Template\Context $context,
19-
array $data = []
25+
array $data = [],
26+
array $expirableSectionNames = []
2027
) {
2128
parent::__construct($context, $data);
29+
$this->expirableSectionNames = $expirableSectionNames;
2230
}
2331

2432
/**
@@ -43,4 +51,26 @@ public function getCustomerDataUrl($route)
4351
{
4452
return $this->getUrl($route, ['_secure' => $this->getRequest()->isSecure()]);
4553
}
54+
55+
/**
56+
* Retrieve lifetime period (in minutes) of the frontend section configuration.
57+
*
58+
* Once this period has expired the corresponding section must be invalidated and reloaded.
59+
*
60+
* @return int section lifetime in minutes
61+
*/
62+
public function getExpirableSectionLifetime()
63+
{
64+
return (int)$this->_scopeConfig->getValue('customer/online_customers/section_data_lifetime');
65+
}
66+
67+
/**
68+
* Retrieve the list of sections that can expire.
69+
*
70+
* @return array
71+
*/
72+
public function getExpirableSectionNames()
73+
{
74+
return array_values($this->expirableSectionNames);
75+
}
4676
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Test\Unit\Block;
7+
8+
use Magento\Customer\Block\CustomerData;
9+
use Magento\Framework\App\Config\ScopeConfigInterface;
10+
use Magento\Framework\View\Element\Template\Context;
11+
12+
class CustomerDataTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/**
15+
* @var Context|\PHPUnit_Framework_MockObject_MockObject
16+
*/
17+
private $contextMock;
18+
19+
/**
20+
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
21+
*/
22+
private $scopeConfigMock;
23+
24+
protected function setUp()
25+
{
26+
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)->getMock();
27+
$this->contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
28+
$this->contextMock->expects($this->once())->method('getScopeConfig')->willReturn($this->scopeConfigMock);
29+
}
30+
31+
public function testGetExpirableSectionLifetimeReturnsConfigurationValue()
32+
{
33+
$block = new CustomerData(
34+
$this->contextMock,
35+
[],
36+
[]
37+
);
38+
39+
$this->scopeConfigMock->expects($this->once())
40+
->method('getValue')
41+
->with('customer/online_customers/section_data_lifetime', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null)
42+
->willReturn('10');
43+
44+
$actualResult = $block->getExpirableSectionLifetime();
45+
$this->assertSame(10, $actualResult);
46+
}
47+
48+
public function testGetExpirableSectionNames()
49+
{
50+
$expectedResult = ['cart'];
51+
$block = new CustomerData(
52+
$this->contextMock,
53+
[],
54+
$expectedResult
55+
);
56+
57+
$this->assertEquals($expectedResult, $block->getExpirableSectionNames());
58+
}
59+
}

0 commit comments

Comments
 (0)