3

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 ?

  • Hi, Can you help me how to add custom_field value in sales_shipment while create shipment programmatically – kim na na Apr 22 at 10:19
  • make file Vendor\ModuleName\Setup\UpgradeSchema.php – HaFiz Umer Apr 23 at 10:05
  • make this upgrade method <?php namespace Vendor\ModuleName\Setup; use Magento\Framework\Setup\UpgradeSchemaInterface; use Magento\Framework\Setup\SchemaSetupInterface; use Magento\Framework\Setup\ModuleContextInterface; class UpgradeSchema implements UpgradeSchemaInterface { public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context) { } – HaFiz Umer Apr 23 at 10:07
  • paste these link of code in upgrade method $salesShipmentGridTable='sales_shipment_grid'; $setup->startSetup(); $setup->getConnection() ->addColumn( $setup->getTable($salesShipmentGridTable), 'custom_attrbute', [ 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 'length' => 255, 'comment' =>'Custom Attribute' ] ); $setup->endSetup(); – HaFiz Umer Apr 23 at 10:10
2

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 :)

  • not need to overrid the sales_order_shipment_grid.xml because am not need to display column on grid. and in virtualType tag this name name="Magento\Sales\Model\ResourceModel\Order\Shipment\Grid" generate xmlSchemaDocWalk error. I follow the magento module/sales/etc/di.xml there in virtualtype tag name has name="ShipmentGridAggregator" . it copy value in sales_shipment_grid table. Thanks – HaFiz Umer Mar 27 at 13:38
  • Ok fine thenm if you don't want to display in shipment grid then you can ignore sales_order_shipment_grid.xml and will the di.xml copied the value in sales_shipment table ?? @HaFizUmer – Prathap Gunasekaran Mar 28 at 4:40
  • yes copy value in grid table. But i use virtualtype name="ShipmentGridAggregator" . i your solution virtual class name create xmlSchemaDocWalk error. – HaFiz Umer Mar 28 at 6:48

Your Answer

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

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