Skip to content

Commit a051525

Browse files
Merge pull request #8586 from magento-lynx/AC-9547
[LYNX] GL delivery PR
2 parents 1819863 + c75d89d commit a051525

File tree

11 files changed

+726
-42
lines changed

11 files changed

+726
-42
lines changed

app/code/Magento/GraphQlResolverCache/Model/Resolver/Result/CacheKey/Calculator/Provider.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class Provider implements ProviderInterface
2626
*/
2727
private array $keyCalculatorInstances = [];
2828

29+
/**
30+
* Dev docs link
31+
*/
32+
private const DEV_DOCS = "https://developer.adobe.com/commerce/webapi/graphql/develop";
33+
2934
/**
3035
* @var ObjectManagerInterface
3136
*/
@@ -58,8 +63,10 @@ private function initForResolver(ResolverInterface $resolver): void
5863
}
5964
$factorProviders = $this->getFactorProvidersForResolver($resolver);
6065
if ($factorProviders === null) {
66+
$devDocs = self::DEV_DOCS;
6167
throw new \InvalidArgumentException(
62-
"GraphQL Resolver Cache key factors are not determined for {$resolverClass} or its parents."
68+
"GraphQL Resolver Cache key factors are not determined for {$resolverClass} or its parents. " .
69+
"See {$devDocs} for information about configuring cache key factors for a resolver."
6370
);
6471
} else {
6572
$runtimePoolKey = $this->generateKeyFromFactorProviders($factorProviders);
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/************************************************************************
3+
*
4+
* Copyright 2023 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* ************************************************************************
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\Quote\Test\Fixture;
20+
21+
use Magento\Framework\DataObject;
22+
use Magento\Framework\Exception\InvalidArgumentException;
23+
use Magento\Quote\Api\CartRepositoryInterface;
24+
use Magento\Quote\Model\QuoteFactory;
25+
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
26+
use Magento\TestFramework\Fixture\DataFixtureInterface;
27+
28+
/**
29+
* Mark cart as inactive
30+
*/
31+
class MakeCartInactive implements DataFixtureInterface
32+
{
33+
private const FIELD_CART_ID = 'cart_id';
34+
35+
/**
36+
* @var CartRepositoryInterface
37+
*/
38+
private CartRepositoryInterface $cartRepository;
39+
40+
/**
41+
* @var QuoteFactory
42+
*/
43+
private QuoteFactory $quoteFactory;
44+
45+
/**
46+
* @var QuoteResource
47+
*/
48+
private QuoteResource $quoteResource;
49+
50+
/**
51+
* @param CartRepositoryInterface $cartRepository
52+
* @param QuoteFactory $quoteFactory
53+
* @param QuoteResource $quoteResource
54+
*/
55+
public function __construct(
56+
CartRepositoryInterface $cartRepository,
57+
QuoteFactory $quoteFactory,
58+
QuoteResource $quoteResource
59+
) {
60+
$this->cartRepository = $cartRepository;
61+
$this->quoteFactory = $quoteFactory;
62+
$this->quoteResource = $quoteResource;
63+
}
64+
65+
/**
66+
* @param array $data
67+
* @return void
68+
* @throws InvalidArgumentException
69+
*/
70+
public function apply(array $data = []): ?DataObject
71+
{
72+
if (empty($data[self::FIELD_CART_ID])) {
73+
throw new InvalidArgumentException(__('"%field" is required', ['field' => self::FIELD_CART_ID]));
74+
}
75+
76+
$quote = $this->quoteFactory->create();
77+
$this->quoteResource->load($quote, $data[self::FIELD_CART_ID]);
78+
$quote->setIsActive(false);
79+
$this->cartRepository->save($quote);
80+
81+
return $quote;
82+
}
83+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/************************************************************************
3+
*
4+
* Copyright 2023 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* ************************************************************************
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\QuoteGraphQl\Model\Cart;
20+
21+
use Magento\Framework\Exception\NoSuchEntityException;
22+
use Magento\Framework\GraphQl\Exception\GraphQlAlreadyExistsException;
23+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
24+
use Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface;
25+
26+
/**
27+
* Validates a pre-defined masked quote id
28+
*/
29+
class ValidateMaskedQuoteId
30+
{
31+
/**
32+
* @var MaskedQuoteIdToQuoteIdInterface
33+
*/
34+
private MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId;
35+
36+
/**
37+
* @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId
38+
*/
39+
public function __construct(
40+
MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId,
41+
) {
42+
$this->maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId;
43+
}
44+
45+
/**
46+
* Validate masked id
47+
*
48+
* @param string $maskedId
49+
* @throws GraphQlAlreadyExistsException
50+
* @throws GraphQlInputException
51+
*/
52+
public function execute(string $maskedId): void
53+
{
54+
if (mb_strlen($maskedId) != 32) {
55+
throw new GraphQlInputException(__('Cart ID length should to be 32 symbols.'));
56+
}
57+
58+
if ($this->isQuoteWithSuchMaskedIdAlreadyExists($maskedId)) {
59+
throw new GraphQlAlreadyExistsException(__('Cart with ID "%1" already exists.', $maskedId));
60+
}
61+
}
62+
63+
/**
64+
* Check is quote with such maskedId already exists
65+
*
66+
* @param string $maskedId
67+
* @return bool
68+
*/
69+
private function isQuoteWithSuchMaskedIdAlreadyExists(string $maskedId): bool
70+
{
71+
try {
72+
$this->maskedQuoteIdToQuoteId->execute($maskedId);
73+
return true;
74+
} catch (NoSuchEntityException $e) {
75+
return false;
76+
}
77+
}
78+
}

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

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77

88
namespace Magento\QuoteGraphQl\Model\Resolver;
99

10-
use Magento\Framework\Exception\NoSuchEntityException;
1110
use Magento\Framework\GraphQl\Config\Element\Field;
12-
use Magento\Framework\GraphQl\Exception\GraphQlAlreadyExistsException;
13-
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1411
use Magento\Framework\GraphQl\Query\ResolverInterface;
1512
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1613
use Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface;
1714
use Magento\QuoteGraphQl\Model\Cart\CreateEmptyCartForCustomer;
1815
use Magento\QuoteGraphQl\Model\Cart\CreateEmptyCartForGuest;
16+
use Magento\QuoteGraphQl\Model\Cart\ValidateMaskedQuoteId;
1917

2018
/**
2119
* @inheritdoc
@@ -37,19 +35,27 @@ class CreateEmptyCart implements ResolverInterface
3735
*/
3836
private $maskedQuoteIdToQuoteId;
3937

38+
/**
39+
* @var ValidateMaskedQuoteId
40+
*/
41+
private ValidateMaskedQuoteId $validateMaskedQuoteId;
42+
4043
/**
4144
* @param CreateEmptyCartForCustomer $createEmptyCartForCustomer
4245
* @param CreateEmptyCartForGuest $createEmptyCartForGuest
4346
* @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId
47+
* @param ValidateMaskedQuoteId $validateMaskedQuoteId
4448
*/
4549
public function __construct(
4650
CreateEmptyCartForCustomer $createEmptyCartForCustomer,
4751
CreateEmptyCartForGuest $createEmptyCartForGuest,
48-
MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId
52+
MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId,
53+
ValidateMaskedQuoteId $validateMaskedQuoteId
4954
) {
5055
$this->createEmptyCartForCustomer = $createEmptyCartForCustomer;
5156
$this->createEmptyCartForGuest = $createEmptyCartForGuest;
5257
$this->maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId;
58+
$this->validateMaskedQuoteId = $validateMaskedQuoteId;
5359
}
5460

5561
/**
@@ -62,46 +68,12 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6268
$predefinedMaskedQuoteId = null;
6369
if (isset($args['input']['cart_id'])) {
6470
$predefinedMaskedQuoteId = $args['input']['cart_id'];
65-
$this->validateMaskedId($predefinedMaskedQuoteId);
71+
$this->validateMaskedQuoteId->execute($predefinedMaskedQuoteId);
6672
}
6773

6874
$maskedQuoteId = (0 === $customerId || null === $customerId)
6975
? $this->createEmptyCartForGuest->execute($predefinedMaskedQuoteId)
7076
: $this->createEmptyCartForCustomer->execute($customerId, $predefinedMaskedQuoteId);
7177
return $maskedQuoteId;
7278
}
73-
74-
/**
75-
* Validate masked id
76-
*
77-
* @param string $maskedId
78-
* @throws GraphQlAlreadyExistsException
79-
* @throws GraphQlInputException
80-
*/
81-
private function validateMaskedId(string $maskedId): void
82-
{
83-
if (mb_strlen($maskedId) != 32) {
84-
throw new GraphQlInputException(__('Cart ID length should to be 32 symbols.'));
85-
}
86-
87-
if ($this->isQuoteWithSuchMaskedIdAlreadyExists($maskedId)) {
88-
throw new GraphQlAlreadyExistsException(__('Cart with ID "%1" already exists.', $maskedId));
89-
}
90-
}
91-
92-
/**
93-
* Check is quote with such maskedId already exists
94-
*
95-
* @param string $maskedId
96-
* @return bool
97-
*/
98-
private function isQuoteWithSuchMaskedIdAlreadyExists(string $maskedId): bool
99-
{
100-
try {
101-
$this->maskedQuoteIdToQuoteId->execute($maskedId);
102-
return true;
103-
} catch (NoSuchEntityException $e) {
104-
return false;
105-
}
106-
}
10779
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/************************************************************************
3+
*
4+
* Copyright 2023 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* ************************************************************************
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\QuoteGraphQl\Model\Resolver;
20+
21+
use Magento\Framework\GraphQl\Config\Element\Field;
22+
use Magento\Framework\GraphQl\Exception\GraphQlAlreadyExistsException;
23+
use Magento\Framework\GraphQl\Query\ResolverInterface;
24+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
25+
use Magento\Quote\Api\CartRepositoryInterface;
26+
use Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface;
27+
use Magento\QuoteGraphQl\Model\Cart\CreateEmptyCartForGuest;
28+
use Magento\QuoteGraphQl\Model\Cart\ValidateMaskedQuoteId;
29+
30+
/**
31+
* Creates a guest cart
32+
*/
33+
class CreateGuestCart implements ResolverInterface
34+
{
35+
/**
36+
* @var CreateEmptyCartForGuest
37+
*/
38+
private CreateEmptyCartForGuest $createEmptyCartForGuest;
39+
40+
/**
41+
* @var MaskedQuoteIdToQuoteIdInterface
42+
*/
43+
private MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId;
44+
45+
/**
46+
* @var CartRepositoryInterface
47+
*/
48+
private CartRepositoryInterface $cartRepository;
49+
50+
/**
51+
* @var ValidateMaskedQuoteId
52+
*/
53+
private ValidateMaskedQuoteId $validateMaskedQuoteId;
54+
55+
/**
56+
* @param CreateEmptyCartForGuest $createEmptyCartForGuest
57+
* @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId
58+
* @param CartRepositoryInterface $cartRepository
59+
* @param ValidateMaskedQuoteId $validateMaskedQuoteId
60+
*/
61+
public function __construct(
62+
CreateEmptyCartForGuest $createEmptyCartForGuest,
63+
MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId,
64+
CartRepositoryInterface $cartRepository,
65+
ValidateMaskedQuoteId $validateMaskedQuoteId
66+
) {
67+
$this->createEmptyCartForGuest = $createEmptyCartForGuest;
68+
$this->maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId;
69+
$this->cartRepository = $cartRepository;
70+
$this->validateMaskedQuoteId = $validateMaskedQuoteId;
71+
}
72+
73+
/**
74+
* @inheritdoc
75+
*/
76+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
77+
{
78+
$customerId = $context->getUserId();
79+
80+
$predefinedMaskedQuoteId = null;
81+
if (isset($args['input']['cart_uid'])) {
82+
$predefinedMaskedQuoteId = $args['input']['cart_uid'];
83+
$this->validateMaskedQuoteId->execute($predefinedMaskedQuoteId);
84+
}
85+
86+
if ($customerId === 0 || $customerId === null) {
87+
$maskedQuoteId = $this->createEmptyCartForGuest->execute($predefinedMaskedQuoteId);
88+
$cartId = $this->maskedQuoteIdToQuoteId->execute($maskedQuoteId);
89+
$cart = $this->cartRepository->get($cartId);
90+
} else {
91+
throw new GraphQlAlreadyExistsException(
92+
__('Use `Query.customerCart` for logged in customer.')
93+
);
94+
}
95+
96+
return [
97+
'cart' => [
98+
'model' => $cart,
99+
],
100+
];
101+
}
102+
}

0 commit comments

Comments
 (0)