Magento 2, no matter how feature-rich, falls short when it comes to meeting the highly customized requirements of clients. Fortunately, the flexible platform allows the developers to modify the code in order to complete the clients’ requirements!
Here, the customization that I’m discussing is to add new column in Magento 2 Quote table & Order table. It can be any column that is not in the default Magento 2 quote table and order table, but the data from the database is needed to be fetched in these tables.
Follow the below method and you get customized Magento 2 quote table and order table!
Method to Add New Column in Magento 2 Quote Table & Order Table:
Create file UpgradeSchema at Vendor/Extension/Setup
<?php namespace Vendor/Extension/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) { $setup->startSetup(); $quoteTable = 'quote'; $orderTable = 'sales_order'; //Quote table $setup->getConnection() ->addColumn( $setup->getTable($quoteTable), 'fee', [ 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, 'length' => '12,4', 'default' => 0.00, 'nullable' => true, 'comment' => 'Extra fee' ] ); //Order table $setup->getConnection() ->addColumn( $setup->getTable($orderTable), 'fee', [ 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, 'length' => '12,4', 'default' => 0.00, 'nullable' => true, 'comment' => 'Extra fee' ] ); $setup->endSetup(); } }
Hopefully, you find the solution in the above method.
Thank you.