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.