Skip to content

Commit ef4f8ad

Browse files
committed
Merge remote-tracking branch 'origin/2.2-develop' into 2.2-develop-mftf-pr1
2 parents 833375d + ee0a2d0 commit ef4f8ad

File tree

15 files changed

+200
-71
lines changed

15 files changed

+200
-71
lines changed

app/code/Magento/Catalog/Block/Product/ListProduct.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ public function getIdentities()
356356
* Get post parameters
357357
*
358358
* @param Product $product
359-
* @return string
359+
* @return array
360360
*/
361361
public function getAddToCartPostParams(Product $product)
362362
{
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogSearch\Ui\DataProvider\Product;
8+
9+
use Magento\Framework\Data\Collection;
10+
use Magento\CatalogSearch\Model\ResourceModel\Search\Collection as SearchCollection;
11+
use Magento\Ui\DataProvider\AddFilterToCollectionInterface;
12+
13+
/**
14+
* Class AddFulltextFilterToCollection
15+
*/
16+
class AddFulltextFilterToCollection implements AddFilterToCollectionInterface
17+
{
18+
/**
19+
* Search Collection
20+
*
21+
* @var SearchCollection
22+
*/
23+
private $searchCollection;
24+
25+
/**
26+
* @param SearchCollection $searchCollection
27+
*/
28+
public function __construct(SearchCollection $searchCollection)
29+
{
30+
$this->searchCollection = $searchCollection;
31+
}
32+
33+
/**
34+
* {@inheritdoc}
35+
*
36+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
37+
*/
38+
public function addFilter(Collection $collection, $field, $condition = null)
39+
{
40+
/** @var $collection \Magento\Catalog\Model\ResourceModel\Product\Collection */
41+
if (isset($condition['fulltext']) && !empty($condition['fulltext'])) {
42+
$this->searchCollection->addBackendSearchFilter($condition['fulltext']);
43+
$productIds = $this->searchCollection->load()->getAllIds();
44+
$collection->addIdFilter($productIds);
45+
}
46+
}
47+
}

app/code/Magento/CatalogSearch/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"magento/module-eav": "101.0.*",
1313
"magento/module-backend": "100.2.*",
1414
"magento/module-theme": "100.2.*",
15+
"magento/module-ui": "101.0.*",
1516
"magento/module-catalog-inventory": "100.2.*",
1617
"magento/framework": "101.0.*"
1718
},

app/code/Magento/CatalogSearch/etc/adminhtml/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,11 @@
1919
<type name="Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit\Tab\Front">
2020
<plugin name="search_weigh" type="Magento\CatalogSearch\Block\Plugin\FrontTabPlugin" />
2121
</type>
22+
<type name="Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider">
23+
<arguments>
24+
<argument name="addFilterStrategies" xsi:type="array">
25+
<item name="fulltext" xsi:type="object">Magento\CatalogSearch\Ui\DataProvider\Product\AddFulltextFilterToCollection</item>
26+
</argument>
27+
</arguments>
28+
</type>
2229
</config>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
9+
<listingToolbar name="listing_top">
10+
<filterSearch name="fulltext"/>
11+
</listingToolbar>
12+
</listing>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Magento\Cms\Model\ResourceModel\Block\Grid;
77

88
use Magento\Framework\Api\Search\SearchResultInterface;
9-
use Magento\Framework\Search\AggregationInterface;
9+
use Magento\Framework\Api\Search\AggregationInterface;
1010
use Magento\Cms\Model\ResourceModel\Block\Collection as BlockCollection;
1111

1212
/**
@@ -82,6 +82,7 @@ public function getAggregations()
8282
public function setAggregations($aggregations)
8383
{
8484
$this->aggregations = $aggregations;
85+
return $this;
8586
}
8687

8788
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function getAggregations()
8383
public function setAggregations($aggregations)
8484
{
8585
$this->aggregations = $aggregations;
86+
return $this;
8687
}
8788

8889
/**

app/code/Magento/OfflineShipping/Block/Adminhtml/Form/Field/Export.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Export extends \Magento\Framework\Data\Form\Element\AbstractElement
2121
* @param \Magento\Framework\Data\Form\Element\Factory $factoryElement
2222
* @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection
2323
* @param \Magento\Framework\Escaper $escaper
24-
* @param \Magento\Backend\Helper\Data $helper
24+
* @param \Magento\Backend\Model\UrlInterface $backendUrl
2525
* @param array $data
2626
*/
2727
public function __construct(

app/code/Magento/Rule/Model/Condition/AbstractCondition.php

Lines changed: 37 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ abstract class AbstractCondition extends \Magento\Framework\DataObject implement
2424
{
2525
/**
2626
* Defines which operators will be available for this condition
27-
*
2827
* @var string
2928
*/
3029
protected $_inputType = null;
@@ -84,17 +83,13 @@ public function __construct(Context $context, array $data = [])
8483

8584
$options = $this->getAttributeOptions();
8685
if ($options) {
87-
foreach (array_keys($options) as $attr) {
88-
$this->setAttribute($attr);
89-
break;
90-
}
86+
reset($options);
87+
$this->setAttribute(key($options));
9188
}
9289
$options = $this->getOperatorOptions();
9390
if ($options) {
94-
foreach (array_keys($options) as $operator) {
95-
$this->setOperator($operator);
96-
break;
97-
}
91+
reset($options);
92+
$this->setOperator(key($options));
9893
}
9994
}
10095

@@ -160,14 +155,13 @@ public function getForm()
160155
*/
161156
public function asArray(array $arrAttributes = [])
162157
{
163-
$out = [
158+
return [
164159
'type' => $this->getType(),
165160
'attribute' => $this->getAttribute(),
166161
'operator' => $this->getOperator(),
167162
'value' => $this->getValue(),
168163
'is_value_processed' => $this->getIsValueParsed(),
169164
];
170-
return $out;
171165
}
172166

173167
/**
@@ -205,7 +199,7 @@ public function getMappedSqlField()
205199
*/
206200
public function asXml()
207201
{
208-
$xml = "<type>" .
202+
return "<type>" .
209203
$this->getType() .
210204
"</type>" .
211205
"<attribute>" .
@@ -217,7 +211,6 @@ public function asXml()
217211
"<value>" .
218212
$this->getValue() .
219213
"</value>";
220-
return $xml;
221214
}
222215

223216
/**
@@ -244,8 +237,7 @@ public function loadXml($xml)
244237
if (is_string($xml)) {
245238
$xml = simplexml_load_string($xml);
246239
}
247-
$arr = (array)$xml;
248-
$this->loadArray($arr);
240+
$this->loadArray((array)$xml);
249241
return $this;
250242
}
251243

@@ -304,10 +296,7 @@ public function loadOperatorOptions()
304296
*/
305297
public function getInputType()
306298
{
307-
if (null === $this->_inputType) {
308-
return 'string';
309-
}
310-
return $this->_inputType;
299+
return null === $this->_inputType ? 'string' : $this->_inputType;
311300
}
312301

313302
/**
@@ -348,12 +337,11 @@ public function loadValueOptions()
348337
*/
349338
public function getValueSelectOptions()
350339
{
351-
$valueOption = $opt = [];
340+
$opt = [];
352341
if ($this->hasValueOption()) {
353-
$valueOption = (array)$this->getValueOption();
354-
}
355-
foreach ($valueOption as $key => $value) {
356-
$opt[] = ['value' => $key, 'label' => $value];
342+
foreach ((array)$this->getValueOption() as $key => $value) {
343+
$opt[] = ['value' => $key, 'label' => $value];
344+
}
357345
}
358346
return $opt;
359347
}
@@ -470,22 +458,20 @@ public function getNewChildName()
470458
*/
471459
public function asHtml()
472460
{
473-
$html = $this->getTypeElementHtml() .
461+
return $this->getTypeElementHtml() .
474462
$this->getAttributeElementHtml() .
475463
$this->getOperatorElementHtml() .
476464
$this->getValueElementHtml() .
477465
$this->getRemoveLinkHtml() .
478466
$this->getChooserContainerHtml();
479-
return $html;
480467
}
481468

482469
/**
483470
* @return string
484471
*/
485472
public function asHtmlRecursive()
486473
{
487-
$html = $this->asHtml();
488-
return $html;
474+
return $this->asHtml();
489475
}
490476

491477
/**
@@ -520,9 +506,10 @@ public function getTypeElementHtml()
520506
public function getAttributeElement()
521507
{
522508
if (null === $this->getAttribute()) {
523-
foreach (array_keys($this->getAttributeOption()) as $option) {
524-
$this->setAttribute($option);
525-
break;
509+
$options = $this->getAttributeOption();
510+
if ($options) {
511+
reset($options);
512+
$this->setAttribute(key($options));
526513
}
527514
}
528515
return $this->getForm()->addField(
@@ -558,10 +545,8 @@ public function getOperatorElement()
558545
{
559546
$options = $this->getOperatorSelectOptions();
560547
if ($this->getOperator() === null) {
561-
foreach ($options as $option) {
562-
$this->setOperator($option['value']);
563-
break;
564-
}
548+
$option = reset($options);
549+
$this->setOperator($option['value']);
565550
}
566551

567552
$elementId = sprintf('%s__%s__operator', $this->getPrefix(), $this->getId());
@@ -654,8 +639,7 @@ public function getValueElementHtml()
654639
public function getAddLinkHtml()
655640
{
656641
$src = $this->_assetRepo->getUrl('images/rule_component_add.gif');
657-
$html = '<img src="' . $src . '" class="rule-param-add v-middle" alt="" title="' . __('Add') . '"/>';
658-
return $html;
642+
return '<img src="' . $src . '" class="rule-param-add v-middle" alt="" title="' . __('Add') . '"/>';
659643
}
660644

661645
/**
@@ -676,11 +660,7 @@ public function getRemoveLinkHtml()
676660
public function getChooserContainerHtml()
677661
{
678662
$url = $this->getValueElementChooserUrl();
679-
$html = '';
680-
if ($url) {
681-
$html = '<div class="rule-chooser" url="' . $url . '"></div>';
682-
}
683-
return $html;
663+
return $url ? '<div class="rule-chooser" url="' . $url . '"></div>' : '';
684664
}
685665

686666
/**
@@ -690,8 +670,7 @@ public function getChooserContainerHtml()
690670
*/
691671
public function asString($format = '')
692672
{
693-
$str = $this->getAttributeName() . ' ' . $this->getOperatorName() . ' ' . $this->getValueName();
694-
return $str;
673+
return $this->getAttributeName() . ' ' . $this->getOperatorName() . ' ' . $this->getValueName();
695674
}
696675

697676
/**
@@ -700,8 +679,7 @@ public function asString($format = '')
700679
*/
701680
public function asStringRecursive($level = 0)
702681
{
703-
$str = str_pad('', $level * 3, ' ', STR_PAD_LEFT) . $this->asString();
704-
return $str;
682+
return str_pad('', $level * 3, ' ', STR_PAD_LEFT) . $this->asString();
705683
}
706684

707685
/**
@@ -740,12 +718,10 @@ public function validateAttribute($validatedValue)
740718
case '==':
741719
case '!=':
742720
if (is_array($value)) {
743-
if (is_array($validatedValue)) {
744-
$result = array_intersect($value, $validatedValue);
745-
$result = !empty($result);
746-
} else {
721+
if (!is_array($validatedValue)) {
747722
return false;
748723
}
724+
$result = !empty(array_intersect($value, $validatedValue));
749725
} else {
750726
if (is_array($validatedValue)) {
751727
$result = count($validatedValue) == 1 && array_shift($validatedValue) == $value;
@@ -759,18 +735,16 @@ public function validateAttribute($validatedValue)
759735
case '>':
760736
if (!is_scalar($validatedValue)) {
761737
return false;
762-
} else {
763-
$result = $validatedValue <= $value;
764738
}
739+
$result = $validatedValue <= $value;
765740
break;
766741

767742
case '>=':
768743
case '<':
769744
if (!is_scalar($validatedValue)) {
770745
return false;
771-
} else {
772-
$result = $validatedValue >= $value;
773746
}
747+
$result = $validatedValue >= $value;
774748
break;
775749

776750
case '{}':
@@ -783,12 +757,11 @@ public function validateAttribute($validatedValue)
783757
}
784758
}
785759
} elseif (is_array($value)) {
786-
if (is_array($validatedValue)) {
787-
$result = array_intersect($value, $validatedValue);
788-
$result = !empty($result);
789-
} else {
760+
if (!is_array($validatedValue)) {
790761
return false;
791762
}
763+
$result = array_intersect($value, $validatedValue);
764+
$result = !empty($result);
792765
} else {
793766
if (is_array($validatedValue)) {
794767
$result = in_array($value, $validatedValue);
@@ -833,13 +806,13 @@ protected function _compareValues($validatedValue, $value, $strict = true)
833806
{
834807
if ($strict && is_numeric($validatedValue) && is_numeric($value)) {
835808
return $validatedValue == $value;
836-
} else {
837-
$validatePattern = preg_quote($validatedValue, '~');
838-
if ($strict) {
839-
$validatePattern = '^' . $validatePattern . '$';
840-
}
841-
return (bool)preg_match('~' . $validatePattern . '~iu', $value);
842809
}
810+
811+
$validatePattern = preg_quote($validatedValue, '~');
812+
if ($strict) {
813+
$validatePattern = '^' . $validatePattern . '$';
814+
}
815+
return (bool)preg_match('~' . $validatePattern . '~iu', $value);
843816
}
844817

845818
/**

0 commit comments

Comments
 (0)