Skip to content

Commit 1af440a

Browse files
committed
Merge branch '2.4-develop' of https://github.com/magento-commerce/magento2ce into ACP2E-1716
2 parents cbdfe00 + cfaeeae commit 1af440a

24 files changed

+1276
-470
lines changed

app/code/Magento/CatalogSearch/Model/Autocomplete/DataProvider.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ class DataProvider implements DataProviderInterface
2121
/**
2222
* Autocomplete limit
2323
*/
24-
const CONFIG_AUTOCOMPLETE_LIMIT = 'catalog/search/autocomplete_limit';
24+
public const CONFIG_AUTOCOMPLETE_LIMIT = 'catalog/search/autocomplete_limit';
2525

2626
/**
27-
* Query factory
28-
*
2927
* @var QueryFactory
3028
*/
3129
protected $queryFactory;
@@ -38,8 +36,6 @@ class DataProvider implements DataProviderInterface
3836
protected $itemFactory;
3937

4038
/**
41-
* Limit
42-
*
4339
* @var int
4440
*/
4541
protected $limit;
@@ -68,8 +64,12 @@ public function __construct(
6864
*/
6965
public function getItems()
7066
{
71-
$collection = $this->getSuggestCollection();
7267
$query = $this->queryFactory->get()->getQueryText();
68+
if (!$query) {
69+
return [];
70+
}
71+
72+
$collection = $this->getSuggestCollection();
7373
$result = [];
7474
foreach ($collection as $item) {
7575
$resultItem = $this->itemFactory->create([

app/code/Magento/CatalogSearch/Test/Unit/Model/Autocomplete/DataProviderTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,17 @@ private function buildCollection(array $data)
147147
->method('getIterator')
148148
->willReturn(new \ArrayIterator($collectionData));
149149
}
150+
151+
public function testGetItemsWithEmptyQueryText()
152+
{
153+
$this->query->expects($this->once())
154+
->method('getQueryText')
155+
->willReturn('');
156+
$this->query->expects($this->never())
157+
->method('getSuggestCollection');
158+
$this->itemFactory->expects($this->never())
159+
->method('create');
160+
$result = $this->model->getItems();
161+
$this->assertEmpty($result);
162+
}
150163
}

app/code/Magento/CustomerGraphQl/Model/Customer/Address/ExtractCustomerAddressData.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ function (array $customAttribute) {
167167
},
168168
$attributes
169169
);
170+
usort($customAttributes['custom_attributesV2'], function (array $a, array $b) {
171+
$aPosition = $a['sort_order'];
172+
$bPosition = $b['sort_order'];
173+
return $aPosition <=> $bPosition;
174+
});
170175

171176
return $customAttributes;
172177
}

app/code/Magento/CustomerGraphQl/Model/Customer/ExtractCustomerData.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ function (array $customAttribute) {
8888
},
8989
$customerData['custom_attributes']
9090
);
91+
usort($customerData['custom_attributes'], function (array $a, array $b) {
92+
$aPosition = $a['sort_order'];
93+
$bPosition = $b['sort_order'];
94+
return $aPosition <=> $bPosition;
95+
});
9196
} else {
9297
$customerData['custom_attributes'] = [];
9398
}

app/code/Magento/CustomerGraphQl/Model/Customer/GetCustomAttributes.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public function execute(string $entityType, array $customAttribute): ?array
7070
$entityType,
7171
$customAttribute['attribute_code']
7272
),
73-
'code' => $customAttribute['attribute_code']
73+
'code' => $customAttribute['attribute_code'],
74+
'sort_order' => $attr->getSortOrder() ?? ''
7475
];
7576

7677
if (in_array($attr->getFrontendInput(), $this->frontendInputs)) {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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\CustomerGraphQl\Model\Resolver;
9+
10+
use Magento\CustomerGraphQl\Model\Customer\ExtractCustomerData;
11+
use Magento\CustomerGraphQl\Model\Customer\GetCustomer;
12+
use Magento\Framework\Api\CustomAttributesDataInterface;
13+
use Magento\Framework\GraphQl\Config\Element\Field;
14+
use Magento\Framework\GraphQl\Query\ResolverInterface;
15+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
16+
17+
/**
18+
* Resolver Custom Attribute filter
19+
*/
20+
class CustomAttributeFilter implements ResolverInterface
21+
{
22+
/**
23+
* @var GetCustomer
24+
*/
25+
private GetCustomer $getCustomer;
26+
27+
/**
28+
* @var ExtractCustomerData
29+
*/
30+
private ExtractCustomerData $extractCustomerData;
31+
32+
/**
33+
* @param GetCustomer $getCustomer
34+
* @param ExtractCustomerData $extractCustomerData
35+
*/
36+
public function __construct(
37+
GetCustomer $getCustomer,
38+
ExtractCustomerData $extractCustomerData,
39+
) {
40+
$this->getCustomer = $getCustomer;
41+
$this->extractCustomerData = $extractCustomerData;
42+
}
43+
44+
/**
45+
* @inheritdoc
46+
*/
47+
public function resolve(
48+
Field $field,
49+
$context,
50+
ResolveInfo $info,
51+
array $value = null,
52+
array $args = null
53+
): array {
54+
$customAttributes = $value[CustomAttributesDataInterface::CUSTOM_ATTRIBUTES];
55+
if (isset($args['uids']) && !empty($args['uids'])) {
56+
$selectedUids = array_values($args['uids']);
57+
return array_filter($customAttributes, function ($attr) use ($selectedUids) {
58+
return in_array($attr['uid'], $selectedUids);
59+
});
60+
}
61+
62+
return $customAttributes;
63+
}
64+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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\CustomerGraphQl\Model\Resolver;
9+
10+
use Magento\CustomerGraphQl\Model\Customer\Address\ExtractCustomerAddressData;
11+
use Magento\CustomerGraphQl\Model\Customer\Address\GetCustomerAddress;
12+
use Magento\Framework\Api\CustomAttributesDataInterface;
13+
use Magento\Framework\GraphQl\Config\Element\Field;
14+
use Magento\Framework\GraphQl\Query\ResolverInterface;
15+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
16+
17+
/**
18+
* Resolver Customer Address Custom Attribute filter
19+
*/
20+
class CustomerAddressCustomAttributeFilter implements ResolverInterface
21+
{
22+
/**
23+
* @var GetCustomerAddress
24+
*/
25+
private GetCustomerAddress $getCustomerAddress;
26+
27+
/**
28+
* @var ExtractCustomerAddressData
29+
*/
30+
private ExtractCustomerAddressData $extractCustomerAddressData;
31+
32+
/**
33+
* @param GetCustomerAddress $getCustomerAddress
34+
* @param ExtractCustomerAddressData $extractCustomerAddressData
35+
*/
36+
public function __construct(
37+
GetCustomerAddress $getCustomerAddress,
38+
ExtractCustomerAddressData $extractCustomerAddressData,
39+
) {
40+
$this->getCustomerAddress = $getCustomerAddress;
41+
$this->extractCustomerAddressData = $extractCustomerAddressData;
42+
}
43+
44+
/**
45+
* @inheritdoc
46+
*/
47+
public function resolve(
48+
Field $field,
49+
$context,
50+
ResolveInfo $info,
51+
array $value = null,
52+
array $args = null
53+
): array {
54+
$customAttributes = $value[CustomAttributesDataInterface::CUSTOM_ATTRIBUTES . 'V2'];
55+
if (isset($args['uids']) && !empty($args['uids'])) {
56+
$selectedUids = array_values($args['uids']);
57+
return array_filter($customAttributes, function ($attr) use ($selectedUids) {
58+
return in_array($attr['uid'], $selectedUids);
59+
});
60+
}
61+
62+
return $customAttributes;
63+
}
64+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ type Customer @doc(description: "Defines the customer name, addresses, and other
139139
is_subscribed: Boolean @doc(description: "Indicates whether the customer is subscribed to the company's newsletter.") @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\IsSubscribed")
140140
addresses: [CustomerAddress] @doc(description: "An array containing the customer's shipping and billing addresses.") @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\CustomerAddresses")
141141
gender: Int @doc(description: "The customer's gender (Male - 1, Female - 2).")
142-
custom_attributes: [AttributeValueInterface] @doc(description: "Customer's custom attributes.")
142+
custom_attributes(uids: [ID!]): [AttributeValueInterface] @doc(description: "Customer's custom attributes.") @resolver(class: "Magento\\CustomerGraphQl\\Model\\Resolver\\CustomAttributeFilter")
143143
}
144144

145145
type CustomerAddress @doc(description: "Contains detailed information about a customer's billing or shipping address."){
@@ -164,7 +164,7 @@ type CustomerAddress @doc(description: "Contains detailed information about a cu
164164
default_shipping: Boolean @doc(description: "Indicates whether the address is the customer's default shipping address.")
165165
default_billing: Boolean @doc(description: "Indicates whether the address is the customer's default billing address.")
166166
custom_attributes: [CustomerAddressAttribute] @deprecated(reason: "Use custom_attributesV2 instead.")
167-
custom_attributesV2: [AttributeValueInterface!]! @doc(description: "Custom attributes assigned to the customer address.")
167+
custom_attributesV2(uids: [ID!]): [AttributeValueInterface!]! @doc(description: "Custom attributes assigned to the customer address.") @resolver(class: "Magento\\CustomerGraphQl\\Model\\Resolver\\CustomerAddressCustomAttributeFilter")
168168
extension_attributes: [CustomerAddressAttribute] @doc(description: "Contains any extension attributes for the address.")
169169
}
170170

app/code/Magento/EavGraphQl/Model/GetAttributeValueComposite.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(array $providers = [])
3434
* @param string $entityType
3535
* @param array $customAttribute
3636
* @return array|null
37-
* @throws RuntimeException
37+
* @throws RuntimeException|LocalizedException
3838
*/
3939
public function execute(string $entityType, array $customAttribute): ?array
4040
{

app/code/Magento/EavGraphQl/Model/Output/Value/GetCustomAttributes.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public function execute(string $entity, string $code, string $value): ?array
6363

6464
$result = [
6565
'uid' => $this->uid->encode($entity, $code),
66-
'code' => $code
66+
'code' => $code,
67+
'sort_order' => $attr->getSortOrder() ?? ''
6768
];
6869

6970
if (in_array($attr->getFrontendInput(), $this->frontendInputs)) {

0 commit comments

Comments
 (0)