-
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.
Merge pull request #3767 from magento-engcom/graphql-develop-prs
[EngCom] Public Pull Requests - GraphQL
- Loading branch information
Showing
8 changed files
with
467 additions
and
585 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
app/code/Magento/QuoteGraphQl/Model/Cart/GetCustomerAddress.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,65 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\QuoteGraphQl\Model\Cart; | ||
|
||
use Magento\Customer\Api\AddressRepositoryInterface; | ||
use Magento\Customer\Api\Data\AddressInterface; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; | ||
|
||
/** | ||
* Get customer address. Throws exception if customer is not owner of address | ||
*/ | ||
class GetCustomerAddress | ||
{ | ||
/** | ||
* @var AddressRepositoryInterface | ||
*/ | ||
private $addressRepository; | ||
|
||
/** | ||
* @param AddressRepositoryInterface $addressRepository | ||
*/ | ||
public function __construct(AddressRepositoryInterface $addressRepository) | ||
{ | ||
$this->addressRepository = $addressRepository; | ||
} | ||
|
||
/** | ||
* Get customer address. Throws exception if customer is not owner of address | ||
* | ||
* @param int $addressId | ||
* @param int $customerId | ||
* @return AddressInterface | ||
* @throws GraphQlAuthorizationException | ||
* @throws GraphQlNoSuchEntityException | ||
* @throws LocalizedException | ||
*/ | ||
public function execute(int $addressId, int $customerId): AddressInterface | ||
{ | ||
try { | ||
$customerAddress = $this->addressRepository->getById($addressId); | ||
} catch (NoSuchEntityException $e) { | ||
throw new GraphQlNoSuchEntityException( | ||
__('Could not find a address with ID "%address_id"', ['address_id' => $addressId]) | ||
); | ||
} | ||
|
||
if ((int)$customerAddress->getCustomerId() !== $customerId) { | ||
throw new GraphQlAuthorizationException( | ||
__( | ||
'The current user cannot use address with ID "%address_id"', | ||
['address_id' => $addressId] | ||
) | ||
); | ||
} | ||
return $customerAddress; | ||
} | ||
} |
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.