Skip to content

Commit 004da75

Browse files
🔃 [Magento Community Engineering] Community Contributions
Accepted Community Pull Requests:
2 parents ed9fecc + 70aa877 commit 004da75

37 files changed

+794
-94
lines changed

app/code/Magento/AuthorizenetGraphQl/Model/AuthorizenetDataProvider.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderInterface;
1111
use Magento\Framework\Stdlib\ArrayManager;
12+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1213

1314
/**
1415
* SetPaymentMethod additional data provider model for Authorizenet payment method
@@ -36,10 +37,32 @@ public function __construct(
3637
*
3738
* @param array $data
3839
* @return array
40+
* @throws GraphQlInputException
3941
*/
4042
public function getData(array $data): array
4143
{
42-
$additionalData = $this->arrayManager->get(static::PATH_ADDITIONAL_DATA, $data) ?? [];
44+
if (!isset($data[self::PATH_ADDITIONAL_DATA])) {
45+
throw new GraphQlInputException(
46+
__('Required parameter "authorizenet_acceptjs" for "payment_method" is missing.')
47+
);
48+
}
49+
if (!isset($data[self::PATH_ADDITIONAL_DATA]['opaque_data_descriptor'])) {
50+
throw new GraphQlInputException(
51+
__('Required parameter "opaque_data_descriptor" for "authorizenet_acceptjs" is missing.')
52+
);
53+
}
54+
if (!isset($data[self::PATH_ADDITIONAL_DATA]['opaque_data_value'])) {
55+
throw new GraphQlInputException(
56+
__('Required parameter "opaque_data_value" for "authorizenet_acceptjs" is missing.')
57+
);
58+
}
59+
if (!isset($data[self::PATH_ADDITIONAL_DATA]['cc_last_4'])) {
60+
throw new GraphQlInputException(
61+
__('Required parameter "cc_last_4" for "authorizenet_acceptjs" is missing.')
62+
);
63+
}
64+
65+
$additionalData = $this->arrayManager->get(static::PATH_ADDITIONAL_DATA, $data);
4366
foreach ($additionalData as $key => $value) {
4467
$additionalData[$this->convertSnakeCaseToCamelCase($key)] = $value;
4568
unset($additionalData[$key]);

app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
use Magento\Catalog\Model\Category;
1111
use Magento\CatalogGraphQl\Model\Resolver\Category\CheckCategoryIsActive;
1212
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\ExtractDataFromCategoryTree;
13-
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1413
use Magento\Framework\GraphQl\Config\Element\Field;
15-
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1614
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1715
use Magento\Framework\GraphQl\Query\ResolverInterface;
16+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
17+
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\CategoryTree as CategoryTreeDataProvider;
1818

1919
/**
2020
* Category tree field resolver, used for GraphQL request processing.
@@ -27,7 +27,7 @@ class CategoryTree implements ResolverInterface
2727
const CATEGORY_INTERFACE = 'CategoryInterface';
2828

2929
/**
30-
* @var \Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\CategoryTree
30+
* @var CategoryTreeDataProvider
3131
*/
3232
private $categoryTree;
3333

@@ -42,12 +42,12 @@ class CategoryTree implements ResolverInterface
4242
private $checkCategoryIsActive;
4343

4444
/**
45-
* @param \Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\CategoryTree $categoryTree
45+
* @param CategoryTreeDataProvider $categoryTree
4646
* @param ExtractDataFromCategoryTree $extractDataFromCategoryTree
4747
* @param CheckCategoryIsActive $checkCategoryIsActive
4848
*/
4949
public function __construct(
50-
\Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\CategoryTree $categoryTree,
50+
CategoryTreeDataProvider $categoryTree,
5151
ExtractDataFromCategoryTree $extractDataFromCategoryTree,
5252
CheckCategoryIsActive $checkCategoryIsActive
5353
) {
@@ -56,22 +56,6 @@ public function __construct(
5656
$this->checkCategoryIsActive = $checkCategoryIsActive;
5757
}
5858

59-
/**
60-
* Get category id
61-
*
62-
* @param array $args
63-
* @return int
64-
* @throws GraphQlInputException
65-
*/
66-
private function getCategoryId(array $args) : int
67-
{
68-
if (!isset($args['id'])) {
69-
throw new GraphQlInputException(__('"id for category should be specified'));
70-
}
71-
72-
return (int)$args['id'];
73-
}
74-
7559
/**
7660
* @inheritdoc
7761
*/
@@ -81,7 +65,9 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
8165
return $value[$field->getName()];
8266
}
8367

84-
$rootCategoryId = $this->getCategoryId($args);
68+
$rootCategoryId = isset($args['id']) ? (int)$args['id'] :
69+
(int)$context->getExtensionAttributes()->getStore()->getRootCategoryId();
70+
8571
if ($rootCategoryId !== Category::TREE_ROOT_ID) {
8672
$this->checkCategoryIsActive->execute($rootCategoryId);
8773
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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\CatalogGraphQl\Model\Resolver;
9+
10+
use Magento\Framework\GraphQl\Config\Element\Field;
11+
use Magento\Framework\GraphQl\Query\ResolverInterface;
12+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
13+
14+
/**
15+
* Root category tree field resolver, used for GraphQL request processing.
16+
*/
17+
class RootCategoryId implements ResolverInterface
18+
{
19+
/**
20+
* @inheritdoc
21+
*/
22+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
23+
{
24+
return (int)$context->getExtensionAttributes()->getStore()->getRootCategoryId();
25+
}
26+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ type StoreConfig @doc(description: "The type contains information about a store
416416
grid_per_page : Int @doc(description: "Products per Page on Grid Default Value.")
417417
list_per_page : Int @doc(description: "Products per Page on List Default Value.")
418418
catalog_default_sort_by : String @doc(description: "Default Sort By.")
419+
root_category_id: Int @doc(description: "The ID of the root category") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\RootCategoryId")
419420
}
420421

421422
type ProductVideo @doc(description: "Contains information about a product video.") implements MediaGalleryInterface {

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1414
use Magento\Framework\GraphQl\Query\ResolverInterface;
1515
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
16+
use Magento\Newsletter\Model\Config;
17+
use Magento\Store\Model\ScopeInterface;
1618

1719
/**
1820
* Create customer account resolver
@@ -30,13 +32,23 @@ class CreateCustomer implements ResolverInterface
3032
private $createCustomerAccount;
3133

3234
/**
35+
* @var Config
36+
*/
37+
private $newsLetterConfig;
38+
39+
/**
40+
* CreateCustomer constructor.
41+
*
3342
* @param ExtractCustomerData $extractCustomerData
3443
* @param CreateCustomerAccount $createCustomerAccount
44+
* @param Config $newsLetterConfig
3545
*/
3646
public function __construct(
3747
ExtractCustomerData $extractCustomerData,
38-
CreateCustomerAccount $createCustomerAccount
48+
CreateCustomerAccount $createCustomerAccount,
49+
Config $newsLetterConfig
3950
) {
51+
$this->newsLetterConfig = $newsLetterConfig;
4052
$this->extractCustomerData = $extractCustomerData;
4153
$this->createCustomerAccount = $createCustomerAccount;
4254
}
@@ -55,6 +67,10 @@ public function resolve(
5567
throw new GraphQlInputException(__('"input" value should be specified'));
5668
}
5769

70+
if (!$this->newsLetterConfig->isActive(ScopeInterface::SCOPE_STORE)) {
71+
$args['input']['is_subscribed'] = false;
72+
}
73+
5874
$customer = $this->createCustomerAccount->execute(
5975
$args['input'],
6076
$context->getExtensionAttributes()->getStore()

app/code/Magento/Newsletter/Test/Unit/Observer/PredispatchNewsletterObserverTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ public function testNewsletterDisabled() : void
121121
->willReturn(false);
122122

123123
$expectedRedirectUrl = 'https://test.com/index';
124-
125124
$this->configMock->expects($this->once())
126125
->method('getValue')
127126
->with('web/default/no_route', ScopeInterface::SCOPE_STORE)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s
5353
$customerAddressId = $shippingAddressInput['customer_address_id'] ?? null;
5454
$addressInput = $shippingAddressInput['address'] ?? null;
5555

56+
if ($addressInput) {
57+
$addressInput['customer_notes'] = $shippingAddressInput['customer_notes'] ?? '';
58+
}
59+
5660
if (null === $customerAddressId && null === $addressInput) {
5761
throw new GraphQlInputException(
5862
__('The shipping address must contain either "customer_address_id" or "address".')
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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\Resolver;
9+
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Query\ResolverInterface;
13+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
14+
use Magento\Quote\Model\Quote;
15+
16+
/**
17+
* @inheritdoc
18+
*/
19+
class CartIsVirtual implements ResolverInterface
20+
{
21+
/**
22+
* @inheritdoc
23+
*/
24+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
25+
{
26+
if (!isset($value['model'])) {
27+
throw new LocalizedException(__('"model" value should be specified'));
28+
}
29+
/** @var Quote $cart */
30+
$cart = $value['model'];
31+
32+
return (bool)$cart->getIsVirtual();
33+
}
34+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
use Magento\Sales\Api\OrderRepositoryInterface;
2121

2222
/**
23-
* @inheritdoc
23+
* Resolver for setting payment method and placing order
24+
*
25+
* @deprecated Should use setPaymentMethodOnCart and placeOrder mutations in single request.
26+
* @see \Magento\QuoteGraphQl\Model\Resolver\SetPaymentMethodOnCart
27+
* @see \Magento\QuoteGraphQl\Model\Resolver\PlaceOrder
2428
*/
2529
class SetPaymentAndPlaceOrder implements ResolverInterface
2630
{

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type Mutation {
1818
setShippingMethodsOnCart(input: SetShippingMethodsOnCartInput): SetShippingMethodsOnCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetShippingMethodsOnCart")
1919
setPaymentMethodOnCart(input: SetPaymentMethodOnCartInput): SetPaymentMethodOnCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\SetPaymentMethodOnCart")
2020
setGuestEmailOnCart(input: SetGuestEmailOnCartInput): SetGuestEmailOnCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\SetGuestEmailOnCart")
21-
setPaymentMethodAndPlaceOrder(input: SetPaymentMethodAndPlaceOrderInput): PlaceOrderOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetPaymentAndPlaceOrder")
21+
setPaymentMethodAndPlaceOrder(input: SetPaymentMethodAndPlaceOrderInput): PlaceOrderOutput @deprecated(reason: "Should use setPaymentMethodOnCart and placeOrder mutations in single request.") @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetPaymentAndPlaceOrder")
2222
placeOrder(input: PlaceOrderInput): PlaceOrderOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\PlaceOrder")
2323
}
2424

@@ -85,6 +85,7 @@ input SetShippingAddressesOnCartInput {
8585
input ShippingAddressInput {
8686
customer_address_id: Int # If provided then will be used address from address book
8787
address: CartAddressInput
88+
customer_notes: String
8889
}
8990

9091
input SetBillingAddressOnCartInput {
@@ -198,6 +199,7 @@ type Cart {
198199
selected_payment_method: SelectedPaymentMethod @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SelectedPaymentMethod")
199200
prices: CartPrices @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartPrices")
200201
total_quantity: Float! @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartTotalQuantity")
202+
is_virtual: Boolean! @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartIsVirtual")
201203
}
202204

203205
interface CartAddressInterface @typeResolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartAddressTypeResolver") {
@@ -210,17 +212,18 @@ interface CartAddressInterface @typeResolver(class: "\\Magento\\QuoteGraphQl\\Mo
210212
postcode: String
211213
country: CartAddressCountry
212214
telephone: String
213-
customer_notes: String
214215
}
215216

216217
type ShippingCartAddress implements CartAddressInterface {
217218
available_shipping_methods: [AvailableShippingMethod] @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\ShippingAddress\\AvailableShippingMethods")
218219
selected_shipping_method: SelectedShippingMethod @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\ShippingAddress\\SelectedShippingMethod")
219220
items_weight: Float
220221
cart_items: [CartItemQuantity]
222+
customer_notes: String
221223
}
222224

223225
type BillingCartAddress implements CartAddressInterface {
226+
customer_notes: String @deprecated (reason: "The field is used only in shipping address")
224227
}
225228

226229
type CartItemQuantity {

0 commit comments

Comments
 (0)