Skip to content

Commit 664a673

Browse files
authored
Merge pull request #3678 from magento-engcom/graphql-develop-prs
[EngCom] Public Pull Requests - GraphQL
2 parents 68a02ca + b56e52e commit 664a673

File tree

13 files changed

+738
-19
lines changed

13 files changed

+738
-19
lines changed

app/code/Magento/BundleGraphQl/Model/Resolver/Options/Collection.php

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function __construct(
6161
* Add parent id/sku pair to use for option filter at fetch time.
6262
*
6363
* @param int $parentId
64+
* @param int $parentEntityId
6465
* @param string $sku
6566
*/
6667
public function addParentFilterData(int $parentId, int $parentEntityId, string $sku) : void

app/code/Magento/CatalogGraphQl/Model/Category/LevelCalculator.php

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
*/
1616
class LevelCalculator
1717
{
18+
/**
19+
* @var ResourceConnection
20+
*/
21+
private $resourceConnection;
22+
23+
/**
24+
* @var Category
25+
*/
26+
private $resourceCategory;
27+
1828
/**
1929
* @param ResourceConnection $resourceConnection
2030
* @param Category $resourceCategory
@@ -39,6 +49,7 @@ public function calculate(int $rootCategoryId) : int
3949
$select = $connection->select()
4050
->from($this->resourceConnection->getTableName('catalog_category_entity'), 'level')
4151
->where($this->resourceCategory->getLinkField() . " = ?", $rootCategoryId);
52+
4253
return (int) $connection->fetchOne($select);
4354
}
4455
}

app/code/Magento/ConfigurableProductGraphQl/Model/ConfigurableProductTypeResolver.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,25 @@
88
namespace Magento\ConfigurableProductGraphQl\Model;
99

1010
use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface;
11+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable as Type;
1112

1213
/**
13-
* {@inheritdoc}
14+
* @inheritdoc
1415
*/
1516
class ConfigurableProductTypeResolver implements TypeResolverInterface
1617
{
1718
/**
18-
* {@inheritdoc}
19+
* Configurable product type resolver code
1920
*/
20-
public function resolveType(array $data) : string
21+
const TYPE_RESOLVER = 'ConfigurableProduct';
22+
23+
/**
24+
* @inheritdoc
25+
*/
26+
public function resolveType(array $data): string
2127
{
22-
if (isset($data['type_id']) && $data['type_id'] == 'configurable') {
23-
return 'ConfigurableProduct';
28+
if (isset($data['type_id']) && $data['type_id'] == Type::TYPE_CODE) {
29+
return self::TYPE_RESOLVER;
2430
}
2531
return '';
2632
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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\Customer;
9+
10+
use Magento\Customer\Api\AccountManagementInterface;
11+
use Magento\Customer\Api\Data\CustomerInterface;
12+
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
13+
use Magento\Framework\Api\DataObjectHelper;
14+
use Magento\Framework\Exception\LocalizedException;
15+
use Magento\Framework\Exception\NoSuchEntityException;
16+
use Magento\Store\Model\StoreManagerInterface;
17+
18+
/**
19+
* Class CreateAccount creates new customer account
20+
*/
21+
class CreateAccount
22+
{
23+
/**
24+
* @var DataObjectHelper
25+
*/
26+
private $dataObjectHelper;
27+
28+
/**
29+
* @var CustomerInterfaceFactory
30+
*/
31+
private $customerFactory;
32+
33+
/**
34+
* @var AccountManagementInterface
35+
*/
36+
private $accountManagement;
37+
38+
/**
39+
* @var StoreManagerInterface
40+
*/
41+
private $storeManager;
42+
43+
/**
44+
* @param DataObjectHelper $dataObjectHelper
45+
* @param CustomerInterfaceFactory $customerFactory
46+
* @param StoreManagerInterface $storeManager
47+
* @param AccountManagementInterface $accountManagement
48+
*/
49+
public function __construct(
50+
DataObjectHelper $dataObjectHelper,
51+
CustomerInterfaceFactory $customerFactory,
52+
StoreManagerInterface $storeManager,
53+
AccountManagementInterface $accountManagement
54+
) {
55+
$this->dataObjectHelper = $dataObjectHelper;
56+
$this->customerFactory = $customerFactory;
57+
$this->accountManagement = $accountManagement;
58+
$this->storeManager = $storeManager;
59+
}
60+
61+
/**
62+
* Creates new customer account
63+
*
64+
* @param array $args
65+
* @return CustomerInterface
66+
* @throws LocalizedException
67+
* @throws NoSuchEntityException
68+
*/
69+
public function execute(array $args): CustomerInterface
70+
{
71+
$customerDataObject = $this->customerFactory->create();
72+
$this->dataObjectHelper->populateWithArray(
73+
$customerDataObject,
74+
$args['input'],
75+
CustomerInterface::class
76+
);
77+
$store = $this->storeManager->getStore();
78+
$customerDataObject->setWebsiteId($store->getWebsiteId());
79+
$customerDataObject->setStoreId($store->getId());
80+
81+
$password = array_key_exists('password', $args['input']) ? $args['input']['password'] : null;
82+
83+
return $this->accountManagement->createAccount($customerDataObject, $password);
84+
}
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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\Customer;
9+
10+
use Magento\Customer\Api\Data\CustomerInterface;
11+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
12+
use Magento\Authorization\Model\UserContextInterface;
13+
14+
/**
15+
* Set up user context after creating new customer account
16+
*/
17+
class SetUpUserContext
18+
{
19+
/**
20+
* Set up user context after creating new customer account
21+
*
22+
* @param ContextInterface $context
23+
* @param CustomerInterface $customer
24+
*/
25+
public function execute(ContextInterface $context, CustomerInterface $customer)
26+
{
27+
$context->setUserId((int)$customer->getId());
28+
$context->setUserType(UserContextInterface::USER_TYPE_CUSTOMER);
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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\ChangeSubscriptionStatus;
11+
use Magento\CustomerGraphQl\Model\Customer\CreateAccount;
12+
use Magento\CustomerGraphQl\Model\Customer\CustomerDataProvider;
13+
use Magento\CustomerGraphQl\Model\Customer\SetUpUserContext;
14+
use Magento\Framework\Exception\State\InputMismatchException;
15+
use Magento\Framework\GraphQl\Config\Element\Field;
16+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
17+
use Magento\Framework\GraphQl\Query\ResolverInterface;
18+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
19+
use Magento\Framework\Validator\Exception as ValidatorException;
20+
21+
/**
22+
* Create customer account resolver
23+
*/
24+
class CreateCustomer implements ResolverInterface
25+
{
26+
/**
27+
* @var CustomerDataProvider
28+
*/
29+
private $customerDataProvider;
30+
31+
/**
32+
* @var ChangeSubscriptionStatus
33+
*/
34+
private $changeSubscriptionStatus;
35+
36+
/**
37+
* @var CreateAccount
38+
*/
39+
private $createAccount;
40+
41+
/**
42+
* @var SetUpUserContext
43+
*/
44+
private $setUpUserContext;
45+
46+
/**
47+
* @param CustomerDataProvider $customerDataProvider
48+
* @param ChangeSubscriptionStatus $changeSubscriptionStatus
49+
* @param SetUpUserContext $setUpUserContext
50+
* @param CreateAccount $createAccount
51+
*/
52+
public function __construct(
53+
CustomerDataProvider $customerDataProvider,
54+
ChangeSubscriptionStatus $changeSubscriptionStatus,
55+
SetUpUserContext $setUpUserContext,
56+
CreateAccount $createAccount
57+
) {
58+
$this->customerDataProvider = $customerDataProvider;
59+
$this->changeSubscriptionStatus = $changeSubscriptionStatus;
60+
$this->createAccount = $createAccount;
61+
$this->setUpUserContext = $setUpUserContext;
62+
}
63+
64+
/**
65+
* @inheritdoc
66+
*/
67+
public function resolve(
68+
Field $field,
69+
$context,
70+
ResolveInfo $info,
71+
array $value = null,
72+
array $args = null
73+
) {
74+
if (!isset($args['input']) || !is_array($args['input']) || empty($args['input'])) {
75+
throw new GraphQlInputException(__('"input" value should be specified'));
76+
}
77+
try {
78+
$customer = $this->createAccount->execute($args);
79+
$customerId = (int)$customer->getId();
80+
$this->setUpUserContext->execute($context, $customer);
81+
if (array_key_exists('is_subscribed', $args['input'])) {
82+
if ($args['input']['is_subscribed']) {
83+
$this->changeSubscriptionStatus->execute($customerId, true);
84+
}
85+
}
86+
$data = $this->customerDataProvider->getCustomerById($customerId);
87+
} catch (ValidatorException $e) {
88+
throw new GraphQlInputException(__($e->getMessage()));
89+
} catch (InputMismatchException $e) {
90+
throw new GraphQlInputException(__($e->getMessage()));
91+
}
92+
93+
return ['customer' => $data];
94+
}
95+
}

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

+16-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ type Query {
88
type Mutation {
99
generateCustomerToken(email: String!, password: String!): CustomerToken @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\GenerateCustomerToken") @doc(description:"Retrieve the customer token")
1010
changeCustomerPassword(currentPassword: String!, newPassword: String!): Customer @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\ChangePassword") @doc(description:"Changes the password for the logged-in customer")
11-
updateCustomer (input: UpdateCustomerInput!): UpdateCustomerOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\UpdateCustomer") @doc(description:"Update the customer's personal information")
11+
createCustomer (input: CustomerInput!): CustomerOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\CreateCustomer") @doc(description:"Create customer account")
12+
updateCustomer (input: CustomerInput!): CustomerOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\UpdateCustomer") @doc(description:"Update the customer's personal information")
1213
revokeCustomerToken: RevokeCustomerTokenOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\RevokeCustomerToken") @doc(description:"Revoke the customer token")
1314
createCustomerAddress(input: CustomerAddressInput!): CustomerAddress @resolver(class: "Magento\\CustomerGraphQl\\Model\\Resolver\\CreateCustomerAddress") @doc(description: "Create customer address")
1415
updateCustomerAddress(id: Int!, input: CustomerAddressInput): CustomerAddress @resolver(class: "Magento\\CustomerGraphQl\\Model\\Resolver\\UpdateCustomerAddress") @doc(description: "Update customer address")
@@ -50,15 +51,21 @@ type CustomerToken {
5051
token: String @doc(description: "The customer token")
5152
}
5253

53-
input UpdateCustomerInput {
54-
firstname: String
55-
lastname: String
56-
email: String
57-
password: String
58-
is_subscribed: Boolean
54+
input CustomerInput {
55+
prefix: String @doc(description: "An honorific, such as Dr., Mr., or Mrs.")
56+
firstname: String @doc(description: "The customer's first name")
57+
middlename: String @doc(description: "The customer's middle name")
58+
lastname: String @doc(description: "The customer's family name")
59+
suffix: String @doc(description: "A value such as Sr., Jr., or III")
60+
email: String @doc(description: "The customer's email address. Required")
61+
dob: String @doc(description: "The customer's date of birth")
62+
taxvat: String @doc(description: "The customer's Tax/VAT number (for corporate customers)")
63+
gender: Int @doc(description: "The customer's gender(Male - 1, Female - 2)")
64+
password: String @doc(description: "The customer's password")
65+
is_subscribed: Boolean @doc(description: "Indicates whether the customer is subscribed to the company's newsletter")
5966
}
6067

61-
type UpdateCustomerOutput {
68+
type CustomerOutput {
6269
customer: Customer!
6370
}
6471

@@ -365,4 +372,4 @@ enum CountryCodeEnum @doc(description: "The list of countries codes") {
365372
YE @doc(description: "Yemen")
366373
ZM @doc(description: "Zambia")
367374
ZW @doc(description: "Zimbabwe")
368-
}
375+
}

app/code/Magento/QuoteGraphQl/Model/Cart/ExtractDataFromCart.php

+3
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ public function execute(Quote $cart): array
4040
];
4141
}
4242

43+
$appliedCoupon = $cart->getCouponCode();
44+
4345
return [
4446
'items' => $items,
47+
'applied_coupon' => $appliedCoupon ? ['code' => $appliedCoupon] : null
4548
];
4649
}
4750
}

0 commit comments

Comments
 (0)