Skip to content

Commit ed038e1

Browse files
author
Cari Spruiell
committed
Merge remote-tracking branch 'mainline/2.3-develop' into trigger-delivery
2 parents 1f00604 + c10eacb commit ed038e1

File tree

83 files changed

+2765
-395
lines changed

Some content is hidden

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

83 files changed

+2765
-395
lines changed

app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/variations.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,12 @@ define([
357357
var element;
358358

359359
_.each(this.disabledAttributes, function (attribute) {
360-
registry.get('code = ' + attribute, 'index = ' + attribute).disabled(false);
360+
registry.get('index = ' + attribute).disabled(false);
361361
});
362362
this.disabledAttributes = [];
363363

364364
_.each(attributes, function (attribute) {
365-
element = registry.get('code = ' + attribute.code, 'index = ' + attribute.code);
365+
element = registry.get('index = ' + attribute.code);
366366

367367
if (!_.isUndefined(element)) {
368368
element.disabled(true);

app/code/Magento/Eav/Test/Unit/Model/TypeLocatorTest.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
namespace Magento\Eav\Test\Unit\Model;
108

9+
use Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface;
1110
use Magento\Eav\Model\TypeLocator;
1211
use Magento\Eav\Model\TypeLocator\ComplexType as ComplexTypeLocator;
1312
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
@@ -66,7 +65,10 @@ public function testGetType(
6665
$expected
6766
) {
6867
$this->complexType->expects($this->once())->method('getType')->willReturn($expected);
69-
$type = $this->customAttributeTypeLocator->getType($attributeCode, $serviceEntityTypeMapData[$serviceClass]);
68+
$type = $this->customAttributeTypeLocator->getType(
69+
$attributeCode,
70+
$serviceEntityTypeMapData[$serviceClass]
71+
);
7072

7173
$this->assertEquals($expected, $type, 'Expected: ' . $expected . 'but got: ' . $type);
7274
}
@@ -79,16 +81,22 @@ public function getTypeDataProvider()
7981
{
8082
$serviceInterface = \Magento\Catalog\Api\Data\ProductInterface::class;
8183
$eavEntityType = 'catalog_product';
82-
$mediaBackEndModelClass = \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface::class;
83-
$mediaAttributeDataInterface = \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface::class;
84+
$mediaBackEndModelClass = ProductAttributeMediaGalleryEntryInterface::class;
85+
$mediaAttributeDataInterface = ProductAttributeMediaGalleryEntryInterface::class;
8486

85-
$attribute = $this->createPartialMock(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class, ['getBackendModel']);
87+
$attribute = $this->createPartialMock(
88+
\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class,
89+
['getBackendModel']
90+
);
8691

8792
$attribute->expects($this->any())
8893
->method('getBackendModel')
8994
->willReturn($mediaBackEndModelClass);
9095

91-
$attributeNoBackendModel = $this->createPartialMock(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class, ['getBackendModel', 'getFrontendInput']);
96+
$attributeNoBackendModel = $this->createPartialMock(
97+
\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class,
98+
['getBackendModel', 'getFrontendInput']
99+
);
92100

93101
$attributeNoBackendModel->expects($this->any())
94102
->method('getBackendModel')

app/code/Magento/GraphQl/Controller/GraphQl.php

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
use Magento\Framework\App\Request\Http;
1111
use Magento\Framework\App\RequestInterface;
1212
use Magento\Framework\App\ResponseInterface;
13-
use Magento\Framework\Exception\LocalizedException;
1413
use Magento\Framework\Serialize\SerializerInterface;
1514
use Magento\Framework\Webapi\Response;
1615
use Magento\GraphQl\Model\SchemaGeneratorInterface;
17-
use Magento\Framework\GraphQl\RequestProcessor;
16+
use Magento\Framework\GraphQl\QueryProcessor;
1817
use Magento\Framework\GraphQl\ExceptionFormatter;
1918
use Magento\GraphQl\Model\ResolverContext;
19+
use Magento\Framework\GraphQl\HttpRequestProcessor;
2020

2121
/**
2222
* Front controller for web API GraphQL area.
@@ -39,38 +39,50 @@ class GraphQl implements FrontControllerInterface
3939
private $jsonSerializer;
4040

4141
/**
42-
* @var RequestProcessor
42+
* @var QueryProcessor
4343
*/
44-
private $requestProcessor;
44+
private $queryProcessor;
4545

46-
/** @var ExceptionFormatter */
46+
/**
47+
* @var ExceptionFormatter
48+
*/
4749
private $graphQlError;
4850

49-
/** @var ResolverContext */
51+
/**
52+
* @var ResolverContext
53+
*/
5054
private $context;
5155

56+
/**
57+
* @var HttpRequestProcessor
58+
*/
59+
private $requestProcessor;
60+
5261
/**
5362
* @param Response $response
5463
* @param SchemaGeneratorInterface $schemaGenerator
5564
* @param SerializerInterface $jsonSerializer
56-
* @param RequestProcessor $requestProcessor
65+
* @param QueryProcessor $queryProcessor
5766
* @param ExceptionFormatter $graphQlError
5867
* @param ResolverContext $context
68+
* @param HttpRequestProcessor $requestProcessor
5969
*/
6070
public function __construct(
6171
Response $response,
6272
SchemaGeneratorInterface $schemaGenerator,
6373
SerializerInterface $jsonSerializer,
64-
RequestProcessor $requestProcessor,
74+
QueryProcessor $queryProcessor,
6575
ExceptionFormatter $graphQlError,
66-
ResolverContext $context
76+
ResolverContext $context,
77+
HttpRequestProcessor $requestProcessor
6778
) {
6879
$this->response = $response;
6980
$this->schemaGenerator = $schemaGenerator;
7081
$this->jsonSerializer = $jsonSerializer;
71-
$this->requestProcessor = $requestProcessor;
82+
$this->queryProcessor = $queryProcessor;
7283
$this->graphQlError = $graphQlError;
7384
$this->context = $context;
85+
$this->requestProcessor = $requestProcessor;
7486
}
7587

7688
/**
@@ -82,17 +94,11 @@ public function __construct(
8294
public function dispatch(RequestInterface $request)
8395
{
8496
try {
85-
/** @var $request Http */
86-
if ($request->getHeader('Content-Type')
87-
&& strpos($request->getHeader('Content-Type'), 'application/json') !== false
88-
) {
89-
$content = $request->getContent();
90-
$data = $this->jsonSerializer->unserialize($content);
91-
} else {
92-
throw new LocalizedException(__('Request content type must be application/json'));
93-
}
97+
/** @var Http $request */
98+
$this->requestProcessor->processHeaders($request);
99+
$data = $this->jsonSerializer->unserialize($request->getContent());
94100
$schema = $this->schemaGenerator->generate();
95-
$result = $this->requestProcessor->process(
101+
$result = $this->queryProcessor->process(
96102
$schema,
97103
isset($data['query']) ? $data['query'] : '',
98104
null,
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\GraphQl\Controller\HttpHeaderProcessor;
8+
9+
use Magento\Framework\GraphQl\HttpHeaderProcessorInterface;
10+
use Magento\Framework\Exception\LocalizedException;
11+
12+
/**
13+
* Processes the "Content-Type" header entry
14+
*/
15+
class ContentTypeProcessor implements HttpHeaderProcessorInterface
16+
{
17+
/**
18+
* Handle the mandatory application/json header
19+
*
20+
* {@inheritDoc}
21+
* @throws LocalizedException
22+
*/
23+
public function processHeaderValue($headerValue)
24+
{
25+
if (!$headerValue || strpos($headerValue, 'application/json') === false) {
26+
throw new LocalizedException(
27+
new \Magento\Framework\Phrase('Request content type must be application/json')
28+
);
29+
}
30+
}
31+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\GraphQl\Controller\HttpHeaderProcessor;
8+
9+
use Magento\Framework\GraphQl\HttpHeaderProcessorInterface;
10+
use Magento\Framework\Exception\NoSuchEntityException;
11+
use Magento\Store\Model\StoreManagerInterface;
12+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
13+
14+
/**
15+
* Process the "Store" header entry
16+
*/
17+
class StoreProcessor implements HttpHeaderProcessorInterface
18+
{
19+
/**
20+
* @var StoreManagerInterface
21+
*/
22+
private $storeManager;
23+
24+
/**
25+
* StoreProcessor constructor.
26+
* @param StoreManagerInterface $storeManager
27+
*/
28+
public function __construct(StoreManagerInterface $storeManager)
29+
{
30+
$this->storeManager = $storeManager;
31+
}
32+
33+
/**
34+
* Handle the value of the store and set the scope
35+
*
36+
* {@inheritDoc}
37+
* @throws NoSuchEntityException
38+
*/
39+
public function processHeaderValue($headerValue)
40+
{
41+
if ($headerValue) {
42+
$storeCode = ltrim(rtrim($headerValue));
43+
$stores = $this->storeManager->getStores(false, true);
44+
if (isset($stores[$storeCode])) {
45+
$this->storeManager->setCurrentStore($storeCode);
46+
} elseif (strtolower($storeCode) !== 'default') {
47+
throw new GraphQlInputException(
48+
new \Magento\Framework\Phrase('Store code %1 does not exist', [$storeCode])
49+
);
50+
}
51+
}
52+
}
53+
}

app/code/Magento/GraphQl/Model/EntityAttributeList.php

Lines changed: 81 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,106 @@
77
namespace Magento\GraphQl\Model;
88

99
use Magento\Eav\Api\AttributeManagementInterface;
10-
use Magento\Eav\Setup\EavSetupFactory;
11-
use Magento\Eav\Setup\EavSetup;
10+
use Magento\Eav\Api\AttributeSetRepositoryInterface;
11+
use Magento\Eav\Api\Data\AttributeInterface;
12+
use Magento\Framework\Api\FilterBuilder;
13+
use Magento\Framework\Api\MetadataServiceInterface;
14+
use Magento\Framework\Api\SearchCriteriaBuilder;
15+
use Magento\Framework\Exception\NoSuchEntityException;
16+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1217

18+
/**
19+
* Iterate through all attribute sets to retrieve attributes for any given entity type
20+
*/
1321
class EntityAttributeList
1422
{
1523
/**
1624
* @var AttributeManagementInterface
1725
*/
18-
private $management;
26+
private $attributeManagement;
1927

2028
/**
21-
* @var EavSetupFactory
29+
* @var AttributeSetRepositoryInterface
2230
*/
23-
private $eavSetupFactory;
31+
private $attributeSetRepository;
2432

2533
/**
26-
* @var EavSetup
34+
* @var SearchCriteriaBuilder
2735
*/
28-
private $eavSetup;
36+
private $searchCriteriaBuilder;
2937

3038
/**
31-
* @param AttributeManagementInterface $management
32-
* @param EavSetupFactory $eavSetupFactory
39+
* @var FilterBuilder
40+
*/
41+
private $filterBuilder;
42+
43+
/**
44+
* @param AttributeManagementInterface $attributeManagement
45+
* @param AttributeSetRepositoryInterface $attributeSetRepository
46+
* @param SearchCriteriaBuilder $searchCriteriaBuilder
47+
* @param FilterBuilder $filterBuilder
3348
*/
3449
public function __construct(
35-
AttributeManagementInterface $management,
36-
EavSetupFactory $eavSetupFactory
50+
AttributeManagementInterface $attributeManagement,
51+
AttributeSetRepositoryInterface $attributeSetRepository,
52+
SearchCriteriaBuilder $searchCriteriaBuilder,
53+
FilterBuilder $filterBuilder
3754
) {
38-
$this->management = $management;
39-
$this->eavSetupFactory = $eavSetupFactory;
40-
$this->eavSetup = $this->eavSetupFactory->create();
55+
$this->attributeManagement = $attributeManagement;
56+
$this->attributeSetRepository = $attributeSetRepository;
57+
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
58+
$this->filterBuilder = $filterBuilder;
4159
}
4260

43-
public function getDefaultEntityAttributes(string $entityCode)
61+
/**
62+
* Retrieve all EAV and custom attribute codes from all attribute sets for given entity code.
63+
*
64+
* Returned in the format [$attributeCode => $isSortable] with $isSortable being a boolean value where an attribute
65+
* can be sorted with in a search criteria expression. The metadata service parameter is only required if type has
66+
* custom attributes.
67+
*
68+
* @param string $entityCode
69+
* @param MetadataServiceInterface $metadataService
70+
* @return boolean[]
71+
* @throws GraphQlInputException
72+
*/
73+
public function getDefaultEntityAttributes(string $entityCode, MetadataServiceInterface $metadataService = null)
4474
{
45-
$defaultAttributeSetId = $this->eavSetup->getDefaultAttributeSetId($entityCode);
46-
return $this->management->getAttributes($entityCode, $defaultAttributeSetId);
75+
$this->searchCriteriaBuilder->addFilters(
76+
[
77+
$this->filterBuilder
78+
->setField('entity_type_code')
79+
->setValue($entityCode)
80+
->setConditionType('eq')
81+
->create(),
82+
]
83+
);
84+
$attributeSetList = $this->attributeSetRepository->getList($this->searchCriteriaBuilder->create())->getItems();
85+
$attributes = [];
86+
foreach ($attributeSetList as $attributeSet) {
87+
try {
88+
$attributes = array_merge(
89+
$attributes,
90+
$this->attributeManagement->getAttributes($entityCode, $attributeSet->getAttributeSetId())
91+
);
92+
} catch (NoSuchEntityException $exception) {
93+
throw new GraphQlInputException(__('Entity code %1 does not exist.', [$entityCode]));
94+
}
95+
}
96+
$attributeCodes = [];
97+
$metadata = $metadataService ? $metadataService->getCustomAttributesMetadata() : [];
98+
foreach ($metadata as $customAttribute) {
99+
if (!array_key_exists($customAttribute->getAttributeCode(), $attributeCodes)) {
100+
$attributeCodes[$customAttribute->getAttributeCode()] = false;
101+
}
102+
}
103+
/** @var AttributeInterface $attribute */
104+
foreach ($attributes as $attribute) {
105+
if (!array_key_exists($attribute->getAttributeCode(), $attributeCodes)) {
106+
$attributeCodes[$attribute->getAttributeCode()]
107+
= ((! $attribute->getIsUserDefined()) && !is_array($attribute));
108+
}
109+
}
110+
return $attributeCodes;
47111
}
48112
}

app/code/Magento/GraphQl/Model/SchemaGenerator.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,6 @@ public function generate()
8484
'fields' => $schemaConfig['fields'],
8585
'resolveField' => function ($value, $args, $context, ResolveInfo $info) {
8686
$fieldName = $info->fieldName;
87-
$fieldNodes = $info->fieldNodes;
88-
$selections = [];
89-
// foreach ($fieldNodes as $fieldNode) {
90-
// foreach ($fieldNode->selectionSet->selections as $field) {
91-
// $name = $field->name;
92-
// if (isset($field->selectionSet)) {
93-
// $selections[$name] = $this->getFields;
94-
// }
95-
// foreach ($field->selectionSet->selections as $selection) {
96-
// $selections[$name] = $selection->name;
97-
// }
98-
// }
99-
// }
10087
$resolver = $this->resolverFactory->create($fieldName);
10188

10289
$fieldArguments = [];

0 commit comments

Comments
 (0)