Question

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/

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top