Question

I create custom attribute("custom_feild") in sales_shipment table and save value. And also make attribute("custom_feild") in sales_shipment_grid. How can copy data from custom_feild of sales_shipment table into custom_feild of sales_shipment_grid table ?

Was it helpful?

Solution

Try this,

Add a column in sales_shipment_grid table like you have in sales_shipment

Then add a sales_order_shipment_grid.xml in the below path

app/code/Vendor/ModuleName/view/adminhtml/ui_component/sales_order_shipment_grid.xml

add the below code in it

<?xml version="1.0" encoding="UTF-8"?>                         
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="sales_order_shipment_columns">
<column name="custom_feild">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="filter" xsi:type="string">text</item>
            <item name="label" xsi:type="string" translate="true">Column Name Goes here</item>
            <item name="visible" xsi:type="boolean">false</item>
        </item>
    </argument>
</column>                                                    
</columns>                                                   
</listing>

then add di.xml in the below path

app/code/Vendor/ModuleName/etc/di.xml

add the below code in it

<?xml version="1.0"?>                                                   
<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\Shipment\Grid" type="Magento\Sales\Model\ResourceModel\Grid">
<arguments>
    <argument name="columns">
        <item name="custom_feild" xsi:type="string">sales_shipment.custom_feild</item>
    </argument>
</arguments>                                                     
</virtualType>                                                        
</config>

custom_feild is the name of column which you have in sales_shipment table and make sure you have same column in sales_shipment_grid table as well.

NOTE : When you post data into sales_shipment table next time then it will also be added into sales_shipment_grid table as then xml will list the column in grid view.

Run below commands after you made these changes

php bin/magento setup:upgrade
php bin/magento cache:flush

Hope this helps :)

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