Skip to content

Commit 9dac3eb

Browse files
authored
LYNX-180: Add cancellation to Luma interface (#151)
1 parent 999c1e8 commit 9dac3eb

31 files changed

+1696
-23
lines changed
Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
<?php
2-
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
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+
* ************************************************************************
516
*/
617
declare(strict_types=1);
718

819
namespace Magento\OrderCancellation\Model\Config;
920

1021
use Magento\Framework\App\Config\ScopeConfigInterface;
1122
use Magento\Store\Model\ScopeInterface as StoreScopeInterface;
23+
use Magento\Store\Model\Store;
1224

1325
/**
1426
* Config Model for order cancellation module
@@ -17,7 +29,9 @@ class Config
1729
{
1830
private const SETTING_ENABLED = '1';
1931

20-
private const SETTING_ENABLE_PATH = 'sales/cancellation/enabled';
32+
private const SALES_CANCELLATION_ENABLED = 'sales/cancellation/enabled';
33+
34+
private const SALES_CANCELLATION_REASONS = 'sales/cancellation/reasons';
2135

2236
/**
2337
* @var ScopeConfigInterface
@@ -27,23 +41,42 @@ class Config
2741
/**
2842
* @param ScopeConfigInterface $scopeConfig
2943
*/
30-
public function __construct(ScopeConfigInterface $scopeConfig)
31-
{
44+
public function __construct(
45+
ScopeConfigInterface $scopeConfig,
46+
) {
3247
$this->scopeConfig = $scopeConfig;
3348
}
3449

3550
/**
36-
* Is order cancellation enabled for requested store
51+
* Check if order cancellation is enabled for a given store.
3752
*
3853
* @param int $storeId
3954
* @return bool
4055
*/
4156
public function isOrderCancellationEnabledForStore(int $storeId): bool
4257
{
4358
return $this->scopeConfig->getValue(
44-
self::SETTING_ENABLE_PATH,
59+
self::SALES_CANCELLATION_ENABLED,
4560
StoreScopeInterface::SCOPE_STORE,
4661
$storeId
4762
) === self::SETTING_ENABLED;
4863
}
64+
65+
/**
66+
* Returns order cancellation reasons.
67+
*
68+
* @param Store $store
69+
* @return array
70+
*/
71+
public function getCancellationReasons(Store $store): array
72+
{
73+
$reasons = $this->scopeConfig->getValue(
74+
self::SALES_CANCELLATION_REASONS,
75+
StoreScopeInterface::SCOPE_STORE,
76+
$store
77+
);
78+
return array_map(function ($reason) {
79+
return $reason['description'];
80+
}, is_array($reasons) ? $reasons : json_decode($reasons, true));
81+
}
4982
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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\OrderCancellation\Model;
20+
21+
use Magento\Sales\Model\Order;
22+
23+
/**
24+
* Check if customer can cancel an order according to its state.
25+
*/
26+
class CustomerCanCancel
27+
{
28+
/**
29+
* Check if customer can cancel an order according to its state.
30+
*
31+
* Not cancellable states are: 'complete', 'on hold', 'cancel', 'closed'.
32+
*
33+
* @param Order $order
34+
* @return bool
35+
*/
36+
public function execute(Order $order): bool
37+
{
38+
if ($order->getState() === Order::STATE_CLOSED
39+
|| $order->getState() === Order::STATE_CANCELED
40+
|| $order->getState() === Order::STATE_HOLDED
41+
|| $order->getState() === Order::STATE_COMPLETE
42+
) {
43+
return false;
44+
}
45+
return true;
46+
}
47+
}

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

Lines changed: 12 additions & 6 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\OrderCancellation\Model\CancelOrder as CancelOrderAction;
15+
use Magento\OrderCancellation\Model\CustomerCanCancel;
1516
use Magento\OrderCancellation\Model\Config\Config;
1617
use Magento\OrderCancellationGraphQl\Model\ValidateRequest;
1718
use Magento\Sales\Api\OrderRepositoryInterface;
@@ -48,25 +49,33 @@ class CancelOrder implements ResolverInterface
4849
*/
4950
private Config $config;
5051

52+
/**
53+
* @var CustomerCanCancel
54+
*/
55+
private CustomerCanCancel $customerCanCancel;
56+
5157
/**
5258
* @param ValidateRequest $validateRequest
5359
* @param OrderFormatter $orderFormatter
5460
* @param OrderRepositoryInterface $orderRepository
5561
* @param Config $config
5662
* @param CancelOrderAction $cancelOrderAction
63+
* @param CustomerCanCancel $customerCanCancel
5764
*/
5865
public function __construct(
5966
ValidateRequest $validateRequest,
6067
OrderFormatter $orderFormatter,
6168
OrderRepositoryInterface $orderRepository,
6269
Config $config,
63-
CancelOrderAction $cancelOrderAction
70+
CancelOrderAction $cancelOrderAction,
71+
CustomerCanCancel $customerCanCancel
6472
) {
6573
$this->validateRequest = $validateRequest;
6674
$this->orderFormatter = $orderFormatter;
6775
$this->orderRepository = $orderRepository;
6876
$this->config = $config;
6977
$this->cancelOrderAction = $cancelOrderAction;
78+
$this->customerCanCancel = $customerCanCancel;
7079
}
7180

7281
/**
@@ -91,12 +100,9 @@ public function resolve(
91100
];
92101
}
93102

94-
if ($order->getState() === order::STATE_CLOSED
95-
|| $order->getState() === order::STATE_CANCELED
96-
|| $order->getState() === order::STATE_HOLDED
97-
) {
103+
if (!$this->customerCanCancel->execute($order)) {
98104
return [
99-
'error' => __('Order already closed, cancelled or on hold'),
105+
'error' => __('Order already closed, complete, cancelled or on hold'),
100106
'order' => $this->orderFormatter->format($order)
101107
];
102108
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/************************************************************************
4+
*
5+
* Copyright 2023 Adobe
6+
* All Rights Reserved.
7+
*
8+
* NOTICE: All information contained herein is, and remains
9+
* the property of Adobe and its suppliers, if any. The intellectual
10+
* and technical concepts contained herein are proprietary to Adobe
11+
* and its suppliers and are protected by all applicable intellectual
12+
* property laws, including trade secret and copyright laws.
13+
* Dissemination of this information or reproduction of this material
14+
* is strictly forbidden unless prior written permission is obtained
15+
* from Adobe.
16+
* ************************************************************************
17+
*/
18+
-->
19+
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
20+
<page name="AdminSalesOrderViewPage" url="sales/order/view/order_id/{{order_id}}" area="admin" module="Magento_Sales" parameterized="true">
21+
<section name="AdminSalesOrderViewSection"/>
22+
</page>
23+
</pages>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/************************************************************************
4+
*
5+
* Copyright 2023 Adobe
6+
* All Rights Reserved.
7+
*
8+
* NOTICE: All information contained herein is, and remains
9+
* the property of Adobe and its suppliers, if any. The intellectual
10+
* and technical concepts contained herein are proprietary to Adobe
11+
* and its suppliers and are protected by all applicable intellectual
12+
* property laws, including trade secret and copyright laws.
13+
* Dissemination of this information or reproduction of this material
14+
* is strictly forbidden unless prior written permission is obtained
15+
* from Adobe.
16+
* ************************************************************************
17+
*/
18+
-->
19+
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
20+
<page name="CustomerOrderCancellationFromOrderHistoryPage" url="sales/order/history/" area="storefront" module="Magento_Sales"/>
21+
</pages>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/************************************************************************
4+
*
5+
* Copyright 2023 Adobe
6+
* All Rights Reserved.
7+
*
8+
* NOTICE: All information contained herein is, and remains
9+
* the property of Adobe and its suppliers, if any. The intellectual
10+
* and technical concepts contained herein are proprietary to Adobe
11+
* and its suppliers and are protected by all applicable intellectual
12+
* property laws, including trade secret and copyright laws.
13+
* Dissemination of this information or reproduction of this material
14+
* is strictly forbidden unless prior written permission is obtained
15+
* from Adobe.
16+
* ************************************************************************
17+
*/
18+
-->
19+
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
20+
<page name="CustomerOrderCancellationFromRecentOrdersPage" url="customer/account/" area="storefront" module="Magento_Sales"/>
21+
</pages>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
9+
<section name="AdminSalesOrderViewSection">
10+
<element name="orderHistoryNoteListFirstComment" type="text" selector="#order_history_block .note-list-item:first-child .note-list-comment"/>
11+
<element name="orderHistoryNoteListLastComment" type="text" selector="#order_history_block .note-list-item:last-child .note-list-comment"/>
12+
</section>
13+
</sections>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/************************************************************************
4+
*
5+
* Copyright 2023 Adobe
6+
* All Rights Reserved.
7+
*
8+
* NOTICE: All information contained herein is, and remains
9+
* the property of Adobe and its suppliers, if any. The intellectual
10+
* and technical concepts contained herein are proprietary to Adobe
11+
* and its suppliers and are protected by all applicable intellectual
12+
* property laws, including trade secret and copyright laws.
13+
* Dissemination of this information or reproduction of this material
14+
* is strictly forbidden unless prior written permission is obtained
15+
* from Adobe.
16+
* ************************************************************************
17+
*/
18+
-->
19+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
20+
<section name="CustomerOrderCancellationSection">
21+
<element name="linkToOrder" type="button" selector="a.order-number"/>
22+
<element name="textOrderStatus" type="text" selector=".order-status"/>
23+
<element name="linkToOpenModal" type="button" selector=".actions .cancel-order" />
24+
<element name="valueForOrderCancellationReason" type="select" selector=".cancel-order-reason"/>
25+
<element name="confirmOrderCancellation" type="button" selector=".cancel-order-button" />
26+
<element name="referenceToLatestOrderStatus" type="text" selector=".table-order-items tr:first-child td.status" />
27+
<element name="referenceToLatestOrderId" type="text" selector=".table-order-items tr:first-child td.id" />
28+
<element name="messageAtTheTop" type="text" selector=".messages .message-error" />
29+
<element name="loadingMask" type="text" selector=".loading-mask" />
30+
</section>
31+
</sections>

0 commit comments

Comments
 (0)