-
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.
GraphQL-55: [Mutations] My Account > Change account information
- Loading branch information
Valeriy Nayda
committed
Oct 9, 2018
1 parent
20e3393
commit 661988b
Showing
14 changed files
with
146 additions
and
270 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
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
67 changes: 0 additions & 67 deletions
67
app/code/Magento/QuoteGraphQl/Model/Authorization/IsCartMutationAllowedForCurrentUser.php
This file was deleted.
Oops, something went wrong.
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
89 changes: 89 additions & 0 deletions
89
app/code/Magento/QuoteGraphQl/Model/Cart/GetCartForUser.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,89 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\QuoteGraphQl\Model\Cart; | ||
|
||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlAuthenticationException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; | ||
use Magento\Quote\Api\CartRepositoryInterface; | ||
use Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface; | ||
use Magento\Quote\Model\Quote; | ||
|
||
/** | ||
* Get cart | ||
*/ | ||
class GetCartForUser | ||
{ | ||
/** | ||
* @var MaskedQuoteIdToQuoteIdInterface | ||
*/ | ||
private $maskedQuoteIdToQuoteId; | ||
|
||
/** | ||
* @var CartRepositoryInterface | ||
*/ | ||
private $cartRepository; | ||
|
||
/** | ||
* @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId | ||
* @param CartRepositoryInterface $cartRepository | ||
*/ | ||
public function __construct( | ||
MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId, | ||
CartRepositoryInterface $cartRepository | ||
) { | ||
$this->maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId; | ||
$this->cartRepository = $cartRepository; | ||
} | ||
|
||
/** | ||
* Get cart for user | ||
* | ||
* @param string $cartHash | ||
* @param int|null $userId | ||
* @return Quote | ||
* @throws GraphQlAuthenticationException | ||
* @throws GraphQlNoSuchEntityException | ||
*/ | ||
public function execute(string $cartHash, ?int $userId): Quote | ||
{ | ||
try { | ||
$cartId = $this->maskedQuoteIdToQuoteId->execute($cartHash); | ||
} catch (NoSuchEntityException $exception) { | ||
throw new GraphQlNoSuchEntityException( | ||
__('Could not find a cart with ID "%masked_cart_id"', ['masked_cart_id' => $cartHash]) | ||
); | ||
} | ||
|
||
try { | ||
/** @var Quote $cart */ | ||
$cart = $this->cartRepository->get($cartId); | ||
} catch (NoSuchEntityException $e) { | ||
throw new GraphQlNoSuchEntityException( | ||
__('Could not find a cart with ID "%masked_cart_id"', ['masked_cart_id' => $cartHash]) | ||
); | ||
} | ||
|
||
$customerId = (int)$cart->getCustomerId(); | ||
|
||
/* Guest cart, allow operations */ | ||
if (!$customerId) { | ||
return $cart; | ||
} | ||
|
||
if ($customerId !== $userId) { | ||
throw new GraphQlAuthenticationException( | ||
__( | ||
'The current user cannot perform operations on cart "%masked_cart_id"', | ||
['masked_cart_id' => $cartHash] | ||
) | ||
); | ||
} | ||
return $cart; | ||
} | ||
} |
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.