Skip to content

Commit 9c2cced

Browse files
Merge remote-tracking branch 'origin' into MC-42288
2 parents cf93f71 + 32fda1c commit 9c2cced

24 files changed

+1496
-2415
lines changed

app/code/Magento/CustomerGraphQl/Model/Context/AddUserInfoToContext.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
namespace Magento\CustomerGraphQl\Model\Context;
99

1010
use Magento\Authorization\Model\UserContextInterface;
11+
use Magento\Customer\Model\ResourceModel\CustomerRepository;
12+
use Magento\Customer\Model\Session;
1113
use Magento\GraphQl\Model\Query\ContextParametersInterface;
1214
use Magento\GraphQl\Model\Query\ContextParametersProcessorInterface;
1315

@@ -21,13 +23,29 @@ class AddUserInfoToContext implements ContextParametersProcessorInterface
2123
*/
2224
private $userContext;
2325

26+
/**
27+
* @var Session
28+
*/
29+
private $session;
30+
31+
/**
32+
* @var CustomerRepository
33+
*/
34+
private $customerRepository;
35+
2436
/**
2537
* @param UserContextInterface $userContext
38+
* @param Session $session
39+
* @param CustomerRepository $customerRepository
2640
*/
2741
public function __construct(
28-
UserContextInterface $userContext
42+
UserContextInterface $userContext,
43+
Session $session,
44+
CustomerRepository $customerRepository
2945
) {
3046
$this->userContext = $userContext;
47+
$this->session = $session;
48+
$this->customerRepository = $customerRepository;
3149
}
3250

3351
/**
@@ -47,7 +65,13 @@ public function execute(ContextParametersInterface $contextParameters): ContextP
4765
}
4866
$contextParameters->setUserType($currentUserType);
4967

50-
$contextParameters->addExtensionAttribute('is_customer', $this->isCustomer($currentUserId, $currentUserType));
68+
$isCustomer = $this->isCustomer($currentUserId, $currentUserType);
69+
$contextParameters->addExtensionAttribute('is_customer', $isCustomer);
70+
if ($isCustomer) {
71+
$customer = $this->customerRepository->getById($currentUserId);
72+
$this->session->setCustomerData($customer);
73+
$this->session->setCustomerGroupId($customer->getGroupId());
74+
}
5175
return $contextParameters;
5276
}
5377

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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\Plugin;
9+
10+
use Magento\Authorization\Model\UserContextInterface;
11+
use Magento\Customer\Model\ResourceModel\CustomerRepository;
12+
use Magento\Customer\Model\Session as CustomerSession;
13+
use Magento\Framework\App\ResponseInterface;
14+
use Magento\Framework\Exception\LocalizedException;
15+
use Magento\Framework\Exception\NoSuchEntityException;
16+
use Magento\GraphQl\Controller\GraphQl as GraphQlController;
17+
18+
/**
19+
* Clear the user data out of the session object before returning the GraphQL response
20+
*/
21+
class ClearCustomerSessionAfterRequest
22+
{
23+
/**
24+
* @var UserContextInterface
25+
*/
26+
private $userContext;
27+
28+
/**
29+
* @var CustomerSession
30+
*/
31+
private $customerSession;
32+
33+
/**
34+
* @var CustomerRepository
35+
*/
36+
private $customerRepository;
37+
38+
/**
39+
* @param UserContextInterface $userContext
40+
* @param CustomerSession $customerSession
41+
* @param CustomerRepository $customerRepository
42+
*/
43+
public function __construct(
44+
UserContextInterface $userContext,
45+
CustomerSession $customerSession,
46+
CustomerRepository $customerRepository
47+
) {
48+
$this->userContext = $userContext;
49+
$this->customerSession = $customerSession;
50+
$this->customerRepository = $customerRepository;
51+
}
52+
53+
/**
54+
* Clear the customer data from the session after business logic has completed
55+
*
56+
* @param GraphQlController $controller
57+
* @param ResponseInterface $response
58+
* @return ResponseInterface
59+
*
60+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
61+
*/
62+
public function afterDispatch(GraphQlController $controller, ResponseInterface $response): ResponseInterface
63+
{
64+
$this->customerSession->setCustomerId(null);
65+
$this->customerSession->setCustomerGroupId(null);
66+
return $response;
67+
}
68+
}

app/code/Magento/CustomerGraphQl/etc/graphql/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@
4040
</argument>
4141
</arguments>
4242
</type>
43+
<type name="Magento\GraphQl\Controller\GraphQl">
44+
<plugin name="ClearCustomerSessionAfterRequest" type="Magento\CustomerGraphQl\Plugin\ClearCustomerSessionAfterRequest" sortOrder="1" disabled="false" />
45+
</type>
4346
</config>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# PaymentGraphQl
2+
3+
**PaymentGraphQl** provides type information for the GraphQl module
4+
to generate payment fields information endpoints.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "magento/module-payment-graph-ql",
3+
"description": "N/A",
4+
"type": "magento2-module",
5+
"require": {
6+
"php": "~7.3.0||~7.4.0",
7+
"magento/framework": "*"
8+
},
9+
"suggest": {
10+
"magento/module-store-graph-ql": "*"
11+
},
12+
"license": [
13+
"OSL-3.0",
14+
"AFL-3.0"
15+
],
16+
"autoload": {
17+
"files": [
18+
"registration.php"
19+
],
20+
"psr-4": {
21+
"Magento\\PaymentGraphQl\\": ""
22+
}
23+
}
24+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider">
10+
<arguments>
11+
<argument name="extendedConfigData" xsi:type="array">
12+
<item name="zero_subtotal_enabled" xsi:type="string">payment/free/active</item>
13+
<item name="zero_subtotal_title" xsi:type="string">payment/free/title</item>
14+
<item name="zero_subtotal_new_order_status" xsi:type="string">payment/free/order_status</item>
15+
<item name="zero_subtotal_payment_action" xsi:type="string">payment/free/payment_action</item>
16+
<item name="zero_subtotal_enable_for_specific_countries" xsi:type="string">payment/free/allowspecific</item>
17+
<item name="zero_subtotal_payment_from_specific_countries" xsi:type="string">payment/free/specificcountry</item>
18+
<item name="zero_subtotal_sort_order" xsi:type="string">payment/free/sort_order</item>
19+
<item name="check_money_order_enabled" xsi:type="string">payment/checkmo/active</item>
20+
<item name="check_money_order_title" xsi:type="string">payment/checkmo/title</item>
21+
<item name="check_money_order_new_order_status" xsi:type="string">payment/checkmo/order_status</item>
22+
<item name="check_money_order_enable_for_specific_countries" xsi:type="string">payment/checkmo/allowspecific</item>
23+
<item name="check_money_order_payment_from_specific_countries" xsi:type="string">payment/checkmo/specificcountry</item>
24+
<item name="check_money_order_make_check_payable_to" xsi:type="string">payment/checkmo/payable_to</item>
25+
<item name="check_money_order_send_check_to" xsi:type="string">payment/checkmo/mailing_address</item>
26+
<item name="check_money_order_min_order_total" xsi:type="string">payment/checkmo/min_order_total</item>
27+
<item name="check_money_order_max_order_total" xsi:type="string">payment/checkmo/max_order_total</item>
28+
<item name="check_money_order_sort_order" xsi:type="string">payment/checkmo/sort_order</item>
29+
</argument>
30+
</arguments>
31+
</type>
32+
</config>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9+
<module name="Magento_PaymentGraphQl"/>
10+
</config>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright © Magento, Inc. All rights reserved.
2+
# See COPYING.txt for license details.
3+
type StoreConfig {
4+
zero_subtotal_enabled: Boolean @doc(description: "Indicates whether the Zero Subtotal payment method is enabled")
5+
zero_subtotal_title: String @doc(description: "The title of the Zero Subtotal payment method displayed on the storefront")
6+
zero_subtotal_new_order_status: String @doc(description: "Status of new orders placed using the Zero Subtotal payment method")
7+
zero_subtotal_payment_action: String @doc(description: "When the new order status is 'Processing', this can be set to 'authorize_capture' to automatically invoice all items that have a zero balance")
8+
zero_subtotal_enable_for_specific_countries: Boolean @doc(description: "Indicates whether only specific countries can use this payment method")
9+
zero_subtotal_payment_from_specific_countries: String @doc(description: "Comma-separated list of specific countries allowed to use the Zero Subtotal payment method")
10+
zero_subtotal_sort_order: Int @doc(description: "A number indicating the position of the Zero Subtotal payment method in the list of available payment methods during checkout")
11+
check_money_order_enabled: Boolean @doc(description: "Indicates whether the Check/Money Order payment method is enabled")
12+
check_money_order_title: String @doc(description: "The title of the Check/Money Order payment method displayed on the storefront")
13+
check_money_order_new_order_status: String @doc(description: "Status of new orders placed using the Check/Money Order payment method")
14+
check_money_order_enable_for_specific_countries: Boolean @doc(description: "Indicates whether only specific countries can use this payment method")
15+
check_money_order_payment_from_specific_countries: String @doc(description: "Comma-separated list of specific countries allowed to use the Check/Money Order payment method")
16+
check_money_order_make_check_payable_to: String @doc(description: "The name of the party to whom the check must be payable")
17+
check_money_order_send_check_to: String @doc(description: "The full street address or PO Box where the checks are mailed")
18+
check_money_order_min_order_total: String @doc(description: "Minimum order amount required to qualify for the Check/Money Order payment method")
19+
check_money_order_max_order_total: String @doc(description: "Maximum order amount required to qualify for the Check/Money Order payment method")
20+
check_money_order_sort_order: Int @doc(description: "A number indicating the position of the Check/Money Order payment method in the list of available payment methods during checkout")
21+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
use Magento\Framework\Component\ComponentRegistrar;
9+
10+
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_PaymentGraphQl', __DIR__);

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@
240240
"magento/module-offline-shipping": "*",
241241
"magento/module-page-cache": "*",
242242
"magento/module-payment": "*",
243+
"magento/module-payment-graph-ql": "*",
243244
"magento/module-paypal": "*",
244245
"magento/module-paypal-captcha": "*",
245246
"magento/module-paypal-graph-ql": "*",

0 commit comments

Comments
 (0)