/   /   /  Magento 2 Snippet: Add decimal column to your table by Setup

Note:

For more extensions and themes visit our store

Magento 2 Snippet: Add decimal column to your table by Setup


  Inside Setup folder add your file:

  1.  
  2.   public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) {
  3.         $installer = $setup;
  4.         $installer->startSetup();
  5.         $orderTable = $installer→getTable('sales_order');
  6.         $connection = $installer→getConnection();
  7.         $connection->addColumn(
  8.                 $orderTable, 'dec_number', [
  9.                     'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL,
  10.                     'length' => '12,4',
  11.                     'nullable' => true,
  12.                     'comment' => 'Decimal number'
  13.                 ]
  14.         );
  15.    }
  16.  

Done

Comments

IBNAB is a company made of a group of professionals whose work is providing secure open source solutions. Our company strives for reaching magnificent results with each experience and provides professional open source solutions that cover every part of the business process.