Skip to content

Commit 2903792

Browse files
merge magento/2.3-develop into magento-tsg/2.3-develop-com-pr1
2 parents 68dc933 + e2ac8c8 commit 2903792

File tree

59 files changed

+3306
-382
lines changed

Some content is hidden

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

59 files changed

+3306
-382
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;
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/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+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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\Resolver;
9+
10+
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\ExtractDataFromCategoryTree;
11+
use Magento\Framework\Exception\InputException;
12+
use Magento\Framework\GraphQl\Config\Element\Field;
13+
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
14+
use Magento\Framework\GraphQl\Query\ResolverInterface;
15+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
16+
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\CategoryTree;
17+
use Magento\CatalogGraphQl\Model\Category\CategoryFilter;
18+
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
19+
20+
/**
21+
* Category List resolver, used for GraphQL category data request processing.
22+
*/
23+
class CategoryList implements ResolverInterface
24+
{
25+
/**
26+
* @var CategoryTree
27+
*/
28+
private $categoryTree;
29+
30+
/**
31+
* @var CollectionFactory
32+
*/
33+
private $collectionFactory;
34+
35+
/**
36+
* @var CategoryFilter
37+
*/
38+
private $categoryFilter;
39+
40+
/**
41+
* @var ExtractDataFromCategoryTree
42+
*/
43+
private $extractDataFromCategoryTree;
44+
45+
/**
46+
* @param CategoryTree $categoryTree
47+
* @param ExtractDataFromCategoryTree $extractDataFromCategoryTree
48+
* @param CategoryFilter $categoryFilter
49+
* @param CollectionFactory $collectionFactory
50+
*/
51+
public function __construct(
52+
CategoryTree $categoryTree,
53+
ExtractDataFromCategoryTree $extractDataFromCategoryTree,
54+
CategoryFilter $categoryFilter,
55+
CollectionFactory $collectionFactory
56+
) {
57+
$this->categoryTree = $categoryTree;
58+
$this->extractDataFromCategoryTree = $extractDataFromCategoryTree;
59+
$this->categoryFilter = $categoryFilter;
60+
$this->collectionFactory = $collectionFactory;
61+
}
62+
63+
/**
64+
* @inheritdoc
65+
*/
66+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
67+
{
68+
if (isset($value[$field->getName()])) {
69+
return $value[$field->getName()];
70+
}
71+
$store = $context->getExtensionAttributes()->getStore();
72+
73+
$rootCategoryIds = [];
74+
if (!isset($args['filters'])) {
75+
$rootCategoryIds[] = (int)$store->getRootCategoryId();
76+
} else {
77+
$categoryCollection = $this->collectionFactory->create();
78+
try {
79+
$this->categoryFilter->applyFilters($args, $categoryCollection, $store);
80+
} catch (InputException $e) {
81+
return [];
82+
}
83+
84+
foreach ($categoryCollection as $category) {
85+
$rootCategoryIds[] = (int)$category->getId();
86+
}
87+
}
88+
89+
$result = $this->fetchCategories($rootCategoryIds, $info);
90+
return $result;
91+
}
92+
93+
/**
94+
* Fetch category tree data
95+
*
96+
* @param array $categoryIds
97+
* @param ResolveInfo $info
98+
* @return array
99+
* @throws GraphQlNoSuchEntityException
100+
*/
101+
private function fetchCategories(array $categoryIds, ResolveInfo $info)
102+
{
103+
$fetchedCategories = [];
104+
foreach ($categoryIds as $categoryId) {
105+
$categoryTree = $this->categoryTree->getTree($info, $categoryId);
106+
if (empty($categoryTree)) {
107+
continue;
108+
}
109+
$fetchedCategories[] = current($this->extractDataFromCategoryTree->execute($categoryTree));
110+
}
111+
112+
return $fetchedCategories;
113+
}
114+
}

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/Query/FieldSelection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ private function getProductFields(ResolveInfo $info): array
6060
$fieldNames[] = $this->collectProductFieldNames($selection, $fieldNames);
6161
}
6262
}
63-
64-
$fieldNames = array_merge(...$fieldNames);
65-
63+
if (!empty($fieldNames)) {
64+
$fieldNames = array_merge(...$fieldNames);
65+
}
6666
return $fieldNames;
6767
}
6868

app/code/Magento/CatalogGraphQl/etc/schema.graphqls

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ type Query {
1111
): Products
1212
@resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Products") @doc(description: "The products query searches for products that match the criteria specified in the search and filter attributes.") @cache(cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\Identity")
1313
category (
14-
id: Int @doc(description: "Id of the category.")
14+
id: Int @doc(description: "Id of the category.")
1515
): CategoryTree
16-
@resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\CategoryTree") @doc(description: "The category query searches for categories that match the criteria specified in the search and filter attributes.") @cache(cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\CategoryTreeIdentity")
16+
@resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\CategoryTree") @doc(description: "The category query searches for categories that match the criteria specified in the search and filter attributes.") @deprecated(reason: "Use 'categoryList' query instead of 'category' query") @cache(cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\CategoryTreeIdentity")
17+
categoryList(
18+
filters: CategoryFilterInput @doc(description: "Identifies which Category filter inputs to search for and return.")
19+
): [CategoryTree] @doc(description: "Returns an array of categories based on the specified filters.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\CategoryList") @cache(cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\CategoriesIdentity")
1720
}
1821

1922
type Price @doc(description: "Price is deprecated, replaced by ProductPrice. The Price object defines the price of a product as well as any tax-related adjustments.") {
@@ -294,6 +297,13 @@ input ProductAttributeFilterInput @doc(description: "ProductAttributeFilterInput
294297
category_id: FilterEqualTypeInput @doc(description: "Filter product by category id")
295298
}
296299

300+
input CategoryFilterInput @doc(description: "CategoryFilterInput defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.")
301+
{
302+
ids: FilterEqualTypeInput @doc(description: "Filter by category ID that uniquely identifies the category.")
303+
url_key: FilterEqualTypeInput @doc(description: "Filter by the part of the URL that identifies the category")
304+
name: FilterMatchTypeInput @doc(description: "Filter by the display name of the category.")
305+
}
306+
297307
input ProductFilterInput @doc(description: "ProductFilterInput is deprecated, use @ProductAttributeFilterInput instead. ProductFilterInput defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.") {
298308
name: FilterTypeInput @doc(description: "The product name. Customers use this name to identify the product.")
299309
sku: FilterTypeInput @doc(description: "A number or code assigned to a product to identify the product, options, price, and manufacturer.")

app/code/Magento/Checkout/view/frontend/web/js/model/address-converter.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ define([
99
'jquery',
1010
'Magento_Checkout/js/model/new-customer-address',
1111
'Magento_Customer/js/customer-data',
12-
'mage/utils/objects'
13-
], function ($, address, customerData, mageUtils) {
12+
'mage/utils/objects',
13+
'underscore'
14+
], function ($, address, customerData, mageUtils, _) {
1415
'use strict';
1516

1617
var countryData = customerData.get('directory-data');
@@ -60,13 +61,15 @@ define([
6061
delete addressData['region_id'];
6162

6263
if (addressData['custom_attributes']) {
63-
addressData['custom_attributes'] = Object.entries(addressData['custom_attributes'])
64-
.map(function (customAttribute) {
64+
addressData['custom_attributes'] = _.map(
65+
addressData['custom_attributes'],
66+
function (value, key) {
6567
return {
66-
'attribute_code': customAttribute[0],
67-
'value': customAttribute[1]
68+
'attribute_code': key,
69+
'value': value
6870
};
69-
});
71+
}
72+
);
7073
}
7174

7275
return address(addressData);

0 commit comments

Comments
 (0)