0

I was able to successfully add new order field through an install script:

$installer->addAttribute('order', 'is_local', array('type'=>Varien_Db_Ddl_Table::TYPE_SMALLINT, 'default'=>1));

However, I could not update the "default" property of it, let's say default=>0. One suggested to use updateAttribute() https://stackoverflow.com/questions/10420199/magento-module-setup-change-product-attribute-to-not-required but it doesn't work in order table.

Thank you.

2 Answers 2

1

Hi you can do this by updateAttribute() function

Create upgrade installer and on the upgrade file update field by updateAttribute() function.

Here

$installer = $this;
/* @var $installer Mage_Sales_Model_Mysql4_Setup */

$installer->startSetup();
$installer->updateAttribute('order', 'is_local',  array('default'=>0));
$installer->endSetup();

format:

$params=array()
$installer->updateAttribute(EntityTypeId,attribute_code',$params );

Till now ,i cannot find the where the issue But currently, i give u an alternative solution:

$installer = $this;
/* @var $installer Mage_Sales_Model_Mysql4_Setup */

$installer->startSetup();
$installer->run("ALTER TABLE  {$this->getTable('sales_flat_order')} CHANGE `is_local` `is_local` SMALLINT(6) NULL DEFAULT '0' COMMENT 'Is Local'");
$installer->endSetup();
4
  • I am not sure but I already did that, both: $installer->updateAttribute('order', 'is_local', array('default'=>0)); and $installer->updateAttribute('order', 'is_local', 'default', 0); Jan 19, 2015 at 9:51
  • And both didn't update the order attribute. Jan 19, 2015 at 10:01
  • ok, i am checking
    – Amit Bera
    Jan 19, 2015 at 10:19
  • Getting back, I did a similar approach, and yes this works. Just a note on $this->getTable('sales_flat_order') which could be $installer->getTable('sales/order'). Jan 20, 2015 at 1:53
0

Here's what I did, since sales/order is a flat table:

$installer->run("
ALTER TABLE `{$installer->getTable('sales/order')}` CHANGE `is_local` `is_local` SMALLINT(6) NULL DEFAULT '0' COMMENT 'Is Local';
");

and

$installer->updateAttribute('order', 'is_local', 'default_value', 0); 

to make it backward compatible.

And verified the default value of the field/attribute is now 0.

Complete:

$installer = $this;
/* @var $installer Mage_Sales_Model_Mysql4_Setup */

$installer->startSetup();

$installer->updateAttribute('order', 'is_local', 'default_value', 0); 
$installer->run("ALTER TABLE `{$installer->getTable('sales/order')}` CHANGE `is_local` `is_local` SMALLINT(6) NULL DEFAULT '0' COMMENT 'Is Local';");

$installer->endSetup();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.