1

Can anyone help me, how to disable input refund shipping, adjustment refund and adjustment fee when we create credit memo on Magento 2?

enter image description here

I can disable it on Magento 1, but I am confused how to disable it for Magento 2.

enter image description here

[edit] in my case, I need to validate a condition. I need to delete that field for payment by certain methods only. so not all orders get disabled/

1
  • I am not able to comment but with Shyam solution how would you do it to remove only one of those three fields? i follow the solution but it removes the three of them i want only the adjustment fee disabled is that even possible?
    – Mr Robot
    Mar 1, 2019 at 0:16

1 Answer 1

1

There is a block adjustments in sales_order_creditmemo_new.xml layout which is responsible to generate adjustment fields. We can simply remove this block from the layout.

In order to disable these fields, create a new file with the name sales_order_creditmemo_new in your custom module and paste below content to remove adjustments block.

app/code/{Namespace}/{Module}/view/adminhtml/layout/sales_order_creditmemo_new.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="creditmemo_totals">
            <referenceBlock name="adjustments" remove="true"/>
        </referenceBlock>
    </body>
</page>

UPDATE

To remove a block conditionally, you can use a helper in layout to apply some conditions.

app/code/{Namespace}/{Module}/view/adminhtml/layout/sales_order_creditmemo_new.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="creditmemo_totals">
            <action method="unsetChild">
                <argument name="block" xsi:type="helper" helper="{Namespace}\{Module}\Helper\Data::removeAdjustmentSection">
                    <param name="name">adjustments</param>
                </argument>
            </action>
        </referenceBlock>
    </body>
</page>

app/code/{Namespace}/{Module}/Helper/Data.php

<?php
namespace {Namespace}\{Module}\Helper;

/**
 * @param $name | Block's reference in layout that you wish to remove
 * passed as param in layout
 * @return string
 */
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
    public function removeAdjustmentSection($name)
    {
        if ({some-conditions-to-remove-block}) {
            return $name;
        }

        return '';
    }
}

In removeAdjustmentSection function, you can define your conditions to remove the block.

3
  • Hi @Shyam, thanks. But in my case, I need to validate a condition. I need to delete that field for payment by certain methods only. do you know how to do that? so not all order get disabled :) Nov 20, 2017 at 10:46
  • @HusenBisri Please check the updated answer
    – Shyam
    Nov 20, 2017 at 13:24
  • Great, thank you @shyam. btw, do you have a reference to learn about xml for magento 2? on devdocs.magento.com I did not find like this Nov 21, 2017 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.