How to Add New Column in Magento 2 Quote Table & Order Table
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
<?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.
Feel free to discuss any doubts on the topic using the Comments section below.
Thank you.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
How to Add Block Before Add to Cart Button in Magento 2 Product Page
How to Check if Magento 2 Order is Invoiced or Shipped
Next