Skip to content

Commit ff244df

Browse files
authored
LYNX-189: Implement cancellation reasons management interface
1 parent 24fb1f2 commit ff244df

File tree

8 files changed

+167
-1
lines changed

8 files changed

+167
-1
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\OrderCancellation\Block\Adminhtml\Form\Field;
9+
10+
use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray;
11+
12+
class Reasons extends AbstractFieldArray
13+
{
14+
/**
15+
* Prepare rendering the new field by adding all the needed columns
16+
*/
17+
protected function _prepareToRender()
18+
{
19+
$this->addColumn('reason', ['label' => __('Reason'), 'class' => 'required-entry']);
20+
$this->_addAfter = false;
21+
$this->_addButtonLabel = __('Add Reason');
22+
}
23+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\OrderCancellation\Model\Config\Backend;
9+
10+
use Magento\Config\Model\Config\Backend\Serialized;
11+
use Magento\Framework\Exception\LocalizedException;
12+
13+
class Reasons extends Serialized
14+
{
15+
/**
16+
* Processing object before save data
17+
*
18+
* @return $this
19+
* @throws LocalizedException
20+
*/
21+
public function beforeSave()
22+
{
23+
$value = $this->getValue();
24+
if (is_array($value)) {
25+
unset($value['__empty']);
26+
27+
if (empty($value)) {
28+
throw new LocalizedException(
29+
__('At least one reason value is required')
30+
);
31+
}
32+
}
33+
$this->setValue($value);
34+
return parent::beforeSave();
35+
}
36+
}

app/code/Magento/OrderCancellation/Test/Mftf/Section/AdminOrderCancellationConfigSection.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,12 @@
99
<section name="AdminOrderCancellationConfigSection">
1010
<element name="valueForSalesCancellation" type="select" selector="#sales_cancellation_enabled"/>
1111
<element name="systemValueForSalesCancellation" type="checkbox" selector="#sales_cancellation_enabled_inherit"/>
12+
<element name="systemValueForSalesCancellationReasons" type="checkbox" selector="#sales_cancellation_reasons_inherit"/>
13+
<element name="deleteReasonRow" type="button" selector="#sales_cancellation_reasons #item{{row}} td.col-actions button.action-delete" parameterized="true"/>
14+
<element name="deleteFirstReason" type="button" selector="#sales_cancellation_reasons tbody tr:first-child td.col-actions button.action-delete" />
15+
<element name="editReasonRow" type="input" selector="#sales_cancellation_reasons #item{{row}} input" parameterized="true"/>
16+
<element name="addReason" type="button" selector="#sales_cancellation_reasons td.col-actions-add button.action-add" />
17+
<element name="editFirstReason" type="input" selector="#sales_cancellation_reasons tbody tr:first-child input" />
18+
<element name="editLastReason" type="input" selector="#sales_cancellation_reasons tbody tr:last-child input" />
1219
</section>
1320
</sections>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="AdminOrderCancellationReasonsConfigCreateEditTest">
11+
<annotations>
12+
<features value="Order Cancellation"/>
13+
<stories value="Add / modify / delete order cancellation reasons through the admin."/>
14+
<title value="Add / modify / delete order cancellation reasons through the admin."/>
15+
<description value="Test adding, modifying and deleting order cancellation reasons through the admin."/>
16+
<severity value="AVERAGE"/>
17+
<testCaseId value="LYNX-189"/>
18+
<group value="configuration"/>
19+
<group value="pr_exclude"/>
20+
</annotations>
21+
<before>
22+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
23+
</before>
24+
<after>
25+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
26+
</after>
27+
<amOnPage url="{{AdminOrderCancellationConfigPage.url('#sales_cancellation-head')}}" stepKey="navigateToConfigurationPage"/>
28+
<waitForPageLoad time="30" stepKey="waitForAdminSalesConfigPageLoad"/>
29+
<uncheckOption selector="{{AdminOrderCancellationConfigSection.systemValueForSalesCancellationReasons}}" stepKey="uncheckUseSystemValue"/>
30+
<click selector="{{AdminOrderCancellationConfigSection.deleteFirstReason}}" stepKey="deleteDefaultReason"/>
31+
<fillField selector="{{AdminOrderCancellationConfigSection.editFirstReason}}" userInput="Modified reason" stepKey="editDefaultReason"/>
32+
<click selector="{{AdminOrderCancellationConfigSection.addReason}}" stepKey="addReason"/>
33+
<fillField selector="{{AdminOrderCancellationConfigSection.editLastReason}}" userInput="New reason" stepKey="fillReason" />
34+
<click selector="{{AdminConfigSection.saveButton}}" stepKey="saveConfig"/>
35+
<waitForElementVisible selector="{{AdminMessagesSection.success}}" stepKey="waitForElementVisible"/>
36+
<see selector="{{AdminMessagesSection.success}}" userInput="You saved the configuration." stepKey="seeConfigSuccessMessage"/>
37+
</test>
38+
</tests>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="AdminOrderCancellationReasonsConfigRemoveAllTest">
11+
<annotations>
12+
<features value="Order Cancellation"/>
13+
<stories value="Add / modify / delete order cancellation reasons through the admin."/>
14+
<title value="Add / modify / delete order cancellation reasons through the admin."/>
15+
<description value="Test that removing all order cancellation reasons through the admin yields an error when saving."/>
16+
<severity value="AVERAGE"/>
17+
<testCaseId value="LYNX-189"/>
18+
<group value="configuration"/>
19+
<group value="pr_exclude"/>
20+
</annotations>
21+
<before>
22+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
23+
</before>
24+
<after>
25+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
26+
</after>
27+
<amOnPage url="{{AdminOrderCancellationConfigPage.url('#sales_cancellation-head')}}" stepKey="navigateToConfigurationPage"/>
28+
<waitForPageLoad time="30" stepKey="waitForAdminSalesConfigPageLoad"/>
29+
<uncheckOption selector="{{AdminOrderCancellationConfigSection.systemValueForSalesCancellationReasons}}" stepKey="uncheckUseSystemValue"/>
30+
<click selector="{{AdminOrderCancellationConfigSection.deleteFirstReason}}" stepKey="deleteDefaultReason1"/>
31+
<click selector="{{AdminOrderCancellationConfigSection.deleteFirstReason}}" stepKey="deleteDefaultReason2"/>
32+
<click selector="{{AdminOrderCancellationConfigSection.deleteFirstReason}}" stepKey="deleteDefaultReason3"/>
33+
<click selector="{{AdminOrderCancellationConfigSection.deleteFirstReason}}" stepKey="deleteDefaultReason4"/>
34+
<click selector="{{AdminOrderCancellationConfigSection.deleteFirstReason}}" stepKey="deleteDefaultReason5"/>
35+
<click selector="{{AdminConfigSection.saveButton}}" stepKey="saveConfig"/>
36+
<waitForElementVisible selector="{{AdminMessagesSection.error}}" stepKey="waitForElementVisible"/>
37+
<see selector="{{AdminMessagesSection.error}}" userInput="At least one reason value is required" stepKey="seeConfigErrorMessage"/>
38+
</test>
39+
</tests>

app/code/Magento/OrderCancellation/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
},
77
"require": {
88
"php": "~8.1.0||~8.2.0",
9-
"magento/framework": "*"
9+
"magento/framework": "*",
10+
"magento/module-config": "*"
1011
},
1112
"type": "magento2-module",
1213
"license": [

app/code/Magento/OrderCancellation/etc/adminhtml/system.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
<label>Order cancellation through GraphQL</label>
1616
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
1717
</field>
18+
<field id="reasons" translate="label" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
19+
<label>Order cancellation reasons</label>
20+
<frontend_model>Magento\OrderCancellation\Block\Adminhtml\Form\Field\Reasons</frontend_model>
21+
<backend_model>Magento\OrderCancellation\Model\Config\Backend\Reasons</backend_model>
22+
</field>
1823
</group>
1924
</section>
2025
</system>

app/code/Magento/OrderCancellation/etc/config.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,23 @@
1111
<sales>
1212
<cancellation>
1313
<enabled>0</enabled>
14+
<reasons>
15+
<item1>
16+
<reason>The item(s) are no longer needed</reason>
17+
</item1>
18+
<item2>
19+
<reason>The order was placed by mistake</reason>
20+
</item2>
21+
<item3>
22+
<reason>Item(s) not arriving within the expected timeframe</reason>
23+
</item3>
24+
<item4>
25+
<reason>Found a better price elsewhere</reason>
26+
</item4>
27+
<item5>
28+
<reason>Other</reason>
29+
</item5>
30+
</reasons>
1431
</cancellation>
1532
</sales>
1633
</default>

0 commit comments

Comments
 (0)