Skip to content

Commit 271e0b9

Browse files
committed
graphQl-509: save_in_address_book has no impact on Address Book
1 parent e286889 commit 271e0b9

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

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

Lines changed: 20 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,23 @@ public function execute(ContextInterface $context, array $shippingAddressInput):
6272
);
6373
}
6474

75+
$customerId = $context->getUserId();
76+
6577
if (null === $customerAddressId) {
6678
$shippingAddress = $this->quoteAddressFactory->createBasedOnInputData($addressInput);
79+
80+
// need to save address only for registered user and if save_in_address_book = true
81+
if (0 !== $customerId && !empty($addressInput['save_in_address_book'])) {
82+
$this->saveQuoteAddressToCustomerAddressBook->execute($shippingAddress, $customerId);
83+
}
6784
} else {
6885
if (false === $context->getExtensionAttributes()->getIsCustomer()) {
6986
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
7087
}
7188

7289
$shippingAddress = $this->quoteAddressFactory->createBasedOnCustomerAddress(
7390
(int)$customerAddressId,
74-
$context->getUserId()
91+
$customerId
7592
);
7693
}
7794

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
*/

0 commit comments

Comments
 (0)