-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8222 from magento-lynx/eav-graphql
- Loading branch information
Showing
37 changed files
with
2,655 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
app/code/Magento/Customer/Test/Fixture/CustomerAttribute.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Customer\Test\Fixture; | ||
|
||
use Magento\Customer\Model\Attribute; | ||
use Magento\Customer\Model\ResourceModel\Attribute as ResourceModelAttribute; | ||
use Magento\Eav\Api\AttributeRepositoryInterface; | ||
use Magento\Eav\Model\AttributeFactory; | ||
use Magento\Framework\DataObject; | ||
use Magento\Framework\Exception\InvalidArgumentException; | ||
use Magento\TestFramework\Fixture\Api\DataMerger; | ||
use Magento\TestFramework\Fixture\Data\ProcessorInterface; | ||
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface; | ||
|
||
class CustomerAttribute implements RevertibleDataFixtureInterface | ||
{ | ||
private const DEFAULT_DATA = [ | ||
'entity_type_id' => null, | ||
'attribute_id' => null, | ||
'attribute_code' => 'attribute%uniqid%', | ||
'default_frontend_label' => 'Attribute%uniqid%', | ||
'frontend_labels' => [], | ||
'frontend_input' => 'text', | ||
'backend_type' => 'varchar', | ||
'is_required' => false, | ||
'is_user_defined' => true, | ||
'note' => null, | ||
'backend_model' => null, | ||
'source_model' => null, | ||
'default_value' => null, | ||
'is_unique' => '0', | ||
'frontend_class' => null, | ||
'used_in_forms' => [], | ||
]; | ||
|
||
/** | ||
* @var DataMerger | ||
*/ | ||
private DataMerger $dataMerger; | ||
|
||
/** | ||
* @var ProcessorInterface | ||
*/ | ||
private ProcessorInterface $processor; | ||
|
||
/** | ||
* @var AttributeFactory | ||
*/ | ||
private AttributeFactory $attributeFactory; | ||
|
||
/** | ||
* @var ResourceModelAttribute | ||
*/ | ||
private ResourceModelAttribute $resourceModelAttribute; | ||
|
||
/** | ||
* @var AttributeRepositoryInterface | ||
*/ | ||
private AttributeRepositoryInterface $attributeRepository; | ||
|
||
/** | ||
* @param DataMerger $dataMerger | ||
* @param ProcessorInterface $processor | ||
* @param AttributeRepositoryInterface $attributeRepository | ||
* @param AttributeFactory $attributeFactory | ||
* @param ResourceModelAttribute $resourceModelAttribute | ||
*/ | ||
public function __construct( | ||
DataMerger $dataMerger, | ||
ProcessorInterface $processor, | ||
AttributeRepositoryInterface $attributeRepository, | ||
AttributeFactory $attributeFactory, | ||
ResourceModelAttribute $resourceModelAttribute | ||
) { | ||
$this->dataMerger = $dataMerger; | ||
$this->processor = $processor; | ||
$this->attributeFactory = $attributeFactory; | ||
$this->resourceModelAttribute = $resourceModelAttribute; | ||
$this->attributeRepository = $attributeRepository; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function apply(array $data = []): ?DataObject | ||
{ | ||
if (empty($data['entity_type_id'])) { | ||
throw new InvalidArgumentException( | ||
__( | ||
'"%field" value is required to create an attribute', | ||
[ | ||
'field' => 'entity_type_id' | ||
] | ||
) | ||
); | ||
} | ||
|
||
/** @var Attribute $attr */ | ||
$attr = $this->attributeFactory->createAttribute(Attribute::class, self::DEFAULT_DATA); | ||
$mergedData = $this->processor->process($this, $this->dataMerger->merge(self::DEFAULT_DATA, $data)); | ||
$attr->setData($mergedData); | ||
$this->resourceModelAttribute->save($attr); | ||
return $attr; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function revert(DataObject $data): void | ||
{ | ||
$this->attributeRepository->deleteById($data['attribute_id']); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
app/code/Magento/CustomerGraphQl/Model/Customer/GetAttributesForm.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CustomerGraphQl\Model\Customer; | ||
|
||
use Magento\Customer\Api\MetadataInterface; | ||
use Magento\EavGraphQl\Model\GetAttributesFormInterface; | ||
use Magento\EavGraphQl\Model\Uid; | ||
|
||
/** | ||
* Attributes form provider for customer | ||
*/ | ||
class GetAttributesForm implements GetAttributesFormInterface | ||
{ | ||
/** | ||
* @var MetadataInterface | ||
*/ | ||
private MetadataInterface $entity; | ||
|
||
/** | ||
* @var Uid | ||
*/ | ||
private Uid $uid; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private string $type; | ||
|
||
/** | ||
* @param MetadataInterface $metadata | ||
* @param Uid $uid | ||
* @param string $type | ||
*/ | ||
public function __construct(MetadataInterface $metadata, Uid $uid, string $type) | ||
{ | ||
$this->entity = $metadata; | ||
$this->uid = $uid; | ||
$this->type = $type; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function execute(string $formCode): ?array | ||
{ | ||
$attributes = []; | ||
foreach ($this->entity->getAttributes($formCode) as $attribute) { | ||
$attributes[] = $this->uid->encode($this->type, $attribute->getAttributeCode()); | ||
} | ||
return $attributes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.