-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔃 [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
- Loading branch information
Showing
22 changed files
with
839 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
app/code/Magento/QuoteGraphQl/Model/Cart/Address/SaveQuoteAddressToCustomerAddressBook.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\QuoteGraphQl\Model\Cart\Address; | ||
|
||
use Magento\Customer\Api\AddressRepositoryInterface; | ||
use Magento\Customer\Api\Data\AddressInterface; | ||
use Magento\Customer\Api\Data\AddressInterfaceFactory; | ||
use Magento\Customer\Api\Data\RegionInterface; | ||
use Magento\Customer\Api\Data\RegionInterfaceFactory; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Quote\Model\Quote\Address as QuoteAddress; | ||
|
||
/** | ||
* Save Address to Customer Address Book. | ||
*/ | ||
class SaveQuoteAddressToCustomerAddressBook | ||
{ | ||
/** | ||
* @var AddressInterfaceFactory | ||
*/ | ||
private $addressFactory; | ||
|
||
/** | ||
* @var AddressRepositoryInterface | ||
*/ | ||
private $addressRepository; | ||
|
||
/** | ||
* @var RegionInterfaceFactory | ||
*/ | ||
private $regionFactory; | ||
|
||
/** | ||
* @param AddressInterfaceFactory $addressFactory | ||
* @param AddressRepositoryInterface $addressRepository | ||
* @param RegionInterfaceFactory $regionFactory | ||
*/ | ||
public function __construct( | ||
AddressInterfaceFactory $addressFactory, | ||
AddressRepositoryInterface $addressRepository, | ||
RegionInterfaceFactory $regionFactory | ||
) { | ||
$this->addressFactory = $addressFactory; | ||
$this->addressRepository = $addressRepository; | ||
$this->regionFactory = $regionFactory; | ||
} | ||
|
||
/** | ||
* Save Address to Customer Address Book. | ||
* | ||
* @param QuoteAddress $quoteAddress | ||
* @param int $customerId | ||
* | ||
* @return void | ||
* @throws GraphQlInputException | ||
*/ | ||
public function execute(QuoteAddress $quoteAddress, int $customerId): void | ||
{ | ||
try { | ||
/** @var AddressInterface $customerAddress */ | ||
$customerAddress = $this->addressFactory->create(); | ||
$customerAddress->setFirstname($quoteAddress->getFirstname()) | ||
->setLastname($quoteAddress->getLastname()) | ||
->setMiddlename($quoteAddress->getMiddlename()) | ||
->setPrefix($quoteAddress->getPrefix()) | ||
->setSuffix($quoteAddress->getSuffix()) | ||
->setVatId($quoteAddress->getVatId()) | ||
->setCountryId($quoteAddress->getCountryId()) | ||
->setCompany($quoteAddress->getCompany()) | ||
->setRegionId($quoteAddress->getRegionId()) | ||
->setFax($quoteAddress->getFax()) | ||
->setCity($quoteAddress->getCity()) | ||
->setPostcode($quoteAddress->getPostcode()) | ||
->setStreet($quoteAddress->getStreet()) | ||
->setTelephone($quoteAddress->getTelephone()) | ||
->setCustomerId($customerId); | ||
|
||
/** @var RegionInterface $region */ | ||
$region = $this->regionFactory->create(); | ||
$region->setRegionCode($quoteAddress->getRegionCode()) | ||
->setRegion($quoteAddress->getRegion()) | ||
->setRegionId($quoteAddress->getRegionId()); | ||
$customerAddress->setRegion($region); | ||
|
||
$this->addressRepository->save($customerAddress); | ||
} catch (LocalizedException $e) { | ||
throw new GraphQlInputException(__($e->getMessage()), $e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.