Skip to content

Commit a989a3e

Browse files
committed
Merge remote-tracking branch 'origin/MC-17003' into 2.3-develop-pr86
2 parents 2e3073d + fc99c48 commit a989a3e

File tree

9 files changed

+196
-7
lines changed

9 files changed

+196
-7
lines changed

app/code/Magento/Sales/Test/Mftf/ActionGroup/AdminOpenAndFillCreditMemoRefundActionGroup.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
<fillField userInput="{{shippingRefund}}" selector="{{AdminCreditMemoTotalSection.refundShipping}}" stepKey="fillShipping"/>
3535
<fillField userInput="{{adjustmentRefund}}" selector="{{AdminCreditMemoTotalSection.adjustmentRefund}}" stepKey="fillAdjustmentRefund"/>
3636
<fillField userInput="{{adjustmentFee}}" selector="{{AdminCreditMemoTotalSection.adjustmentFee}}" stepKey="fillAdjustmentFee"/>
37+
<waitForElementVisible selector="{{AdminCreditMemoTotalSection.updateTotals}}" stepKey="waitForUpdateTotalsButton"/>
38+
<click selector="{{AdminCreditMemoTotalSection.updateTotals}}" stepKey="clickUpdateTotals"/>
3739
<checkOption selector="{{AdminCreditMemoTotalSection.emailCopy}}" stepKey="checkSendEmailCopy"/>
3840
</actionGroup>
3941

app/code/Magento/Sales/Test/Mftf/Test/AdminCheckingCreditMemoUpdateTotalsTest.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
<testCaseId value="MC-18159"/>
1919
<useCaseId value="MC-17003"/>
2020
<group value="sales"/>
21-
<skip>
22-
<issueId value="MC-17003"/>
23-
</skip>
2421
</annotations>
2522
<before>
2623
<!--Create product-->
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Sales\ViewModel\CreditMemo\Create;
10+
11+
use Magento\Backend\Block\Widget\Button;
12+
use Magento\Framework\View\Element\BlockInterface;
13+
use Magento\Framework\View\LayoutInterface;
14+
use Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create\Items;
15+
16+
/**
17+
* View model to add Update Totals button for new Credit Memo
18+
*/
19+
class UpdateTotalsButton implements \Magento\Framework\View\Element\Block\ArgumentInterface
20+
{
21+
/**
22+
* @var LayoutInterface
23+
*/
24+
private $layout;
25+
26+
/**
27+
* @var Items
28+
*/
29+
private $items;
30+
31+
/**
32+
* @param LayoutInterface $layout
33+
* @param Items $items
34+
*/
35+
public function __construct(
36+
LayoutInterface $layout,
37+
Items $items
38+
) {
39+
$this->layout = $layout;
40+
$this->items = $items;
41+
}
42+
43+
/**
44+
* Get Update Totals block html.
45+
*
46+
* @return string
47+
*/
48+
public function getUpdateTotalsButton(): string
49+
{
50+
$block = $this->createUpdateTotalsBlock();
51+
52+
return $block->toHtml();
53+
}
54+
55+
/**
56+
* Create Update Totals block.
57+
*
58+
* @return BlockInterface
59+
*/
60+
private function createUpdateTotalsBlock(): BlockInterface
61+
{
62+
$onclick = "submitAndReloadArea($('creditmemo_item_container'),'" . $this->items->getUpdateUrl() . "')";
63+
$block = $this->layout->addBlock(Button::class, 'update_totals_button', 'order_items');
64+
$block->setData(
65+
[
66+
'label' => __('Update Totals'),
67+
'class' => 'update-totals-button secondary',
68+
'onclick' => $onclick,
69+
]
70+
);
71+
72+
return $block;
73+
}
74+
}

app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_new.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
</block>
1919
<block class="Magento\Sales\Block\Adminhtml\Order\Payment" name="order_payment"/>
2020
<block class="Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create\Items" name="order_items" template="Magento_Sales::order/creditmemo/create/items.phtml">
21+
<arguments>
22+
<argument name="viewModel" xsi:type="object">Magento\Sales\ViewModel\CreditMemo\Create\UpdateTotalsButton</argument>
23+
</arguments>
2124
<block class="Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer" name="order_items.default" as="default" template="Magento_Sales::order/creditmemo/create/items/renderer/default.phtml"/>
2225
<block class="Magento\Sales\Block\Adminhtml\Items\Column\Qty" name="column_qty" template="Magento_Sales::items/column/qty.phtml" group="column"/>
2326
<block class="Magento\Sales\Block\Adminhtml\Items\Column\Name" name="column_name" template="Magento_Sales::items/column/name.phtml" group="column"/>

app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_updateqty.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
<update handle="sales_order_item_price"/>
1010
<body>
1111
<block class="Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create\Items" name="order_items" template="Magento_Sales::order/creditmemo/create/items.phtml">
12+
<arguments>
13+
<argument name="viewModel" xsi:type="object">Magento\Sales\ViewModel\CreditMemo\Create\UpdateTotalsButton</argument>
14+
</arguments>
1215
<block class="Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer" name="order_items.default" as="default" template="Magento_Sales::order/creditmemo/create/items/renderer/default.phtml"/>
1316
<block class="Magento\Sales\Block\Adminhtml\Items\Column\Qty" name="column_qty" template="Magento_Sales::items/column/qty.phtml" group="column"/>
1417
<block class="Magento\Sales\Block\Adminhtml\Items\Column\Name" name="column_name" template="Magento_Sales::items/column/name.phtml" group="column"/>

app/code/Magento/Sales/view/adminhtml/templates/order/creditmemo/create/items.phtml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
/* @var \Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create\Items $block */
88
?>
9-
<?php $_items = $block->getCreditmemo()->getAllItems() ?>
9+
<?php
10+
/** @var Magento\Sales\ViewModel\CreditMemo\Create\UpdateTotalsButton $viewModel */
11+
$viewModel = $block->getData('viewModel');
12+
$_items = $block->getCreditmemo()->getAllItems();
13+
?>
1014

1115
<section class="admin__page-section">
1216
<div class="admin__page-section-title">
@@ -100,6 +104,7 @@
100104
<span class="title"><?= $block->escapeHtml(__('Refund Totals')) ?></span>
101105
</div>
102106
<?= $block->getChildHtml('creditmemo_totals') ?>
107+
<div class="totals-actions"><?= /* @noEscape */ $viewModel->getUpdateTotalsButton() ?></div>
103108
<div class="order-totals-actions">
104109
<div class="field choice admin__field admin__field-option field-append-comments">
105110
<input id="notify_customer"
@@ -139,8 +144,8 @@ require(['jquery'], function(jQuery){
139144

140145
//<![CDATA[
141146
var submitButtons = jQuery('.submit-button');
142-
var updateButtons = jQuery('.update-button');
143-
var fields = jQuery('.qty-input');
147+
var updateButtons = jQuery('.update-button, .update-totals-button');
148+
var fields = jQuery('.qty-input, .order-subtotal-table input[type="text"]');
144149
function enableButtons(buttons) {
145150
buttons.removeClass('disabled').prop('disabled', false);
146151
}

app/design/adminhtml/Magento/backend/Magento_Sales/web/css/source/module/order/_total.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
}
2323
}
2424

25+
.totals-actions {
26+
text-align: right;
27+
}
28+
2529
.order-totals-actions {
2630
margin-top: @indent__s;
2731
.actions {

dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Totals.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace Magento\Sales\Test\Block\Adminhtml\Order\Creditmemo;
810

911
use Magento\Mtf\Client\Locator;
@@ -27,6 +29,34 @@ class Totals extends \Magento\Sales\Test\Block\Adminhtml\Order\Totals
2729
*/
2830
protected $capture = '[name="invoice[capture_case]"]';
2931

32+
/**
33+
* Refund Shipping css selector.
34+
*
35+
* @var string
36+
*/
37+
private $refundShippingSelector = '#shipping_amount';
38+
39+
/**
40+
* Adjustment Refund css selector.
41+
*
42+
* @var string
43+
*/
44+
private $adjustmentRefundSelector = '#adjustment_positive';
45+
46+
/**
47+
* Adjustment Fee css selector.
48+
*
49+
* @var string
50+
*/
51+
private $adjustmentFeeSelector = '#adjustment_negative';
52+
53+
/**
54+
* Update Totals button css selector.
55+
*
56+
* @var string
57+
*/
58+
private $updateTotalsSelector = '.update-totals-button';
59+
3060
/**
3161
* Submit invoice.
3262
*
@@ -57,4 +87,44 @@ public function setCaptureOption($option)
5787
{
5888
$this->_rootElement->find($this->capture, Locator::SELECTOR_CSS, 'select')->setValue($option);
5989
}
90+
91+
/**
92+
* Get Refund Shipping input element.
93+
*
94+
* @return \Magento\Mtf\Client\ElementInterface
95+
*/
96+
public function getRefundShippingElement()
97+
{
98+
return $this->_rootElement->find($this->refundShippingSelector, Locator::SELECTOR_CSS);
99+
}
100+
101+
/**
102+
* Get Adjustment Refund input element.
103+
*
104+
* @return \Magento\Mtf\Client\ElementInterface
105+
*/
106+
public function getAdjustmentRefundElement()
107+
{
108+
return $this->_rootElement->find($this->adjustmentRefundSelector, Locator::SELECTOR_CSS);
109+
}
110+
111+
/**
112+
* Get Adjustment Fee input element.
113+
*
114+
* @return \Magento\Mtf\Client\ElementInterface
115+
*/
116+
public function getAdjustmentFeeElement()
117+
{
118+
return $this->_rootElement->find($this->adjustmentFeeSelector, Locator::SELECTOR_CSS);
119+
}
120+
121+
/**
122+
* Click update totals button.
123+
*
124+
* @return void
125+
*/
126+
public function clickUpdateTotals()
127+
{
128+
$this->_rootElement->find($this->updateTotalsSelector)->click();
129+
}
60130
}

dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/CreateCreditMemoStep.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace Magento\Sales\Test\TestStep;
810

911
use Magento\Checkout\Test\Fixture\Cart;
@@ -95,8 +97,11 @@ public function run()
9597
if ($this->compare($items, $refundData)) {
9698
$this->orderCreditMemoNew->getFormBlock()->updateQty();
9799
}
98-
100+
$hasChangeTotals = $this->isTotalsDataChanged($refundData);
99101
$this->orderCreditMemoNew->getFormBlock()->fillFormData($refundData);
102+
if ($hasChangeTotals) {
103+
$this->orderCreditMemoNew->getTotalsBlock()->clickUpdateTotals();
104+
}
100105
$this->orderCreditMemoNew->getFormBlock()->submit();
101106
}
102107

@@ -116,4 +121,30 @@ protected function getCreditMemoIds()
116121
$this->salesOrderView->getOrderForm()->openTab('creditmemos');
117122
return $this->salesOrderView->getOrderForm()->getTab('creditmemos')->getGridBlock()->getIds();
118123
}
124+
125+
/**
126+
* Is totals data changed.
127+
*
128+
* @param array $data
129+
* @return bool
130+
*/
131+
private function isTotalsDataChanged(array $data): bool
132+
{
133+
$compareData = [
134+
'shipping_amount' =>
135+
$this->orderCreditMemoNew->getTotalsBlock()->getRefundShippingElement()->getValue(),
136+
'adjustment_positive' =>
137+
$this->orderCreditMemoNew->getTotalsBlock()->getAdjustmentRefundElement()->getValue(),
138+
'adjustment_negative' =>
139+
$this->orderCreditMemoNew->getTotalsBlock()->getAdjustmentFeeElement()->getValue(),
140+
];
141+
142+
foreach ($compareData as $fieldName => $fieldValue) {
143+
if (isset($data['form_data'][$fieldName]) && $fieldValue !== $data['form_data'][$fieldName]) {
144+
return true;
145+
}
146+
}
147+
148+
return false;
149+
}
119150
}

0 commit comments

Comments
 (0)