Skip to content

Commit 09ed1b8

Browse files
committed
Inject user context instead of using global implementation
1 parent 0beed4e commit 09ed1b8

File tree

3 files changed

+55
-35
lines changed

3 files changed

+55
-35
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/Cart/CreateEmptyCart.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\QuoteGraphQl\Model\Resolver\Cart;
99

10+
use Magento\Authorization\Model\UserContextInterface;
1011
use Magento\Framework\GraphQl\Config\Element\Field;
1112
use Magento\Framework\GraphQl\Query\Resolver\Value;
1213
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
@@ -42,21 +43,29 @@ class CreateEmptyCart implements ResolverInterface
4243
*/
4344
private $quoteIdMaskFactory;
4445

46+
/**
47+
* @var UserContextInterface
48+
*/
49+
private $userContext;
50+
4551
/**
4652
* @param CartManagementInterface $cartManagement
4753
* @param GuestCartManagementInterface $guestCartManagement
4854
* @param ValueFactory $valueFactory
55+
* @param UserContextInterface $userContext
4956
* @param QuoteIdMaskFactory $quoteIdMaskFactory
5057
*/
5158
public function __construct(
5259
CartManagementInterface $cartManagement,
5360
GuestCartManagementInterface $guestCartManagement,
5461
ValueFactory $valueFactory,
62+
UserContextInterface $userContext,
5563
QuoteIdMaskFactory $quoteIdMaskFactory
5664
) {
5765
$this->cartManagement = $cartManagement;
5866
$this->guestCartManagement = $guestCartManagement;
5967
$this->valueFactory = $valueFactory;
68+
$this->userContext = $userContext;
6069
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
6170
}
6271

@@ -65,7 +74,7 @@ public function __construct(
6574
*/
6675
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) : Value
6776
{
68-
$customerId = $context->getUserId();
77+
$customerId = $this->userContext->getUserId();
6978

7079
if ($customerId) {
7180
$cartId = $this->cartManagement->createEmptyCartForCustomer($customerId);

app/code/Magento/QuoteGraphQl/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"require": {
66
"php": "~7.1.3||~7.2.0",
77
"magento/framework": "*",
8+
"magento/module-authorization": "*",
89
"magento/module-quote": "*"
910
},
1011
"suggest": {

composer.lock

Lines changed: 44 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)