Skip to content

Commit 14d6388

Browse files
🔃 [Magento Community Engineering] Community Contributions - GraphQL
Accepted Community Pull Requests: - magento/graphql-ce#873: graphQl-509: `save_in_address_book` has no impact on Address Book (by @kisroman) - magento/graphql-ce#991: graphQl-987: [Test coverage] Cover exceptions in Magento\QuoteGraphQl� (by @kisroman) - magento/graphql-ce#995: magento/graphql-ce#985: Remove unnecessary exceptions (by @atwixfirster) - magento/graphql-ce#997: magento/graphql-ce#975: [Test coverage] Cover CartAddressTypeResolver (by @atwixfirster) - magento/graphql-ce#990: Extend test coverage for CustomerDownloadableGraphQl (by @TomashKhamlai) - magento/graphql-ce#983: #981 Extend test coverage for BraintreeGraphQl (by @TomashKhamlai) - magento/graphql-ce#973: GraphQl-972: added support of the Global scope in the config fixture (by @VitaliyBoyko) Fixed GitHub Issues: - #975: [Question] Have traits been considered for the Interceptor classes? (reported by @fooman) has been fixed in magento/graphql-ce#997 by @atwixfirster in 2.3-develop branch Related commits: 1. 493d744 - #989: make build artifacts accessable (reported by @Flyingmana) has been fixed in magento/graphql-ce#990 by @TomashKhamlai in 2.3-develop branch Related commits: 1. bccd287 - #972: Pub/Static directory is empty (reported by @mrugeshrocks) has been fixed in magento/graphql-ce#973 by @VitaliyBoyko in 2.3-develop branch Related commits: 1. 3489da5 2. 63bd232 3. b64a485
2 parents c60cf10 + 44cc3c5 commit 14d6388

22 files changed

+839
-60
lines changed

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@
99

1010
use Magento\Customer\Model\AuthenticationInterface;
1111
use Magento\Framework\Exception\InvalidEmailOrPasswordException;
12-
use Magento\Framework\Exception\LocalizedException;
13-
use Magento\Framework\Exception\NoSuchEntityException;
1412
use Magento\Framework\Exception\State\UserLockedException;
1513
use Magento\Framework\GraphQl\Exception\GraphQlAuthenticationException;
16-
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
17-
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1814

1915
/**
2016
* Check customer password
@@ -41,8 +37,6 @@ public function __construct(
4137
* @param string $password
4238
* @param int $customerId
4339
* @throws GraphQlAuthenticationException
44-
* @throws GraphQlInputException
45-
* @throws GraphQlNoSuchEntityException
4640
*/
4741
public function execute(string $password, int $customerId)
4842
{
@@ -52,10 +46,6 @@ public function execute(string $password, int $customerId)
5246
throw new GraphQlAuthenticationException(__($e->getMessage()), $e);
5347
} catch (UserLockedException $e) {
5448
throw new GraphQlAuthenticationException(__($e->getMessage()), $e);
55-
} catch (NoSuchEntityException $e) {
56-
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
57-
} catch (LocalizedException $e) {
58-
throw new GraphQlInputException(__($e->getMessage()), $e);
5949
}
6050
}
6151
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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\Address;
9+
10+
use Magento\Customer\Api\AddressRepositoryInterface;
11+
use Magento\Customer\Api\Data\AddressInterface;
12+
use Magento\Customer\Api\Data\AddressInterfaceFactory;
13+
use Magento\Customer\Api\Data\RegionInterface;
14+
use Magento\Customer\Api\Data\RegionInterfaceFactory;
15+
use Magento\Framework\Exception\LocalizedException;
16+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
17+
use Magento\Quote\Model\Quote\Address as QuoteAddress;
18+
19+
/**
20+
* Save Address to Customer Address Book.
21+
*/
22+
class SaveQuoteAddressToCustomerAddressBook
23+
{
24+
/**
25+
* @var AddressInterfaceFactory
26+
*/
27+
private $addressFactory;
28+
29+
/**
30+
* @var AddressRepositoryInterface
31+
*/
32+
private $addressRepository;
33+
34+
/**
35+
* @var RegionInterfaceFactory
36+
*/
37+
private $regionFactory;
38+
39+
/**
40+
* @param AddressInterfaceFactory $addressFactory
41+
* @param AddressRepositoryInterface $addressRepository
42+
* @param RegionInterfaceFactory $regionFactory
43+
*/
44+
public function __construct(
45+
AddressInterfaceFactory $addressFactory,
46+
AddressRepositoryInterface $addressRepository,
47+
RegionInterfaceFactory $regionFactory
48+
) {
49+
$this->addressFactory = $addressFactory;
50+
$this->addressRepository = $addressRepository;
51+
$this->regionFactory = $regionFactory;
52+
}
53+
54+
/**
55+
* Save Address to Customer Address Book.
56+
*
57+
* @param QuoteAddress $quoteAddress
58+
* @param int $customerId
59+
*
60+
* @return void
61+
* @throws GraphQlInputException
62+
*/
63+
public function execute(QuoteAddress $quoteAddress, int $customerId): void
64+
{
65+
try {
66+
/** @var AddressInterface $customerAddress */
67+
$customerAddress = $this->addressFactory->create();
68+
$customerAddress->setFirstname($quoteAddress->getFirstname())
69+
->setLastname($quoteAddress->getLastname())
70+
->setMiddlename($quoteAddress->getMiddlename())
71+
->setPrefix($quoteAddress->getPrefix())
72+
->setSuffix($quoteAddress->getSuffix())
73+
->setVatId($quoteAddress->getVatId())
74+
->setCountryId($quoteAddress->getCountryId())
75+
->setCompany($quoteAddress->getCompany())
76+
->setRegionId($quoteAddress->getRegionId())
77+
->setFax($quoteAddress->getFax())
78+
->setCity($quoteAddress->getCity())
79+
->setPostcode($quoteAddress->getPostcode())
80+
->setStreet($quoteAddress->getStreet())
81+
->setTelephone($quoteAddress->getTelephone())
82+
->setCustomerId($customerId);
83+
84+
/** @var RegionInterface $region */
85+
$region = $this->regionFactory->create();
86+
$region->setRegionCode($quoteAddress->getRegionCode())
87+
->setRegion($quoteAddress->getRegion())
88+
->setRegionId($quoteAddress->getRegionId());
89+
$customerAddress->setRegion($region);
90+
91+
$this->addressRepository->save($customerAddress);
92+
} catch (LocalizedException $e) {
93+
throw new GraphQlInputException(__($e->getMessage()), $e);
94+
}
95+
}
96+
}

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

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1313
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1414
use Magento\Quote\Model\Quote\Address;
15+
use Magento\QuoteGraphQl\Model\Cart\Address\SaveQuoteAddressToCustomerAddressBook;
1516

1617
/**
1718
* Get shipping address
@@ -23,12 +24,21 @@ class GetShippingAddress
2324
*/
2425
private $quoteAddressFactory;
2526

27+
/**
28+
* @var SaveQuoteAddressToCustomerAddressBook
29+
*/
30+
private $saveQuoteAddressToCustomerAddressBook;
31+
2632
/**
2733
* @param QuoteAddressFactory $quoteAddressFactory
34+
* @param SaveQuoteAddressToCustomerAddressBook $saveQuoteAddressToCustomerAddressBook
2835
*/
29-
public function __construct(QuoteAddressFactory $quoteAddressFactory)
30-
{
36+
public function __construct(
37+
QuoteAddressFactory $quoteAddressFactory,
38+
SaveQuoteAddressToCustomerAddressBook $saveQuoteAddressToCustomerAddressBook
39+
) {
3140
$this->quoteAddressFactory = $quoteAddressFactory;
41+
$this->saveQuoteAddressToCustomerAddressBook = $saveQuoteAddressToCustomerAddressBook;
3242
}
3343

3444
/**
@@ -62,16 +72,46 @@ public function execute(ContextInterface $context, array $shippingAddressInput):
6272
);
6373
}
6474

75+
$shippingAddress = $this->createShippingAddress($context, $customerAddressId, $addressInput);
76+
77+
return $shippingAddress;
78+
}
79+
80+
/**
81+
* Create shipping address.
82+
*
83+
* @param ContextInterface $context
84+
* @param int|null $customerAddressId
85+
* @param array|null $addressInput
86+
*
87+
* @return \Magento\Quote\Model\Quote\Address
88+
* @throws GraphQlAuthorizationException
89+
*/
90+
private function createShippingAddress(
91+
ContextInterface $context,
92+
?int $customerAddressId,
93+
?array $addressInput
94+
) {
95+
$customerId = $context->getUserId();
96+
6597
if (null === $customerAddressId) {
6698
$shippingAddress = $this->quoteAddressFactory->createBasedOnInputData($addressInput);
99+
100+
// need to save address only for registered user and if save_in_address_book = true
101+
if (0 !== $customerId
102+
&& isset($addressInput['save_in_address_book'])
103+
&& (bool)$addressInput['save_in_address_book'] === true
104+
) {
105+
$this->saveQuoteAddressToCustomerAddressBook->execute($shippingAddress, $customerId);
106+
}
67107
} else {
68108
if (false === $context->getExtensionAttributes()->getIsCustomer()) {
69109
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
70110
}
71111

72112
$shippingAddress = $this->quoteAddressFactory->createBasedOnCustomerAddress(
73113
(int)$customerAddressId,
74-
$context->getUserId()
114+
$customerId
75115
);
76116
}
77117

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\GraphQl\Model\Query\ContextInterface;
1414
use Magento\Quote\Api\Data\CartInterface;
1515
use Magento\Quote\Model\Quote\Address;
16+
use Magento\QuoteGraphQl\Model\Cart\Address\SaveQuoteAddressToCustomerAddressBook;
1617

1718
/**
1819
* Set billing address for a specified shopping cart
@@ -29,16 +30,24 @@ class SetBillingAddressOnCart
2930
*/
3031
private $assignBillingAddressToCart;
3132

33+
/**
34+
* @var SaveQuoteAddressToCustomerAddressBook
35+
*/
36+
private $saveQuoteAddressToCustomerAddressBook;
37+
3238
/**
3339
* @param QuoteAddressFactory $quoteAddressFactory
3440
* @param AssignBillingAddressToCart $assignBillingAddressToCart
41+
* @param SaveQuoteAddressToCustomerAddressBook $saveQuoteAddressToCustomerAddressBook
3542
*/
3643
public function __construct(
3744
QuoteAddressFactory $quoteAddressFactory,
38-
AssignBillingAddressToCart $assignBillingAddressToCart
45+
AssignBillingAddressToCart $assignBillingAddressToCart,
46+
SaveQuoteAddressToCustomerAddressBook $saveQuoteAddressToCustomerAddressBook
3947
) {
4048
$this->quoteAddressFactory = $quoteAddressFactory;
4149
$this->assignBillingAddressToCart = $assignBillingAddressToCart;
50+
$this->saveQuoteAddressToCustomerAddressBook = $saveQuoteAddressToCustomerAddressBook;
4251
}
4352

4453
/**
@@ -101,6 +110,15 @@ private function createBillingAddress(
101110
): Address {
102111
if (null === $customerAddressId) {
103112
$billingAddress = $this->quoteAddressFactory->createBasedOnInputData($addressInput);
113+
114+
$customerId = $context->getUserId();
115+
// need to save address only for registered user and if save_in_address_book = true
116+
if (0 !== $customerId
117+
&& isset($addressInput['save_in_address_book'])
118+
&& (bool)$addressInput['save_in_address_book'] === true
119+
) {
120+
$this->saveQuoteAddressToCustomerAddressBook->execute($billingAddress, $customerId);
121+
}
104122
} else {
105123
if (false === $context->getExtensionAttributes()->getIsCustomer()) {
106124
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
@@ -111,6 +129,7 @@ private function createBillingAddress(
111129
(int)$context->getUserId()
112130
);
113131
}
132+
114133
return $billingAddress;
115134
}
116135
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\QuoteGraphQl\Model\Cart;
99

10-
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
1110
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1211
use Magento\GraphQl\Model\Query\ContextInterface;
1312
use Magento\Quote\Api\Data\CartInterface;
@@ -21,6 +20,7 @@ class SetShippingAddressesOnCart implements SetShippingAddressesOnCartInterface
2120
* @var AssignShippingAddressToCart
2221
*/
2322
private $assignShippingAddressToCart;
23+
2424
/**
2525
* @var GetShippingAddress
2626
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ input CartAddressInput {
109109
postcode: String
110110
country_code: String!
111111
telephone: String!
112-
save_in_address_book: Boolean!
112+
save_in_address_book: Boolean
113113
}
114114

115115
input SetShippingMethodsOnCartInput {

dev/tests/api-functional/framework/Magento/TestFramework/Annotation/ApiConfigFixture.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Config\Model\Config;
1111
use Magento\Config\Model\ResourceModel\Config as ConfigResource;
1212
use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory;
13+
use Magento\Framework\App\Config\ScopeConfigInterface;
1314
use Magento\TestFramework\Helper\Bootstrap;
1415
use Magento\Store\Model\StoreManagerInterface;
1516
use PHPUnit\Framework\TestCase;
@@ -156,4 +157,31 @@ private function getStoreIdByCode(string $storeCode): int
156157
$store = $storeManager->getStore($storeCode);
157158
return (int)$store->getId();
158159
}
160+
161+
/**
162+
* @inheritDoc
163+
*/
164+
protected function _setConfigValue($configPath, $value, $storeCode = false)
165+
{
166+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
167+
if ($storeCode === false) {
168+
$objectManager->get(
169+
\Magento\TestFramework\App\ApiMutableScopeConfig::class
170+
)->setValue(
171+
$configPath,
172+
$value,
173+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
174+
);
175+
176+
return;
177+
}
178+
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
179+
\Magento\TestFramework\App\ApiMutableScopeConfig::class
180+
)->setValue(
181+
$configPath,
182+
$value,
183+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
184+
$storeCode
185+
);
186+
}
159187
}

dev/tests/api-functional/framework/Magento/TestFramework/App/MutableScopeConfig.php renamed to dev/tests/api-functional/framework/Magento/TestFramework/App/ApiMutableScopeConfig.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/**
1818
* @inheritdoc
1919
*/
20-
class MutableScopeConfig implements MutableScopeConfigInterface
20+
class ApiMutableScopeConfig implements MutableScopeConfigInterface
2121
{
2222
/**
2323
* @var Config
@@ -56,7 +56,6 @@ public function setValue(
5656
/**
5757
* Clean app config cache
5858
*
59-
* @param string|null $type
6059
* @return void
6160
*/
6261
public function clean()
@@ -89,19 +88,13 @@ private function getTestAppConfig()
8988
private function persistConfig($path, $value, $scopeType, $scopeCode): void
9089
{
9190
$pathParts = explode('/', $path);
92-
$store = '';
93-
if ($scopeType === \Magento\Store\Model\ScopeInterface::SCOPE_STORE) {
94-
if ($scopeCode !== null) {
95-
$store = ObjectManager::getInstance()
91+
$store = 0;
92+
if ($scopeType === \Magento\Store\Model\ScopeInterface::SCOPE_STORE
93+
&& $scopeCode !== null) {
94+
$store = ObjectManager::getInstance()
9695
->get(\Magento\Store\Api\StoreRepositoryInterface::class)
9796
->get($scopeCode)
9897
->getId();
99-
} else {
100-
$store = ObjectManager::getInstance()
101-
->get(\Magento\Store\Model\StoreManagerInterface::class)
102-
->getStore()
103-
->getId();
104-
}
10598
}
10699
$configData = [
107100
'section' => $pathParts[0],

dev/tests/api-functional/testsuite/Magento/GraphQl/Braintree/CreateBraintreeClientTokenTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class CreateBraintreeClientTokenTest extends GraphQlAbstract
2020
* @magentoConfigFixture default_store payment/braintree/active 1
2121
* @magentoConfigFixture default_store payment/braintree/environment sandbox
2222
* @magentoConfigFixture default_store payment/braintree/merchant_id def_merchant_id
23+
* @magentoConfigFixture default_store payment/braintree/merchant_account_id def_merchant_id
2324
* @magentoConfigFixture default_store payment/braintree/public_key def_public_key
2425
* @magentoConfigFixture default_store payment/braintree/private_key def_private_key
2526
*/

0 commit comments

Comments
 (0)