Skip to content

Commit 98f53e7

Browse files
committed
MC-22215: Add customerCart Query and cart_id changes to schema and related resolvers
- Fixed static failures on dependency test
1 parent 3874423 commit 98f53e7

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/CustomerCart.php

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
use Magento\Framework\Exception\NoSuchEntityException;
1111
use Magento\Framework\GraphQl\Config\Element\Field;
12-
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1312
use Magento\Framework\GraphQl\Query\ResolverInterface;
1413
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1514
use Magento\QuoteGraphQl\Model\Cart\CreateEmptyCartForCustomer;
16-
use Magento\Authorization\Model\UserContextInterface;
15+
use Magento\GraphQl\Model\Query\ContextInterface;
16+
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
1717
use Magento\Quote\Api\CartManagementInterface;
1818

1919
/**
@@ -49,35 +49,20 @@ public function __construct(
4949
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
5050
{
5151
$currentUserId = $context->getUserId();
52-
$currentUserType = $context->getUserType();
53-
$isCustomerLoggedIn = $this->isCustomer($currentUserId, $currentUserType);
5452

55-
if ($isCustomerLoggedIn) {
56-
try {
57-
$cart = $this->cartManagement->getCartForCustomer($currentUserId);
58-
} catch (NoSuchEntityException $e) {
59-
$this->createEmptyCartForCustomer->execute($currentUserId, null);
60-
$cart = $this->cartManagement->getCartForCustomer($currentUserId);
61-
}
62-
63-
} else {
64-
throw new GraphQlInputException(__('The request is allowed for logged in customer'));
53+
/** @var ContextInterface $context */
54+
if (false === $context->getExtensionAttributes()->getIsCustomer()) {
55+
throw new GraphQlAuthorizationException(__('The request is allowed for logged in customer'));
56+
}
57+
try {
58+
$cart = $this->cartManagement->getCartForCustomer($currentUserId);
59+
} catch (NoSuchEntityException $e) {
60+
$this->createEmptyCartForCustomer->execute($currentUserId, null);
61+
$cart = $this->cartManagement->getCartForCustomer($currentUserId);
6562
}
6663

6764
return [
6865
'model' => $cart
6966
];
7067
}
71-
72-
/**
73-
* Check if current user is logged in
74-
*
75-
* @param int|null $customerId
76-
* @param int|null $customerType
77-
* @return bool
78-
*/
79-
private function isCustomer(?int $customerId, ?int $customerType): bool
80-
{
81-
return !empty($customerId) && !empty($customerType) && $customerType !== UserContextInterface::USER_TYPE_GUEST;
82-
}
8368
}

0 commit comments

Comments
 (0)