Skip to content

Commit bb53584

Browse files
authored
LYNX-167: Remove UID and set attribute code as ID
1 parent d865701 commit bb53584

34 files changed

+44
-481
lines changed

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,12 @@
1010
use Magento\Eav\Model\AttributeRepository;
1111
use Magento\EavGraphQl\Model\GetAttributeSelectedOptionComposite;
1212
use Magento\EavGraphQl\Model\GetAttributeValueInterface;
13-
use Magento\EavGraphQl\Model\Uid;
1413

1514
/**
1615
* Custom attribute value provider for customer
1716
*/
1817
class GetCustomAttributes implements GetAttributeValueInterface
1918
{
20-
/**
21-
* @var Uid
22-
*/
23-
private Uid $uid;
24-
2519
/**
2620
* @var AttributeRepository
2721
*/
@@ -38,18 +32,15 @@ class GetCustomAttributes implements GetAttributeValueInterface
3832
private array $frontendInputs;
3933

4034
/**
41-
* @param Uid $uid
4235
* @param AttributeRepository $attributeRepository
4336
* @param GetAttributeSelectedOptionComposite $attributeSelectedOptionComposite
4437
* @param array $frontendInputs
4538
*/
4639
public function __construct(
47-
Uid $uid,
4840
AttributeRepository $attributeRepository,
4941
GetAttributeSelectedOptionComposite $attributeSelectedOptionComposite,
5042
array $frontendInputs = []
5143
) {
52-
$this->uid = $uid;
5344
$this->attributeRepository = $attributeRepository;
5445
$this->frontendInputs = $frontendInputs;
5546
$this->attributeSelectedOptionComposite = $attributeSelectedOptionComposite;
@@ -66,10 +57,7 @@ public function execute(string $entityType, array $customAttribute): ?array
6657
);
6758

6859
$result = [
69-
'uid' => $this->uid->encode(
70-
$entityType,
71-
$customAttribute['attribute_code']
72-
),
60+
'entity_type' => $entityType,
7361
'code' => $customAttribute['attribute_code'],
7462
'sort_order' => $attr->getSortOrder() ?? ''
7563
];

app/code/Magento/CustomerGraphQl/Model/Output/CustomerAttributeMetadata.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,15 @@
1111
use Magento\Customer\Model\Data\ValidationRule;
1212
use Magento\Eav\Api\Data\AttributeInterface;
1313
use Magento\EavGraphQl\Model\Output\GetAttributeDataInterface;
14-
use Magento\EavGraphQl\Model\Uid as AttributeUid;
1514
use Magento\Framework\Exception\LocalizedException;
1615
use Magento\Framework\Exception\NoSuchEntityException;
1716
use Magento\Framework\GraphQl\Query\EnumLookup;
18-
use Magento\Framework\GraphQl\Query\Uid;
1917

2018
/**
2119
* Format attributes metadata for GraphQL output
2220
*/
2321
class CustomerAttributeMetadata implements GetAttributeDataInterface
2422
{
25-
/**
26-
* @var AttributeUid
27-
*/
28-
private AttributeUid $attributeUid;
29-
30-
/**
31-
* @var Uid
32-
*/
33-
private Uid $uid;
34-
3523
/**
3624
* @var EnumLookup
3725
*/
@@ -48,21 +36,15 @@ class CustomerAttributeMetadata implements GetAttributeDataInterface
4836
private string $entityType;
4937

5038
/**
51-
* @param AttributeUid $attributeUid
52-
* @param Uid $uid
5339
* @param EnumLookup $enumLookup
5440
* @param MetadataInterface $metadata
5541
* @param string $entityType
5642
*/
5743
public function __construct(
58-
AttributeUid $attributeUid,
59-
Uid $uid,
6044
EnumLookup $enumLookup,
6145
MetadataInterface $metadata,
6246
string $entityType
6347
) {
64-
$this->attributeUid = $attributeUid;
65-
$this->uid = $uid;
6648
$this->enumLookup = $enumLookup;
6749
$this->metadata = $metadata;
6850
$this->entityType = $entityType;
@@ -103,8 +85,7 @@ public function execute(
10385

10486
if ($attributeMetadata->isVisible()) {
10587
$data = [
106-
'input_filter' =>
107-
empty($attributeMetadata->getInputFilter())
88+
'input_filter' => empty($attributeMetadata->getInputFilter())
10889
? 'NONE'
10990
: $this->enumLookup->getEnumValueFromField(
11091
'InputFilterEnum',

app/code/Magento/CustomerGraphQl/Model/Resolver/CustomAttributeFilter.php

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
namespace Magento\CustomerGraphQl\Model\Resolver;
99

10-
use Magento\CustomerGraphQl\Model\Customer\ExtractCustomerData;
11-
use Magento\CustomerGraphQl\Model\Customer\GetCustomer;
1210
use Magento\Framework\Api\CustomAttributesDataInterface;
1311
use Magento\Framework\GraphQl\Config\Element\Field;
1412
use Magento\Framework\GraphQl\Query\ResolverInterface;
@@ -19,28 +17,6 @@
1917
*/
2018
class CustomAttributeFilter implements ResolverInterface
2119
{
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-
4420
/**
4521
* @inheritdoc
4622
*/
@@ -52,10 +28,10 @@ public function resolve(
5228
array $args = null
5329
): array {
5430
$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);
31+
if (!empty($args['attributeCodes'])) {
32+
$attributeCodes = array_values($args['attributeCodes']);
33+
return array_filter($customAttributes, function ($attr) use ($attributeCodes) {
34+
return in_array($attr['code'], $attributeCodes);
5935
});
6036
}
6137

app/code/Magento/CustomerGraphQl/Model/Resolver/CustomerAddressCustomAttributeFilter.php

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
namespace Magento\CustomerGraphQl\Model\Resolver;
99

10-
use Magento\CustomerGraphQl\Model\Customer\Address\ExtractCustomerAddressData;
11-
use Magento\CustomerGraphQl\Model\Customer\Address\GetCustomerAddress;
1210
use Magento\Framework\Api\CustomAttributesDataInterface;
1311
use Magento\Framework\GraphQl\Config\Element\Field;
1412
use Magento\Framework\GraphQl\Query\ResolverInterface;
@@ -19,28 +17,6 @@
1917
*/
2018
class CustomerAddressCustomAttributeFilter implements ResolverInterface
2119
{
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-
4420
/**
4521
* @inheritdoc
4622
*/
@@ -52,10 +28,10 @@ public function resolve(
5228
array $args = null
5329
): array {
5430
$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);
31+
if (isset($args['attributeCodes']) && !empty($args['attributeCodes'])) {
32+
$attributeCodes = array_values($args['attributeCodes']);
33+
return array_filter($customAttributes, function ($attr) use ($attributeCodes) {
34+
return in_array($attr['code'], $attributeCodes);
5935
});
6036
}
6137

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(uids: [ID!]): [AttributeValueInterface] @doc(description: "Customer's custom attributes.") @resolver(class: "Magento\\CustomerGraphQl\\Model\\Resolver\\CustomAttributeFilter")
142+
custom_attributes(attributeCodes: [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(uids: [ID!]): [AttributeValueInterface!]! @doc(description: "Custom attributes assigned to the customer address.") @resolver(class: "Magento\\CustomerGraphQl\\Model\\Resolver\\CustomerAddressCustomAttributeFilter")
167+
custom_attributesV2(attributeCodes: [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/Eav/Model/Entity/Attribute.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
2+
23
/**
34
* Copyright © Magento, Inc. All rights reserved.
45
* See COPYING.txt for license details.
56
*/
7+
68
namespace Magento\Eav\Model\Entity;
79

810
use Magento\Eav\Model\ReservedAttributeCheckerInterface;
@@ -533,13 +535,13 @@ public function getIdentities()
533535
strtoupper($this->getEntityType()->getEntityTypeCode())
534536
);
535537

536-
$formsUsedBeforeChange = $this->getOrigData('used_in_forms') ?? [];
538+
$usedBeforeChange = $this->getOrigData('used_in_forms') ?? [];
537539
$usedInForms = $this->getUsedInForms() ?? [];
538540

539-
if ($formsUsedBeforeChange != $usedInForms) {
541+
if (is_array($usedBeforeChange) && is_array($usedInForms) && ($usedBeforeChange != $usedInForms)) {
540542
$formsToInvalidate = array_merge(
541-
array_diff($formsUsedBeforeChange, $usedInForms),
542-
array_diff($usedInForms, $formsUsedBeforeChange)
543+
array_diff($usedBeforeChange, $usedInForms),
544+
array_diff($usedInForms, $usedBeforeChange)
543545
);
544546

545547
foreach ($formsToInvalidate as $form) {

app/code/Magento/EavGraphQl/Model/Output/GetAttributeData.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,24 @@
1111

1212
use Magento\Eav\Api\Data\AttributeInterface;
1313
use Magento\Eav\Api\Data\AttributeOptionInterface;
14-
use Magento\EavGraphQl\Model\Uid as AttributeUid;
1514
use Magento\Framework\Exception\RuntimeException;
1615
use Magento\Framework\GraphQl\Query\EnumLookup;
17-
use Magento\Framework\GraphQl\Query\Uid;
1816

1917
/**
2018
* Format attributes for GraphQL output
2119
*/
2220
class GetAttributeData implements GetAttributeDataInterface
2321
{
24-
/**
25-
* @var AttributeUid
26-
*/
27-
private AttributeUid $attributeUid;
28-
29-
/**
30-
* @var Uid
31-
*/
32-
private Uid $uid;
33-
3422
/**
3523
* @var EnumLookup
3624
*/
3725
private EnumLookup $enumLookup;
3826

3927
/**
40-
* @param AttributeUid $attributeUid
41-
* @param Uid $uid
4228
* @param EnumLookup $enumLookup
4329
*/
44-
public function __construct(AttributeUid $attributeUid, Uid $uid, EnumLookup $enumLookup)
30+
public function __construct(EnumLookup $enumLookup)
4531
{
46-
$this->attributeUid = $attributeUid;
47-
$this->uid = $uid;
4832
$this->enumLookup = $enumLookup;
4933
}
5034

@@ -64,7 +48,6 @@ public function execute(
6448
): array {
6549
return [
6650
'id' => $attribute->getAttributeId(),
67-
'uid' => $this->attributeUid->encode($entityType, $attribute->getAttributeCode()),
6851
'code' => $attribute->getAttributeCode(),
6952
'label' => $attribute->getStoreLabel($storeId),
7053
'sort_order' => $attribute->getPosition(),
@@ -123,7 +106,6 @@ function (AttributeOptionInterface $option) use ($attribute) {
123106
return null;
124107
}
125108
return [
126-
'uid' => $this->uid->encode($value),
127109
'label' => $label,
128110
'value' => $value,
129111
'is_default' => $attribute->getDefaultValue() ?

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@
99

1010
use Magento\Eav\Model\AttributeRepository;
1111
use Magento\EavGraphQl\Model\Output\Value\Options\GetAttributeSelectedOptionInterface;
12-
use Magento\EavGraphQl\Model\Uid;
1312

1413
/**
1514
* Custom attribute value provider for customer
1615
*/
1716
class GetCustomAttributes implements GetAttributeValueInterface
1817
{
19-
/**
20-
* @var Uid
21-
*/
22-
private Uid $uid;
23-
2418
/**
2519
* @var AttributeRepository
2620
*/
@@ -37,18 +31,15 @@ class GetCustomAttributes implements GetAttributeValueInterface
3731
private array $frontendInputs;
3832

3933
/**
40-
* @param Uid $uid
4134
* @param AttributeRepository $attributeRepository
4235
* @param GetAttributeSelectedOptionInterface $getAttributeSelectedOption
4336
* @param array $frontendInputs
4437
*/
4538
public function __construct(
46-
Uid $uid,
4739
AttributeRepository $attributeRepository,
4840
GetAttributeSelectedOptionInterface $getAttributeSelectedOption,
4941
array $frontendInputs = []
5042
) {
51-
$this->uid = $uid;
5243
$this->attributeRepository = $attributeRepository;
5344
$this->frontendInputs = $frontendInputs;
5445
$this->getAttributeSelectedOption = $getAttributeSelectedOption;
@@ -62,7 +53,7 @@ public function execute(string $entity, string $code, string $value): ?array
6253
$attr = $this->attributeRepository->get($entity, $code);
6354

6455
$result = [
65-
'uid' => $this->uid->encode($entity, $code),
56+
'entity_type' => $entity,
6657
'code' => $code,
6758
'sort_order' => $attr->getSortOrder() ?? ''
6859
];

0 commit comments

Comments
 (0)