Skip to content

Commit 2b17d9b

Browse files
Merge pull request #9591 from magento-lynx/graphql-api-enhancements
[LYNX] Delivery PR
2 parents a52ff98 + 329cc0c commit 2b17d9b

File tree

18 files changed

+491
-630
lines changed

18 files changed

+491
-630
lines changed

app/code/Magento/OrderCancellation/Model/Email/ConfirmationKeySender.php

+11-19
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,28 @@ public function __construct(
5151
* Send email to guest user with confirmation key.
5252
*
5353
* @param Order $order
54-
* @param string $confirmationKey
54+
* @param array $confirmationDetails
5555
* @return void
5656
* @throws LocalizedException
5757
*/
5858
public function execute(
5959
Order $order,
60-
string $confirmationKey,
60+
array $confirmationDetails
6161
):void {
6262
try {
6363
$storeId = (int)$order->getStoreId();
64-
$guestOrderUrl = $this->url->getUrl(
65-
self::ORDER_VIEW_PATH,
66-
[
67-
'_query' => [
68-
'confirmation_key' => $confirmationKey,
69-
'order_id' => $order->getIncrementId()
70-
]
71-
]
72-
);
73-
$templateParams = [
74-
'customer_name' => $order->getCustomerName(),
75-
'order_id' => $order->getIncrementId(),
76-
'guest_order_url' => $guestOrderUrl,
77-
'escaper' => $this->escaper,
78-
];
79-
8064
$this->transportBuilder
8165
->setTemplateIdentifier(self::TEMPLATE_ID)
8266
->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => $storeId])
83-
->setTemplateVars($templateParams)
67+
->setTemplateVars([
68+
'customer_name' => $order->getCustomerName(),
69+
'order_id' => $order->getIncrementId(),
70+
'guest_order_url' => $this->url->getUrl(
71+
self::ORDER_VIEW_PATH,
72+
['_query' => $confirmationDetails]
73+
),
74+
'escaper' => $this->escaper,
75+
])
8476
->setFromByScope($this->orderIdentity->getEmailIdentity(), $storeId)
8577
->addTo($order->getCustomerEmail(), $order->getCustomerName())
8678
->getTransport()

app/code/Magento/OrderCancellation/Model/ResourceModel/SalesOrderConfirmCancel.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function get(int $orderId): ?array
4040
$connection = $this->resourceConnection->getConnection();
4141
return $connection->fetchRow(
4242
$connection->select()->from(
43-
self::TABLE_NAME
43+
$this->resourceConnection->getTableName(self::TABLE_NAME)
4444
)->where(
4545
'order_id = ?',
4646
$orderId
@@ -60,7 +60,7 @@ public function insert(int $orderId, string $confirmationKey, string $reason): v
6060
{
6161
$connection = $this->resourceConnection->getConnection();
6262
$connection->insertOnDuplicate(
63-
self::TABLE_NAME,
63+
$this->resourceConnection->getTableName(self::TABLE_NAME),
6464
[
6565
'order_id' => $orderId,
6666
'confirmation_key' => $confirmationKey,

app/code/Magento/OrderCancellationGraphQl/Model/CancelOrderGuest.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\OrderCancellationGraphQl\Model;
99

1010
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\GraphQl\Query\Uid;
1112
use Magento\OrderCancellation\Model\Email\ConfirmationKeySender;
1213
use Magento\OrderCancellation\Model\GetConfirmationKey;
1314
use Magento\Sales\Api\OrderRepositoryInterface;
@@ -23,12 +24,14 @@ class CancelOrderGuest
2324
* @param OrderRepositoryInterface $orderRepository
2425
* @param ConfirmationKeySender $confirmationKeySender
2526
* @param GetConfirmationKey $confirmationKey
27+
* @param Uid $idEncoder
2628
*/
2729
public function __construct(
2830
private readonly OrderFormatter $orderFormatter,
2931
private readonly OrderRepositoryInterface $orderRepository,
3032
private readonly ConfirmationKeySender $confirmationKeySender,
3133
private readonly GetConfirmationKey $confirmationKey,
34+
private readonly Uid $idEncoder
3235
) {
3336
}
3437

@@ -65,7 +68,13 @@ public function execute(Order $order, array $input): array
6568
*/
6669
private function sendConfirmationKeyEmail(Order $order, string $reason): void
6770
{
68-
$this->confirmationKeySender->execute($order, $this->confirmationKey->execute($order, $reason));
71+
$this->confirmationKeySender->execute(
72+
$order,
73+
[
74+
'order_id' => $this->idEncoder->encode((string)$order->getEntityId()),
75+
'confirmation_key' => $this->confirmationKey->execute($order, $reason)
76+
]
77+
);
6978

7079
// add comment in order about confirmation key send
7180
$order->addCommentToStatusHistory(

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\GraphQl\Config\Element\Field;
1212
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
1313
use Magento\Framework\GraphQl\Query\ResolverInterface;
14+
use Magento\Framework\GraphQl\Query\Uid;
1415
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1516
use Magento\OrderCancellation\Model\CancelOrder as CancelOrderAction;
1617
use Magento\OrderCancellationGraphQl\Model\Validator\ValidateOrder;
@@ -31,13 +32,15 @@ class CancelOrder implements ResolverInterface
3132
* @param OrderRepositoryInterface $orderRepository
3233
* @param CancelOrderAction $cancelOrderAction
3334
* @param ValidateOrder $validateOrder
35+
* @param Uid $idEncoder
3436
*/
3537
public function __construct(
3638
private readonly ValidateRequest $validateRequest,
3739
private readonly OrderFormatter $orderFormatter,
3840
private readonly OrderRepositoryInterface $orderRepository,
3941
private readonly CancelOrderAction $cancelOrderAction,
40-
private readonly ValidateOrder $validateOrder
42+
private readonly ValidateOrder $validateOrder,
43+
private readonly Uid $idEncoder
4144
) {
4245
}
4346

@@ -54,7 +57,7 @@ public function resolve(
5457
$this->validateRequest->execute($context, $args['input'] ?? []);
5558

5659
try {
57-
$order = $this->orderRepository->get($args['input']['order_id']);
60+
$order = $this->orderRepository->get($this->idEncoder->decode($args['input']['order_id']));
5861

5962
if ((int)$order->getCustomerId() !== $context->getUserId()) {
6063
throw new GraphQlAuthorizationException(__('Current user is not authorized to cancel this order'));

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\Exception\LocalizedException;
1111
use Magento\Framework\GraphQl\Config\Element\Field;
1212
use Magento\Framework\GraphQl\Query\ResolverInterface;
13+
use Magento\Framework\GraphQl\Query\Uid;
1314
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1415
use Magento\OrderCancellationGraphQl\Model\ConfirmCancelOrder as ConfirmCancelOrderGuest;
1516
use Magento\OrderCancellationGraphQl\Model\Validator\ValidateOrder;
@@ -28,12 +29,14 @@ class ConfirmCancelOrder implements ResolverInterface
2829
* @param OrderRepositoryInterface $orderRepository
2930
* @param ConfirmCancelOrderGuest $confirmCancelOrder
3031
* @param ValidateOrder $validateOrder
32+
* @param Uid $idEncoder
3133
*/
3234
public function __construct(
3335
private readonly ValidateConfirmRequest $validateRequest,
3436
private readonly OrderRepositoryInterface $orderRepository,
3537
private readonly ConfirmCancelOrderGuest $confirmCancelOrder,
36-
private readonly ValidateOrder $validateOrder
38+
private readonly ValidateOrder $validateOrder,
39+
private readonly Uid $idEncoder
3740
) {
3841
}
3942

@@ -50,7 +53,7 @@ public function resolve(
5053
$this->validateRequest->execute($args['input'] ?? []);
5154

5255
try {
53-
$order = $this->orderRepository->get($args['input']['order_id']);
56+
$order = $this->orderRepository->get((int)$this->idEncoder->decode($args['input']['order_id']));
5457

5558
if (!$order->getCustomerIsGuest()) {
5659
return [

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function execute(mixed $input): void
3030
);
3131
}
3232

33-
if (!$input['order_id'] || (int)$input['order_id'] === 0) {
33+
if (empty($input['order_id'])) {
3434
throw new GraphQlInputException(
3535
__(
3636
'Required parameter "%field" is missing or incorrect.',

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function execute(
3838
);
3939
}
4040

41-
if (!$input['order_id'] || (int)$input['order_id'] === 0) {
41+
if (empty($input['order_id'])) {
4242
throw new GraphQlInputException(
4343
__(
4444
'Required parameter "%field" is missing or incorrect.',

app/code/Magento/OrderCancellationGraphQl/etc/graphql/di.xml

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0"?>
22
<!--
33
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
4+
* Copyright 2025 Adobe
5+
* All Rights Reserved.
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
@@ -14,8 +14,6 @@
1414
</argument>
1515
</arguments>
1616
</type>
17-
<preference for="Magento\SalesGraphQl\Api\OrderAvailableActionProviderInterface"
18-
type="Magento\OrderCancellationGraphQl\Model\GetOrderCancellationAvailableActions" />
1917
<type name="Magento\SalesGraphQl\Model\GetOrderAvailableActions">
2018
<arguments>
2119
<argument name="actions" xsi:type="array">

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ type Mutation {
1717
}
1818

1919
input CancelOrderInput @doc(description: "Defines the order to cancel.") {
20-
order_id: ID! @doc(description: "Order ID.")
20+
order_id: ID! @doc(description: "The unique ID of an `Order` type.")
2121
reason: String! @doc(description: "Cancellation reason.")
2222
}
2323

2424
input ConfirmCancelOrderInput {
25-
order_id: ID! @doc(description: "Order ID.")
25+
order_id: ID! @doc(description: "The unique ID of an `Order` type.")
2626
confirmation_key: String! @doc(description: "Confirmation Key to cancel the order.")
2727
}
2828

@@ -51,6 +51,6 @@ enum CancelOrderErrorCode {
5151
INVALID_ORDER_STATUS
5252
}
5353

54-
enum OrderActionType @doc(description: "The list of available order actions.") {
54+
enum OrderActionType {
5555
CANCEL
5656
}

app/code/Magento/OrderCancellationUi/view/frontend/web/js/cancel-order-modal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ mutation cancelOrder($order_id: ID!, $reason: String!) {
4949
data: JSON.stringify({
5050
query: mutation,
5151
variables: {
52-
'order_id': config.order_id,
52+
'order_id': btoa(config.order_id),
5353
'reason': reason
5454
}
5555
}),

app/code/Magento/SalesGraphQl/Model/GetReorderAvailableActions.php

+15-6
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,30 @@
77

88
namespace Magento\SalesGraphQl\Model;
99

10+
use Magento\Sales\Helper\Reorder;
11+
use Magento\Sales\Model\Order;
1012
use Magento\SalesGraphQl\Api\OrderAvailableActionProviderInterface;
1113

1214
class GetReorderAvailableActions implements OrderAvailableActionProviderInterface
1315
{
16+
/**
17+
* GetReorderAvailableActions constructor
18+
*
19+
* @param Reorder $reorderHelper
20+
*/
21+
public function __construct(
22+
private readonly Reorder $reorderHelper
23+
) {
24+
}
25+
1426
/**
1527
* Get reorder available action
1628
*
17-
* @param \Magento\Sales\Model\Order $order
29+
* @param Order $order
1830
* @return array|string[]
1931
*/
20-
public function execute(\Magento\Sales\Model\Order $order): array
32+
public function execute(Order $order): array
2133
{
22-
if ($order->canReorder()) {
23-
return ['REORDER'];
24-
}
25-
return [];
34+
return $this->reorderHelper->canReorder($order->getId()) ? ['REORDER'] : [];
2635
}
2736
}

app/code/Magento/SalesGraphQl/etc/graphql/di.xml

-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252
</argument>
5353
</arguments>
5454
</type>
55-
<preference for="Magento\SalesGraphQl\Api\OrderAvailableActionProviderInterface"
56-
type="Magento\SalesGraphQl\Model\GetReorderAvailableActions" />
5755
<type name="Magento\SalesGraphQl\Model\GetOrderAvailableActions">
5856
<arguments>
5957
<argument name="actions" xsi:type="array">

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -318,19 +318,19 @@ enum OrderActionType @doc(description: "The list of available order actions.") {
318318
}
319319

320320
type StoreConfig {
321-
display_product_prices_in_catalog: Boolean! @doc(description: "Configuration data from tax/display/type")
322-
display_shipping_prices: Boolean! @doc(description: "Configuration data from tax/display/shipping")
323-
orders_invoices_credit_memos_display_price: Boolean! @doc(description: "Configuration data from tax/sales_display/price")
324-
orders_invoices_credit_memos_display_subtotal: Boolean! @doc(description: "Configuration data from tax/sales_display/subtotal")
325-
orders_invoices_credit_memos_display_shipping_amount: Boolean! @doc(description: "Configuration data from tax/sales_display/shipping")
321+
display_product_prices_in_catalog: Int! @doc(description: "Configuration data from tax/display/type")
322+
display_shipping_prices: Int! @doc(description: "Configuration data from tax/display/shipping")
323+
orders_invoices_credit_memos_display_price: Int! @doc(description: "Configuration data from tax/sales_display/price")
324+
orders_invoices_credit_memos_display_subtotal: Int! @doc(description: "Configuration data from tax/sales_display/subtotal")
325+
orders_invoices_credit_memos_display_shipping_amount: Int! @doc(description: "Configuration data from tax/sales_display/shipping")
326326
orders_invoices_credit_memos_display_grandtotal: Boolean! @doc(description: "Configuration data from tax/sales_display/grandtotal")
327327
orders_invoices_credit_memos_display_full_summary: Boolean! @doc(description: "Configuration data from tax/sales_display/full_summary")
328328
orders_invoices_credit_memos_display_zero_tax: Boolean! @doc(description: "Configuration data from tax/sales_display/zero_tax")
329329
fixed_product_taxes_enable: Boolean! @doc(description: "Configuration data from tax/weee/enable")
330-
fixed_product_taxes_display_prices_in_product_lists: Int @doc(description: "Configuration data from tax/weee/display_list")
331-
fixed_product_taxes_display_prices_on_product_view_page: Int @doc(description: "Configuration data from tax/weee/display")
332-
fixed_product_taxes_display_prices_in_sales_modules: Int @doc(description: "Configuration data from tax/weee/display_sales")
333-
fixed_product_taxes_display_prices_in_emails: Int @doc(description: "Configuration data from tax/weee/display_email")
330+
fixed_product_taxes_display_prices_in_product_lists: Int! @doc(description: "Configuration data from tax/weee/display_list")
331+
fixed_product_taxes_display_prices_on_product_view_page: Int! @doc(description: "Configuration data from tax/weee/display")
332+
fixed_product_taxes_display_prices_in_sales_modules: Int! @doc(description: "Configuration data from tax/weee/display_sales")
333+
fixed_product_taxes_display_prices_in_emails: Int! @doc(description: "Configuration data from tax/weee/display_email")
334334
fixed_product_taxes_apply_tax_to_fpt: Boolean! @doc(description: "Configuration data from tax/weee/apply_vat")
335335
fixed_product_taxes_include_fpt_in_subtotal: Boolean! @doc(description: "Configuration data from tax/weee/include_in_subtotal")
336336
}

0 commit comments

Comments
 (0)