Skip to content

Commit 718c64f

Browse files
authored
LYNX-598: Modify guest order token generation to use lastname instead of postcode
1 parent c06951d commit 718c64f

File tree

12 files changed

+50
-63
lines changed

12 files changed

+50
-63
lines changed

app/code/Magento/OrderCancellationGraphQl/Model/Resolver/RequestGuestOrderCancel.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public function resolve(
5656
?array $args = null
5757
) {
5858
$this->validateRequest->validateInput($args['input'] ?? []);
59-
list($number, $email, $postcode) = $this->getNumberEmailPostcode($args['input']['token']);
59+
list($number, $email, $lastname) = $this->getNumberEmailLastname($args['input']['token']);
6060

6161
$order = $this->getOrder($number);
62-
$this->validateRequest->validateOrderDetails($order, $postcode, $email);
62+
$this->validateRequest->validateOrderDetails($order, $lastname, $email);
6363

6464
$errors = $this->validateOrder->execute($order);
6565
if ($errors) {
@@ -93,13 +93,13 @@ private function getOrder(string $number): OrderInterface
9393
}
9494

9595
/**
96-
* Retrieve number, email and postcode from token
96+
* Retrieve number, email and lastname from token
9797
*
9898
* @param string $token
9999
* @return array
100100
* @throws GraphQlNoSuchEntityException
101101
*/
102-
private function getNumberEmailPostcode(string $token): array
102+
private function getNumberEmailLastname(string $token): array
103103
{
104104
$data = $this->token->decrypt($token);
105105
if (count($data) !== 3) {

app/code/Magento/OrderCancellationGraphQl/Model/Validator/ValidateGuestRequest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ public function validateInput(mixed $input): void
5959
* Ensure the order matches the provided criteria
6060
*
6161
* @param OrderInterface $order
62-
* @param string $postcode
62+
* @param string $lastname
6363
* @param string $email
6464
* @return void
6565
* @throws GraphQlAuthorizationException
6666
* @throws GraphQlNoSuchEntityException
6767
*/
68-
public function validateOrderDetails(OrderInterface $order, string $postcode, string $email): void
68+
public function validateOrderDetails(OrderInterface $order, string $lastname, string $email): void
6969
{
7070
$billingAddress = $order->getBillingAddress();
7171

72-
if ($billingAddress->getPostcode() !== $postcode || $billingAddress->getEmail() !== $email) {
72+
if ($billingAddress->getLastname() !== $lastname || $billingAddress->getEmail() !== $email) {
7373
$this->cannotLocateOrder();
7474
}
7575

app/code/Magento/SalesGraphQl/Model/Resolver/GuestOrder.php

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Magento\Store\Model\StoreManagerInterface;
2121

2222
/**
23-
* Retrieve guest order based
23+
* Retrieve guest order details
2424
*/
2525
class GuestOrder implements ResolverInterface
2626
{
@@ -50,9 +50,9 @@ public function resolve(
5050
?array $value = null,
5151
?array $args = null
5252
) {
53-
list($number, $email, $postcode) = $this->getNumberEmailPostcode($args['input'] ?? []);
53+
list($number, $email, $lastname) = $this->getNumberEmailLastname($args['input'] ?? []);
5454
$order = $this->getOrder($number);
55-
$this->validateOrder($order, $postcode, $email);
55+
$this->validateOrder($order, $lastname, $email);
5656
return $this->orderFormatter->format($order);
5757
}
5858

@@ -82,35 +82,32 @@ private function getOrder(string $number): OrderInterface
8282
* Ensure the order matches the provided criteria
8383
*
8484
* @param OrderInterface $order
85-
* @param string $postcode
85+
* @param string $lastname
8686
* @param string $email
8787
* @return void
8888
* @throws GraphQlAuthorizationException
8989
* @throws GraphQlNoSuchEntityException
9090
*/
91-
private function validateOrder(OrderInterface $order, string $postcode, string $email): void
91+
private function validateOrder(OrderInterface $order, string $lastname, string $email): void
9292
{
93-
if ($order->getBillingAddress()->getPostcode() !== $postcode) {
94-
$this->cannotLocateOrder();
95-
}
96-
97-
if ($order->getBillingAddress()->getEmail() !== $email) {
93+
$billingAddress = $order->getBillingAddress();
94+
if ($billingAddress->getLastname() !== $lastname || $billingAddress->getEmail() !== $email) {
9895
$this->cannotLocateOrder();
9996
}
10097

10198
if ($order->getCustomerId()) {
102-
$this->customerHasToLogin();
99+
throw new GraphQlAuthorizationException(__('Please login to view the order.'));
103100
}
104101
}
105102

106103
/**
107-
* Retrieve number, email and postcode from input
104+
* Retrieve order number, email, and lastname from input
108105
*
109106
* @param array $input
110107
* @return array
111108
* @throws GraphQlNoSuchEntityException
112109
*/
113-
private function getNumberEmailPostcode(array $input): array
110+
private function getNumberEmailLastname(array $input): array
114111
{
115112
if (isset($input['token'])) {
116113
$data = $this->token->decrypt($input['token']);
@@ -119,10 +116,10 @@ private function getNumberEmailPostcode(array $input): array
119116
}
120117
return $data;
121118
}
122-
if (!isset($input['number']) || !isset($input['email']) || !isset($input['postcode'])) {
119+
if (!isset($input['number']) || !isset($input['email']) || !isset($input['lastname'])) {
123120
$this->cannotLocateOrder();
124121
}
125-
return [$input['number'], $input['email'], $input['postcode']];
122+
return [$input['number'], $input['email'], $input['lastname']];
126123
}
127124

128125
/**
@@ -135,15 +132,4 @@ private function cannotLocateOrder(): void
135132
{
136133
throw new GraphQlNoSuchEntityException(__('We couldn\'t locate an order with the information provided.'));
137134
}
138-
139-
/**
140-
* Throw exception when the guest checkout is not enabled or order is customer order
141-
*
142-
* @return void
143-
* @throws GraphQlAuthorizationException
144-
*/
145-
private function customerHasToLogin(): void
146-
{
147-
throw new GraphQlAuthorizationException(__('Please login to view the order.'));
148-
}
149135
}

app/code/Magento/SalesGraphQl/Model/Resolver/Token.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\GraphQl\Query\ResolverInterface;
1313
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1414
use Magento\Sales\Api\Data\OrderInterface;
15+
use Magento\SalesGraphQl\Model\Order\Token as OrderToken;
1516

1617
/**
1718
* Retrieve order token
@@ -22,7 +23,7 @@ class Token implements ResolverInterface
2223
* @param Token $token
2324
*/
2425
public function __construct(
25-
private readonly \Magento\SalesGraphQl\Model\Order\Token $token
26+
private readonly OrderToken $token
2627
) {
2728
}
2829

@@ -44,7 +45,7 @@ public function resolve(
4445
return $this->token->encrypt(
4546
$order->getIncrementId(),
4647
$order->getBillingAddress()->getEmail(),
47-
$order->getBillingAddress()->getPostcode()
48+
$order->getBillingAddress()->getLastname()
4849
);
4950
}
5051
}

app/code/Magento/SalesGraphQl/etc/schema.graphqls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
type Query {
55
customerOrders: CustomerOrders @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\Orders") @deprecated(reason: "Use the `customer` query instead.") @cache(cacheable: false)
6-
guestOrder(input: OrderInformationInput!): CustomerOrder! @doc(description:"Retrieve guest order details based on number, email and postcode.") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\GuestOrder") @cache(cacheable: false)
6+
guestOrder(input: OrderInformationInput!): CustomerOrder! @doc(description:"Retrieve guest order details based on number, email and billing last name.") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\GuestOrder") @cache(cacheable: false)
77
guestOrderByToken(input: OrderTokenInput!): CustomerOrder! @doc(description:"Retrieve guest order details based on token.") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\GuestOrder") @cache(cacheable: false)
88
}
99

@@ -310,7 +310,7 @@ input OrderTokenInput @doc(description: "Input to retrieve an order based on tok
310310
input OrderInformationInput @doc(description: "Input to retrieve an order based on details.") {
311311
number: String! @doc(description: "Order number.")
312312
email: String! @doc(description: "Order billing address email.")
313-
postcode: String! @doc(description: "Order billing address postcode.")
313+
lastname: String! @doc(description: "Order billing address lastname.")
314314
}
315315

316316
enum OrderActionType @doc(description: "The list of available order actions.") {

dev/tests/api-functional/testsuite/Magento/GraphQl/OrderCancellation/CancelGuestOrderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,14 +467,14 @@ private function getOrderToken(OrderInterface $order): string
467467
return Bootstrap::getObjectManager()->create(Token::class)->encrypt(
468468
$order->getIncrementId(),
469469
$order->getBillingAddress()->getEmail(),
470-
$order->getBillingAddress()->getPostcode()
470+
$order->getBillingAddress()->getLastname()
471471
);
472472
}
473473

474474
/**
475475
* @return array[]
476476
*/
477-
public function orderStatusProvider(): array
477+
public static function orderStatusProvider(): array
478478
{
479479
return [
480480
'On Hold status' => [

dev/tests/api-functional/testsuite/Magento/GraphQl/Sales/GuestOrderByTokenTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function testCustomerOrder(): void
137137
'%token' => Bootstrap::getObjectManager()->get(Token::class)->encrypt(
138138
$order->getIncrementId(),
139139
$order->getBillingAddress()->getEmail(),
140-
$order->getBillingAddress()->getPostcode()
140+
$order->getBillingAddress()->getLastname()
141141
)
142142
]
143143
);

dev/tests/api-functional/testsuite/Magento/GraphQl/Sales/GuestOrderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class GuestOrderTest extends GraphQlAbstract
3333
guestOrder(input: {
3434
number: "%number",
3535
email: "%email",
36-
postcode: "%postcode"
36+
lastname: "%lastname"
3737
}) {
3838
number
3939
email
@@ -65,7 +65,7 @@ public function testGuestOrder(): void
6565
[
6666
'%number' => $order->getIncrementId(),
6767
'%email' => $order->getBillingAddress()->getEmail(),
68-
'%postcode' => $order->getBillingAddress()->getPostcode(),
68+
'%lastname' => $order->getBillingAddress()->getLastname(),
6969
]
7070
);
7171
$response = $this->graphQlQuery($query);
@@ -106,7 +106,7 @@ public function testCustomerOrder(): void
106106
[
107107
'%number' => $order->getIncrementId(),
108108
'%email' => $order->getBillingAddress()->getEmail(),
109-
'%postcode' => $order->getBillingAddress()->getPostcode(),
109+
'%lastname' => $order->getBillingAddress()->getLastname(),
110110
]
111111
);
112112
$this->graphQlQuery($query);
@@ -133,7 +133,7 @@ public function testGuestOrderIncorrectEmail(): void
133133
[
134134
'%number' => $order->getIncrementId(),
135135
'%email' => 'incorrect' . $order->getBillingAddress()->getEmail(),
136-
'%postcode' => $order->getBillingAddress()->getPostcode(),
136+
'%lastname' => $order->getBillingAddress()->getLastname(),
137137
]
138138
);
139139
$this->graphQlQuery($query);

dev/tests/api-functional/testsuite/Magento/GraphQl/Sales/OrderItemPricesTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function testOrderItemPricesWithSpecialPriceAndTax(): void
112112
$this->getQuery(
113113
$order->getIncrementId(),
114114
$order->getBillingAddress()->getEmail(),
115-
$order->getBillingAddress()->getPostcode()
115+
$order->getBillingAddress()->getLastname()
116116
)
117117
);
118118

@@ -170,7 +170,7 @@ public function testOrderItemPricesWithoutSpecialPriceAndTax(): void
170170
$this->getQuery(
171171
$order->getIncrementId(),
172172
$order->getBillingAddress()->getEmail(),
173-
$order->getBillingAddress()->getPostcode()
173+
$order->getBillingAddress()->getLastname()
174174
)
175175
);
176176

@@ -192,17 +192,17 @@ public function testOrderItemPricesWithoutSpecialPriceAndTax(): void
192192
*
193193
* @param string $number
194194
* @param string $email
195-
* @param string $postcode
195+
* @param string $lastname
196196
* @return string
197197
*/
198-
private function getQuery(string $number, string $email, string $postcode): string
198+
private function getQuery(string $number, string $email, string $lastname): string
199199
{
200200
return <<<QUERY
201201
{
202202
guestOrder(input: {
203203
number: "{$number}",
204204
email: "{$email}",
205-
postcode: "{$postcode}"
205+
lastname: "{$lastname}"
206206
}) {
207207
items {
208208
prices {

dev/tests/api-functional/testsuite/Magento/GraphQl/Sales/OrderStatusChangeDateTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private function assertOrderStatusChangeDate(OrderInterface $order, string $stat
8383
$updatedGuestOrder = $this->graphQlMutation($this->getQuery(
8484
$order->getIncrementId(),
8585
$order->getBillingAddress()->getEmail(),
86-
$order->getBillingAddress()->getPostcode()
86+
$order->getBillingAddress()->getLastname()
8787
));
8888
self::assertEquals(
8989
self::STATUS_MAPPER[$status],
@@ -100,17 +100,17 @@ private function assertOrderStatusChangeDate(OrderInterface $order, string $stat
100100
*
101101
* @param string $number
102102
* @param string $email
103-
* @param string $postcode
103+
* @param string $lastname
104104
* @return string
105105
*/
106-
private function getQuery(string $number, string $email, string $postcode): string
106+
private function getQuery(string $number, string $email, string $lastname): string
107107
{
108108
return <<<QUERY
109109
{
110110
guestOrder(input: {
111111
number: "{$number}",
112112
email: "{$email}",
113-
postcode: "{$postcode}"
113+
lastname: "{$lastname}"
114114
}) {
115115
created_at
116116
status

0 commit comments

Comments
 (0)