0

I have added a custom attribute custom_status to the sales_creditmemo and the sales_creditmemo_grid tables via a InstallData script in a custom module, and added the custom field to the creditmemo listing in the admin area by creating a /view/adminhtml/ui_component/sales_order_creditmemo_grid.xml file in the custom module. So far all works fine.

Now when I change the value of this field by modifying a creditmemo and storing it via the creditmemoRepository, the field gets updated in the sales_creditmemo table. But not In the sales_creditmemo_grid table.

I use a virtualType in the etc/di.xml file to connect the two. this works fine for the invoice grid, but not in the Creditmemo grid:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <virtualType name="Magento\Sales\Model\ResourceModel\Order\Invoice\Grid" type="Magento\Sales\Model\ResourceModel\Grid">
        <arguments>
            <argument name="columns" xsi:type="array">
                <item name="custom_status" xsi:type="string">sales_invoice.custom_status</item>
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="Magento\Sales\Model\ResourceModel\Order\Creditmemo\Grid" type="Magento\Sales\Model\ResourceModel\Grid">
        <arguments>
            <argument name="columns" xsi:type="array">
                <item name="custom_status" xsi:type="string">sales_creditmemo.custom_status</item>
            </argument>
        </arguments>
    </virtualType>
</config>

I copied the code for the invoice from a tutorial, and modified it for the creditmemo's, so there is probably something I did wrong there. Anyone know how to do this for Creditmemo's?

I am using Magento 2.4.4.

3
  • First check, you have duplicate names for 'item' in both arguments. Rectify it first. Jun 22 at 11:17
  • @JasvirSingh what one do you mean, the name in the argument or the name in the item? The name in the item is the name of the field in the table. that is the same name in both the creditmemo as the invoice grid. The name in the argument, I asumed is just to identify what type of element i want to modify. Jun 23 at 7:34
  • <item name="custom_status" xsi:type="string"> You have mentioned same name "custom_status" two times , that can be the case. its okay you use same values but names should be different I think. Jun 24 at 8:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.