Skip to content

Commit 02e29e8

Browse files
author
Bohdan Shevchenko
committed
Merge remote-tracking branch 'origin/2.3-develop' into MC-21563
2 parents 77eb04b + b169e62 commit 02e29e8

File tree

104 files changed

+6616
-1030
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

+6616
-1030
lines changed

app/code/Magento/Backend/view/adminhtml/templates/widget/grid.phtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ $numColumns = $block->getColumns() !== null ? count($block->getColumns()) : 0;
170170
<?php if ($block->getSortableUpdateCallback()) : ?>
171171
<?= $block->escapeJs($block->getJsObjectName()) ?>.sortableUpdateCallback = <?= /* @noEscape */ $block->getSortableUpdateCallback() ?>;
172172
<?php endif; ?>
173+
<?php if ($block->getFilterKeyPressCallback()) : ?>
174+
<?= $block->escapeJs($block->getJsObjectName()) ?>.filterKeyPressCallback = <?= /* @noEscape */ $block->getFilterKeyPressCallback() ?>;
175+
<?php endif; ?>
173176
<?= $block->escapeJs($block->getJsObjectName()) ?>.bindSortable();
174177
<?php if ($block->getRowInitCallback()) : ?>
175178
<?= $block->escapeJs($block->getJsObjectName()) ?>.initRowCallback = <?= /* @noEscape */ $block->getRowInitCallback() ?>;

app/code/Magento/Backend/view/adminhtml/templates/widget/grid/extended.phtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ $numColumns = count($block->getColumns());
272272
<?php if ($block->getCheckboxCheckCallback()) : ?>
273273
<?= $block->escapeJs($block->getJsObjectName()) ?>.checkboxCheckCallback = <?= /* @noEscape */ $block->getCheckboxCheckCallback() ?>;
274274
<?php endif; ?>
275+
<?php if ($block->getFilterKeyPressCallback()) : ?>
276+
<?= $block->escapeJs($block->getJsObjectName()) ?>.filterKeyPressCallback = <?= /* @noEscape */ $block->getFilterKeyPressCallback() ?>;
277+
<?php endif; ?>
275278
<?php if ($block->getRowInitCallback()) : ?>
276279
<?= $block->escapeJs($block->getJsObjectName()) ?>.initRowCallback = <?= /* @noEscape */ $block->getRowInitCallback() ?>;
277280
<?= $block->escapeJs($block->getJsObjectName()) ?>.initGridRows();

app/code/Magento/Braintree/Gateway/Validator/ErrorCodeProvider.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Braintree\Error\Validation;
1212
use Braintree\Result\Error;
1313
use Braintree\Result\Successful;
14+
use Braintree\Transaction;
1415

1516
/**
1617
* Processes errors codes from Braintree response.
@@ -38,12 +39,14 @@ public function getErrorCodes($response): array
3839
$result[] = $error->code;
3940
}
4041

41-
if (isset($response->transaction) && $response->transaction->status === 'gateway_rejected') {
42-
$result[] = $response->transaction->gatewayRejectionReason;
43-
}
42+
if (isset($response->transaction) && $response->transaction) {
43+
if ($response->transaction->status === Transaction::GATEWAY_REJECTED) {
44+
$result[] = $response->transaction->gatewayRejectionReason;
45+
}
4446

45-
if (isset($response->transaction) && $response->transaction->status === 'processor_declined') {
46-
$result[] = $response->transaction->processorResponseCode;
47+
if ($response->transaction->status === Transaction::PROCESSOR_DECLINED) {
48+
$result[] = $response->transaction->processorResponseCode;
49+
}
4750
}
4851

4952
return $result;

app/code/Magento/Catalog/Helper/Output.php

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,21 @@
99

1010
use Magento\Catalog\Model\Category as ModelCategory;
1111
use Magento\Catalog\Model\Product as ModelProduct;
12+
use Magento\Eav\Model\Config;
13+
use Magento\Framework\App\Helper\AbstractHelper;
14+
use Magento\Framework\App\Helper\Context;
15+
use Magento\Framework\Escaper;
16+
use Magento\Framework\Exception\LocalizedException;
1217
use Magento\Framework\Filter\Template;
18+
use function is_object;
19+
use function method_exists;
20+
use function preg_match;
21+
use function strtolower;
1322

14-
class Output extends \Magento\Framework\App\Helper\AbstractHelper
23+
/**
24+
* Html output
25+
*/
26+
class Output extends AbstractHelper
1527
{
1628
/**
1729
* Array of existing handlers
@@ -37,12 +49,12 @@ class Output extends \Magento\Framework\App\Helper\AbstractHelper
3749
/**
3850
* Eav config
3951
*
40-
* @var \Magento\Eav\Model\Config
52+
* @var Config
4153
*/
4254
protected $_eavConfig;
4355

4456
/**
45-
* @var \Magento\Framework\Escaper
57+
* @var Escaper
4658
*/
4759
protected $_escaper;
4860

@@ -53,27 +65,32 @@ class Output extends \Magento\Framework\App\Helper\AbstractHelper
5365

5466
/**
5567
* Output constructor.
56-
* @param \Magento\Framework\App\Helper\Context $context
57-
* @param \Magento\Eav\Model\Config $eavConfig
68+
* @param Context $context
69+
* @param Config $eavConfig
5870
* @param Data $catalogData
59-
* @param \Magento\Framework\Escaper $escaper
71+
* @param Escaper $escaper
6072
* @param array $directivePatterns
73+
* @param array $handlers
6174
*/
6275
public function __construct(
63-
\Magento\Framework\App\Helper\Context $context,
64-
\Magento\Eav\Model\Config $eavConfig,
76+
Context $context,
77+
Config $eavConfig,
6578
Data $catalogData,
66-
\Magento\Framework\Escaper $escaper,
67-
$directivePatterns = []
79+
Escaper $escaper,
80+
$directivePatterns = [],
81+
array $handlers = []
6882
) {
6983
$this->_eavConfig = $eavConfig;
7084
$this->_catalogData = $catalogData;
7185
$this->_escaper = $escaper;
7286
$this->directivePatterns = $directivePatterns;
87+
$this->_handlers = $handlers;
7388
parent::__construct($context);
7489
}
7590

7691
/**
92+
* Return template processor
93+
*
7794
* @return Template
7895
*/
7996
protected function _getTemplateProcessor()
@@ -115,8 +132,7 @@ public function addHandler($method, $handler)
115132
*/
116133
public function getHandlers($method)
117134
{
118-
$method = strtolower($method);
119-
return $this->_handlers[$method] ?? [];
135+
return $this->_handlers[strtolower($method)] ?? [];
120136
}
121137

122138
/**
@@ -145,21 +161,21 @@ public function process($method, $result, $params)
145161
* @param string $attributeName
146162
* @return string
147163
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
148-
* @throws \Magento\Framework\Exception\LocalizedException
164+
* @throws LocalizedException
149165
*/
150166
public function productAttribute($product, $attributeHtml, $attributeName)
151167
{
152168
$attribute = $this->_eavConfig->getAttribute(ModelProduct::ENTITY, $attributeName);
153169
if ($attribute &&
154170
$attribute->getId() &&
155-
$attribute->getFrontendInput() != 'media_image' &&
171+
$attribute->getFrontendInput() !== 'media_image' &&
156172
(!$attribute->getIsHtmlAllowedOnFront() &&
157173
!$attribute->getIsWysiwygEnabled())
158174
) {
159-
if ($attribute->getFrontendInput() != 'price') {
175+
if ($attribute->getFrontendInput() !== 'price') {
160176
$attributeHtml = $this->_escaper->escapeHtml($attributeHtml);
161177
}
162-
if ($attribute->getFrontendInput() == 'textarea') {
178+
if ($attribute->getFrontendInput() === 'textarea') {
163179
$attributeHtml = nl2br($attributeHtml);
164180
}
165181
}
@@ -187,14 +203,14 @@ public function productAttribute($product, $attributeHtml, $attributeName)
187203
* @param string $attributeHtml
188204
* @param string $attributeName
189205
* @return string
190-
* @throws \Magento\Framework\Exception\LocalizedException
206+
* @throws LocalizedException
191207
*/
192208
public function categoryAttribute($category, $attributeHtml, $attributeName)
193209
{
194210
$attribute = $this->_eavConfig->getAttribute(ModelCategory::ENTITY, $attributeName);
195211

196212
if ($attribute &&
197-
$attribute->getFrontendInput() != 'image' &&
213+
$attribute->getFrontendInput() !== 'image' &&
198214
(!$attribute->getIsHtmlAllowedOnFront() &&
199215
!$attribute->getIsWysiwygEnabled())
200216
) {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Model\Product;
9+
10+
use Magento\Framework\EntityManager\HydratorInterface;
11+
12+
/**
13+
* Class is used to extract data and populate entity with data
14+
*/
15+
class Hydrator implements HydratorInterface
16+
{
17+
/**
18+
* @inheritdoc
19+
*/
20+
public function extract($entity)
21+
{
22+
return $entity->getData();
23+
}
24+
25+
/**
26+
* @inheritdoc
27+
*/
28+
public function hydrate($entity, array $data)
29+
{
30+
$lockedAttributes = $entity->getLockedAttributes();
31+
$entity->unlockAttributes();
32+
$entity->setData(array_merge($entity->getData(), $data));
33+
foreach ($lockedAttributes as $attribute) {
34+
$entity->lockAttribute($attribute);
35+
}
36+
37+
return $entity;
38+
}
39+
}

app/code/Magento/Catalog/Ui/Component/UrlInput/Product.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
use Magento\Framework\UrlInterface;
1212

13+
/**
14+
* Returns configuration for product Url Input type
15+
*/
1316
class Product implements \Magento\Ui\Model\UrlInput\ConfigInterface
1417
{
1518
/**
@@ -27,7 +30,7 @@ public function __construct(UrlInterface $urlBuilder)
2730
}
2831

2932
/**
30-
* {@inheritdoc}
33+
* @inheritdoc
3134
*/
3235
public function getConfig(): array
3336
{
@@ -46,6 +49,7 @@ public function getConfig(): array
4649
'template' => 'ui/grid/filters/elements/ui-select',
4750
'searchUrl' => $this->urlBuilder->getUrl('catalog/product/search'),
4851
'filterPlaceholder' => __('Product Name or SKU'),
52+
'filterRateLimitMethod' => 'notifyWhenChangesStop',
4953
'isDisplayEmptyPlaceholder' => true,
5054
'emptyOptionsHtml' => __('Start typing to find products'),
5155
'missingValuePlaceholder' => __('Product with ID: %s doesn\'t exist'),

app/code/Magento/Catalog/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@
867867
<argument name="hydrators" xsi:type="array">
868868
<item name="Magento\Catalog\Api\Data\CategoryInterface" xsi:type="string">Magento\Framework\EntityManager\AbstractModelHydrator</item>
869869
<item name="Magento\Catalog\Api\Data\CategoryTreeInterface" xsi:type="string">Magento\Framework\EntityManager\AbstractModelHydrator</item>
870-
<item name="Magento\Catalog\Api\Data\ProductInterface" xsi:type="string">Magento\Framework\EntityManager\AbstractModelHydrator</item>
870+
<item name="Magento\Catalog\Api\Data\ProductInterface" xsi:type="string">Magento\Catalog\Model\Product\Hydrator</item>
871871
</argument>
872872
</arguments>
873873
</type>
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogGraphQl\Model\Category;
9+
10+
use Magento\Catalog\Api\Data\CategoryInterface;
11+
use Magento\Catalog\Model\ResourceModel\Category\Collection;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\Exception\InputException;
14+
use Magento\Store\Api\Data\StoreInterface;
15+
use Magento\Store\Model\ScopeInterface;
16+
use Magento\Search\Model\Query;
17+
18+
/**
19+
* Category filter allows to filter collection using 'id, url_key, name' from search criteria.
20+
*/
21+
class CategoryFilter
22+
{
23+
/**
24+
* @var ScopeConfigInterface
25+
*/
26+
private $scopeConfig;
27+
28+
/**
29+
* @param ScopeConfigInterface $scopeConfig
30+
*/
31+
public function __construct(
32+
ScopeConfigInterface $scopeConfig
33+
) {
34+
$this->scopeConfig = $scopeConfig;
35+
}
36+
37+
/**
38+
* Filter for filtering the requested categories id's based on url_key, ids, name in the result.
39+
*
40+
* @param array $args
41+
* @param Collection $categoryCollection
42+
* @param StoreInterface $store
43+
* @throws InputException
44+
*/
45+
public function applyFilters(array $args, Collection $categoryCollection, StoreInterface $store)
46+
{
47+
$categoryCollection->addAttributeToFilter(CategoryInterface::KEY_IS_ACTIVE, ['eq' => 1]);
48+
foreach ($args['filters'] as $field => $cond) {
49+
foreach ($cond as $condType => $value) {
50+
if ($field === 'ids') {
51+
$categoryCollection->addIdFilter($value);
52+
} else {
53+
$this->addAttributeFilter($categoryCollection, $field, $condType, $value, $store);
54+
}
55+
}
56+
}
57+
}
58+
59+
/**
60+
* Add filter to category collection
61+
*
62+
* @param Collection $categoryCollection
63+
* @param string $field
64+
* @param string $condType
65+
* @param string|array $value
66+
* @param StoreInterface $store
67+
* @throws InputException
68+
*/
69+
private function addAttributeFilter($categoryCollection, $field, $condType, $value, $store)
70+
{
71+
if ($condType === 'match') {
72+
$this->addMatchFilter($categoryCollection, $field, $value, $store);
73+
return;
74+
}
75+
$categoryCollection->addAttributeToFilter($field, [$condType => $value]);
76+
}
77+
78+
/**
79+
* Add match filter to collection
80+
*
81+
* @param Collection $categoryCollection
82+
* @param string $field
83+
* @param string $value
84+
* @param StoreInterface $store
85+
* @throws InputException
86+
*/
87+
private function addMatchFilter($categoryCollection, $field, $value, $store)
88+
{
89+
$minQueryLength = $this->scopeConfig->getValue(
90+
Query::XML_PATH_MIN_QUERY_LENGTH,
91+
ScopeInterface::SCOPE_STORE,
92+
$store
93+
);
94+
$searchValue = str_replace('%', '', $value);
95+
$matchLength = strlen($searchValue);
96+
if ($matchLength < $minQueryLength) {
97+
throw new InputException(__('Invalid match filter'));
98+
}
99+
100+
$categoryCollection->addAttributeToFilter($field, ['like' => "%{$searchValue}%"]);
101+
}
102+
}

0 commit comments

Comments
 (0)