Skip to content

Commit 3cbe632

Browse files
🔃 [Magento Community Engineering] Community Contributions - GraphQL
Accepted Community Pull Requests:
2 parents e7e3377 + 586edd8 commit 3cbe632

35 files changed

+284
-136
lines changed

app/code/Magento/ConfigurableProductGraphQl/Model/Cart/BuyRequest/SuperAttributeDataProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Catalog\Api\Data\ProductInterface;
1111
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1213
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1314
use Magento\Framework\Stdlib\ArrayManager;
1415
use Magento\QuoteGraphQl\Model\Cart\BuyRequest\BuyRequestDataProviderInterface;
@@ -76,6 +77,10 @@ public function execute(array $cartItemData): array
7677
} catch (NoSuchEntityException $e) {
7778
throw new GraphQlNoSuchEntityException(__('Could not find specified product.'));
7879
}
80+
$configurableProductLinks = $parentProduct->getExtensionAttributes()->getConfigurableProductLinks();
81+
if (!in_array($product->getId(), $configurableProductLinks)) {
82+
throw new GraphQlInputException(__('Could not find specified product.'));
83+
}
7984
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
8085
$this->optionCollection->addProductId((int)$parentProduct->getData($linkField));
8186
$options = $this->optionCollection->getAttributesByProductId((int)$parentProduct->getData($linkField));

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,16 @@ public function execute(CustomerInterface $customer): array
101101
}
102102
}
103103
$customerData = array_merge($customerData, $customAttributes);
104-
//Field is deprecated and should not be exposed on storefront.
104+
//Fields are deprecated and should not be exposed on storefront.
105105
$customerData['group_id'] = null;
106-
$customerData['model'] = $customer;
107106
$customerData['id'] = null;
108107

108+
$customerData['model'] = $customer;
109+
110+
//'dob' is deprecated, 'date_of_birth' is used instead.
111+
if (!empty($customerData['dob'])) {
112+
$customerData['date_of_birth'] = $customerData['dob'];
113+
}
109114
return $customerData;
110115
}
111116
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ public function resolve(
7070
if (!$this->newsLetterConfig->isActive(ScopeInterface::SCOPE_STORE)) {
7171
$args['input']['is_subscribed'] = false;
7272
}
73-
73+
if (isset($args['input']['date_of_birth'])) {
74+
$args['input']['dob'] = $args['input']['date_of_birth'];
75+
}
7476
$customer = $this->createCustomerAccount->execute(
7577
$args['input'],
7678
$context->getExtensionAttributes()->getStore()

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public function resolve(
7070
if (empty($args['input']) || !is_array($args['input'])) {
7171
throw new GraphQlInputException(__('"input" value should be specified'));
7272
}
73+
if (isset($args['input']['date_of_birth'])) {
74+
$args['input']['dob'] = $args['input']['date_of_birth'];
75+
}
7376

7477
$customer = $this->getCustomer->execute($context);
7578
$this->updateCustomerAccount->execute(

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ input CustomerInput {
6060
middlename: String @doc(description: "The customer's middle name")
6161
lastname: String @doc(description: "The customer's family name")
6262
suffix: String @doc(description: "A value such as Sr., Jr., or III")
63-
email: String @doc(description: "The customer's email address. Required")
64-
dob: String @doc(description: "The customer's date of birth")
63+
email: String! @doc(description: "The customer's email address. Required")
64+
dob: String @doc(description: "Deprecated: Use `date_of_birth` instead")
65+
date_of_birth: String @doc(description: "The customer's date of birth")
6566
taxvat: String @doc(description: "The customer's Tax/VAT number (for corporate customers)")
66-
gender: Int @doc(description: "The customer's gender(Male - 1, Female - 2)")
67+
gender: Int @doc(description: "The customer's gender (Male - 1, Female - 2)")
6768
password: String @doc(description: "The customer's password")
6869
is_subscribed: Boolean @doc(description: "Indicates whether the customer is subscribed to the company's newsletter")
6970
}
@@ -87,12 +88,13 @@ type Customer @doc(description: "Customer defines the customer name and address
8788
email: String @doc(description: "The customer's email address. Required")
8889
default_billing: String @doc(description: "The ID assigned to the billing address")
8990
default_shipping: String @doc(description: "The ID assigned to the shipping address")
90-
dob: String @doc(description: "The customer's date of birth")
91-
taxvat: String @doc(description: "The customer's Tax/VAT number (for corporate customers)")
91+
dob: String @doc(description: "The customer's date of birth") @deprecated(reason: "Use `date_of_birth` instead")
92+
date_of_birth: String @doc(description: "The customer's date of birth")
93+
taxvat: String @doc(description: "The customer's Value-added tax (VAT) number (for corporate customers)")
9294
id: Int @doc(description: "The ID assigned to the customer") @deprecated(reason: "id is not needed as part of Customer because on server side it can be identified based on customer token used for authentication. There is no need to know customer ID on the client side.")
9395
is_subscribed: Boolean @doc(description: "Indicates whether the customer is subscribed to the company's newsletter") @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\IsSubscribed")
9496
addresses: [CustomerAddress] @doc(description: "An array containing the customer's shipping and billing addresses") @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\CustomerAddresses")
95-
gender: Int @doc(description: "The customer's gender(Male - 1, Female - 2)")
97+
gender: Int @doc(description: "The customer's gender (Male - 1, Female - 2)")
9698
}
9799

98100
type CustomerAddress @doc(description: "CustomerAddress contains detailed information about a customer's billing and shipping addresses"){
@@ -112,7 +114,7 @@ type CustomerAddress @doc(description: "CustomerAddress contains detailed inform
112114
middlename: String @doc(description: "The middle name of the person associated with the shipping/billing address")
113115
prefix: String @doc(description: "An honorific, such as Dr., Mr., or Mrs.")
114116
suffix: String @doc(description: "A value such as Sr., Jr., or III")
115-
vat_id: String @doc(description: "The customer's Tax/VAT number (for corporate customers)")
117+
vat_id: String @doc(description: "The customer's Value-added tax (VAT) number (for corporate customers)")
116118
default_shipping: Boolean @doc(description: "Indicates whether the address is the default shipping address")
117119
default_billing: Boolean @doc(description: "Indicates whether the address is the default billing address")
118120
custom_attributes: [CustomerAddressAttribute] @deprecated(reason: "Custom attributes should not be put into container")

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type Query {
77
}
88

99
type Mutation {
10-
createPaypalExpressToken(input: PaypalExpressTokenInput!): PaypalExpressToken @resolver(class: "\\Magento\\PaypalGraphQl\\Model\\Resolver\\PaypalExpressToken") @doc(description:"Initiates an Express Checkout transaction and receives a token. Use this mutation for Express Checkout and Payments Standard payment methods.")
10+
createPaypalExpressToken(input: PaypalExpressTokenInput!): PaypalExpressTokenOutput @resolver(class: "\\Magento\\PaypalGraphQl\\Model\\Resolver\\PaypalExpressToken") @doc(description:"Initiates an Express Checkout transaction and receives a token. Use this mutation for Express Checkout and Payments Standard payment methods.")
1111
createPayflowProToken(input: PayflowProTokenInput!): CreatePayflowProTokenOutput @resolver(class: "\\Magento\\PaypalGraphQl\\Model\\Resolver\\PayflowProToken") @doc(description: "Initiates a transaction and receives a token. Use this mutation for Payflow Pro and Payments Pro payment methods")
1212
handlePayflowProResponse(input: PayflowProResponseInput!): PayflowProResponseOutput @resolver(class: "\\Magento\\PaypalGraphQl\\Model\\Resolver\\PayflowProResponse") @doc(description: "Handles payment response and saves payment in Quote. Use this mutations for Payflow Pro and Payments Pro payment methods.")
1313
}
@@ -20,7 +20,12 @@ input PaypalExpressTokenInput @doc(description: "Defines the attributes required
2020
express_button: Boolean @doc(description: "Indicates whether the buyer selected the quick checkout button. The default value is false")
2121
}
2222

23-
type PaypalExpressToken @doc(description: "Contains the token returned by PayPal and a set of URLs that allow the buyer to authorize payment and adjust checkout details. Applies to Express Checkout and Payments Standard payment methods.") {
23+
type PaypalExpressToken @doc(description: "Deprecated: use type `PaypalExpressTokenOutput` instead") {
24+
token: String @deprecated(reason: "Use field `token` of type `PaypalExpressTokenOutput` instead") @doc(description:"The token returned by PayPal")
25+
paypal_urls: PaypalExpressUrlList @deprecated(reason: "Use field `paypal_urls` of type `PaypalExpressTokenOutput` instead") @doc(description:"A set of URLs that allow the buyer to authorize payment and adjust checkout details")
26+
}
27+
28+
type PaypalExpressTokenOutput @doc(description: "Contains the token returned by PayPal and a set of URLs that allow the buyer to authorize payment and adjust checkout details. Applies to Express Checkout and Payments Standard payment methods.") {
2429
token: String @doc(description:"The token returned by PayPal")
2530
paypal_urls: PaypalExpressUrlList @doc(description:"A set of URLs that allow the buyer to authorize payment and adjust checkout details")
2631
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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\QuoteGraphQl\Model\Cart;
9+
10+
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
11+
use Magento\GraphQl\Model\Query\ContextInterface;
12+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
13+
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
14+
use Magento\Quote\Model\Quote\Address;
15+
16+
/**
17+
* Get shipping address
18+
*/
19+
class GetShippingAddress
20+
{
21+
/**
22+
* @var QuoteAddressFactory
23+
*/
24+
private $quoteAddressFactory;
25+
26+
/**
27+
* @param QuoteAddressFactory $quoteAddressFactory
28+
*/
29+
public function __construct(QuoteAddressFactory $quoteAddressFactory)
30+
{
31+
$this->quoteAddressFactory = $quoteAddressFactory;
32+
}
33+
34+
/**
35+
* Get Shipping Address based on the input.
36+
*
37+
* @param ContextInterface $context
38+
* @param array $shippingAddressInput
39+
* @return Address
40+
* @throws GraphQlAuthorizationException
41+
* @throws GraphQlInputException
42+
* @throws GraphQlNoSuchEntityException
43+
*/
44+
public function execute(ContextInterface $context, array $shippingAddressInput): Address
45+
{
46+
$customerAddressId = $shippingAddressInput['customer_address_id'] ?? null;
47+
$addressInput = $shippingAddressInput['address'] ?? null;
48+
49+
if ($addressInput) {
50+
$addressInput['customer_notes'] = $shippingAddressInput['customer_notes'] ?? '';
51+
}
52+
53+
if (null === $customerAddressId && null === $addressInput) {
54+
throw new GraphQlInputException(
55+
__('The shipping address must contain either "customer_address_id" or "address".')
56+
);
57+
}
58+
59+
if ($customerAddressId && $addressInput) {
60+
throw new GraphQlInputException(
61+
__('The shipping address cannot contain "customer_address_id" and "address" at the same time.')
62+
);
63+
}
64+
65+
if (null === $customerAddressId) {
66+
$shippingAddress = $this->quoteAddressFactory->createBasedOnInputData($addressInput);
67+
} else {
68+
if (false === $context->getExtensionAttributes()->getIsCustomer()) {
69+
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
70+
}
71+
72+
$shippingAddress = $this->quoteAddressFactory->createBasedOnCustomerAddress(
73+
(int)$customerAddressId,
74+
$context->getUserId()
75+
);
76+
}
77+
78+
return $shippingAddress;
79+
}
80+
}

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

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,25 @@
1717
*/
1818
class SetShippingAddressesOnCart implements SetShippingAddressesOnCartInterface
1919
{
20-
/**
21-
* @var QuoteAddressFactory
22-
*/
23-
private $quoteAddressFactory;
24-
2520
/**
2621
* @var AssignShippingAddressToCart
2722
*/
2823
private $assignShippingAddressToCart;
24+
/**
25+
* @var GetShippingAddress
26+
*/
27+
private $getShippingAddress;
2928

3029
/**
31-
* @param QuoteAddressFactory $quoteAddressFactory
3230
* @param AssignShippingAddressToCart $assignShippingAddressToCart
31+
* @param GetShippingAddress $getShippingAddress
3332
*/
3433
public function __construct(
35-
QuoteAddressFactory $quoteAddressFactory,
36-
AssignShippingAddressToCart $assignShippingAddressToCart
34+
AssignShippingAddressToCart $assignShippingAddressToCart,
35+
GetShippingAddress $getShippingAddress
3736
) {
38-
$this->quoteAddressFactory = $quoteAddressFactory;
3937
$this->assignShippingAddressToCart = $assignShippingAddressToCart;
38+
$this->getShippingAddress = $getShippingAddress;
4039
}
4140

4241
/**
@@ -50,37 +49,8 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s
5049
);
5150
}
5251
$shippingAddressInput = current($shippingAddressesInput);
53-
$customerAddressId = $shippingAddressInput['customer_address_id'] ?? null;
54-
$addressInput = $shippingAddressInput['address'] ?? null;
55-
56-
if ($addressInput) {
57-
$addressInput['customer_notes'] = $shippingAddressInput['customer_notes'] ?? '';
58-
}
59-
60-
if (null === $customerAddressId && null === $addressInput) {
61-
throw new GraphQlInputException(
62-
__('The shipping address must contain either "customer_address_id" or "address".')
63-
);
64-
}
6552

66-
if ($customerAddressId && $addressInput) {
67-
throw new GraphQlInputException(
68-
__('The shipping address cannot contain "customer_address_id" and "address" at the same time.')
69-
);
70-
}
71-
72-
if (null === $customerAddressId) {
73-
$shippingAddress = $this->quoteAddressFactory->createBasedOnInputData($addressInput);
74-
} else {
75-
if (false === $context->getExtensionAttributes()->getIsCustomer()) {
76-
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
77-
}
78-
79-
$shippingAddress = $this->quoteAddressFactory->createBasedOnCustomerAddress(
80-
(int)$customerAddressId,
81-
$context->getUserId()
82-
);
83-
}
53+
$shippingAddress = $this->getShippingAddress->execute($context, $shippingAddressInput);
8454

8555
$this->assignShippingAddressToCart->execute($cart, $shippingAddress);
8656
}

app/code/Magento/QuoteGraphQl/Model/Resolver/PlaceOrder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
8989

9090
return [
9191
'order' => [
92+
'order_number' => $order->getIncrementId(),
93+
// @deprecated The order_id field is deprecated, use order_number instead
9294
'order_id' => $order->getIncrementId(),
9395
],
9496
];

app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentAndPlaceOrder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
9999

100100
return [
101101
'order' => [
102+
'order_number' => $order->getIncrementId(),
103+
// @deprecated The order_id field is deprecated, use order_number instead
102104
'order_id' => $order->getIncrementId(),
103105
],
104106
];

0 commit comments

Comments
 (0)