HI,
I want to add new attributes to order table, i created a module, with an installData.php, It worked.
Now I want to add more attribute, so i created a upgradeData.php file with the following code:
<?php namespace Cursol\OrderAttribute\Setup; use Magento\Framework\Setup\UpgradeDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Sales\Model\Order; class InstallData implements UpgradeDataInterface { /** * @var \Magento\Sales\Setup\SalesSetupFactory */ protected $salesSetupFactory; /** * @param \Magento\Sales\Setup\SalesSetupFactory $salesSetupFactory */ public function __construct( \Magento\Sales\Setup\SalesSetupFactory $salesSetupFactory ) { $this->salesSetupFactory = $salesSetupFactory; } /** * {@inheritDoc} */ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $installer = $setup; $installer->startSetup(); $salesSetup = $this->salesSetupFactory->create(['resourceName' => 'sales_setup', 'setup' => $installer]); $salesSetup->addAttribute(Order::ENTITY, 'id_tactill', [ 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 'length'=> 255, 'visible' => false, 'nullable' => true ]); $installer->getConnection()->addColumn( $installer->getTable('sales_order_grid'), 'id_tactill', [ 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 'length' => 255, 'comment' =>'Id Tactill' ] ); $salesSetup->addAttribute(Order::ENTITY, 'remboursement_tactill', [ 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 'length'=> 255, 'visible' => false, 'nullable' => true ]); $installer->getConnection()->addColumn( $installer->getTable('sales_order_grid'), 'remboursement_tactill', [ 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 'length' => 255, 'comment' =>'Id Remboursement Tactill' ] ); $salesSetup->addAttribute(Order::ENTITY, 'closed_at_tactill', [ 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 'length'=> 255, 'visible' => false, 'nullable' => true ]); $installer->getConnection()->addColumn( $installer->getTable('sales_order_grid'), 'closed_at_tactill', [ 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 'length' => 255, 'comment' =>'Closed At Tactill' ] ); $salesSetup->addAttribute(Order::ENTITY, 'number_tactill', [ 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 'length'=> 255, 'visible' => false, 'nullable' => true ]); $installer->getConnection()->addColumn( $installer->getTable('sales_order_grid'), 'number_tactill', [ 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 'length' => 255, 'comment' =>'Number tactill' ] ); /////tried this first $salesSetup->addAttribute(Order::ENTITY, 'vendor_tactil', [ 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 'length'=> 255, 'visible' => false, 'nullable' => true ]); $installer->getConnection()->addColumn( $installer->getTable('sales_order_grid'), 'vendor_tactil', [ 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 'length' => 255, 'comment' =>'Vendor tactill' ] ); /////then tried this to see if it work better $options = ['type' => 'varchar', 'visible' => false, 'required' => false]; $salesSetup->addAttribute('order', 'vendor_tactil', $options); $installer->endSetup(); } }
I doesn't get any error during upgrade, but it doesn't add the column either
i've already seen this post, but i doesn't see my mistake.
Any help ?
thanks
Solved! Go to Solution.
Hi @thibault_andrei
The post which you are referring is fine.
You have missed few things in your class for upgradeSchema.
Wrong
class InstallData implements UpgradeDataInterface
Correct
class UpgradeData implements UpgradeDataInterface
You have also missed updated version number in the class, which you have to define in app/etc/module.xml
if ($context->getVersion() && version_compare($context->getVersion(), '1.0.2') < 0 ){
Please compare your file with reference file and do the required changes.
If you are using magento2 latest version then you can also use db_schema.
I hope it will help you!
Hi @thibault_andrei
The post which you are referring is fine.
You have missed few things in your class for upgradeSchema.
Wrong
class InstallData implements UpgradeDataInterface
Correct
class UpgradeData implements UpgradeDataInterface
You have also missed updated version number in the class, which you have to define in app/etc/module.xml
if ($context->getVersion() && version_compare($context->getVersion(), '1.0.2') < 0 ){
Please compare your file with reference file and do the required changes.
If you are using magento2 latest version then you can also use db_schema.
I hope it will help you!
I feel ashamed that i didn't see the class name change
It was the probleme, i don't need the version comparison, as it just a test and not mean to be reused.
Thanks for the correction