I have been trying to create a new order attribute in Magento 2, but not successful yet.
I have created a new module and this is already showing.
I added the different codes available in my setup InstallData.php
but nothing worked so far.
Anybody who have successfully created an order attribute?
This is one of the code I have tried in InstallSchema.php
<?php
namespace Namespace\Module\Setup;
use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
/**
* @codeCoverageIgnore
*/
class InstallSchema implements InstallSchemaInterface
{
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;
$installer->startSetup();
$installer->getConnection()->addColumn(
$installer->getTable('quote'),
'delivery_eta',
[
'type' => 'varchar',
'nullable' => false,
'comment' => 'Delivery ETA',
]
);
$installer->getConnection()->addColumn(
$installer->getTable('sales_order'),
'delivery_eta',
[
'type' => 'datetime',
'nullable' => false,
'comment' => 'Delivery ETA',
]
);
$setup->endSetup();
}
}