0

I'm trying to add a custom field to the order admin screen, specifically a dropdown box with the information appended to the order.

I have created a custom module, which has the structure:

etc -> with config.xml

    <?xml version="1.0"?>
<config>
    <modules>
        <Custom_Module>
            <version>0.4.0</version>
        </Custom_Module>
    </modules>

    <global>
     <resources>
         <Custom_Module>
              <setup>
                  <module>Custom_Module</module>
                  <class>Mage_Sales_Model_Mysql4_Setup</class>
              </setup>
               <connection>
                <use>core_setup</use>
              </connection>
         </Custom_Module>
     </resources>
 </global>
</config>

sql -> Custom_Module_Setup/mysql4-install-0.4.0.php

    $installer = $this;
$installer->startSetup();

$options = array(
    'value' = array(
        'test' => array('test'),
        'test2' => array('test2'),
        )
    );

$installer->addAttribute('order', 'test_option', array(
    'label' => 'Test Option',
    'default' => '',
    'type' => 'varchar',
    'input' => 'select',
    'visible' => true,
    'required' => false,
    'position' => 1,
    'visible_on_front'  => false,
    'option' => $options,
    'default' => array('web'),
));

$installer->endSetup();

I also have in modules

<?xml version="1.0"?>
<config>
    <modules>
        <Custom_Module>
            <active>true</active>
            <codePool>local</codePool>
            <depends></depends>
        </Custom_Module>
    </modules>
</config>

From what I can tell, the module is activated, and config file is read but the install file is not? The attribute is not appearing as a column in sales_flat_order (I have been flushing the cache while testing each time)

So question 1 what am I doing wrong? Question 2 once I have it appearing in the column, how can I then display/save it in the order edit screen?

2 Answers 2

1

You have an error in your config.xml, change:

<global>
 <resources>
     <Custom_Module>
          <setup>
              <module>Custom_Module</module>
              <class>Mage_Sales_Model_Mysql4_Setup</class>
          </setup>
           <connection>
            <use>core_setup</use>
          </connection>
     </Custom_Module>
 </resources>

To:

<resources>
        <custom_module_setup>
            <setup>
                <module>Custom_Module</module>
        <class>Mage_Sales_Model_Mysql4_Setup</class>
            </setup>
        </custom_module_setup>
    </resources>

And then create the upgrade script in the directory: sql/custom_module_setup/, since 1.6 you can name them install-0.4.0.php (without the mysql4- prefix). Also check the core_resource tabel for custom_module_setup to check what version is installed, remove the record if you want your setup script to run again.

1
  • So I modified as you have above, renamed the sql/Custom_Module_Setup to custom_module_setup and dropped the mysql4 prefix. I then went to core_resources and removed the version and retested. Still no attribute appearing as a column in sales_flat_order
    – Tim Nash
    Commented Jun 18, 2013 at 12:16
0

This install to me has worked:

$installer = $this;
$installer->startSetup();
$installer->addAttribute(
    'order',
    'order_telephone',
    array(
        'type' => 'int',
        'grid' => true
    )
);
$installer->endSetup();
3
  • It would be good to clarify what $this is.
    – benmarks
    Commented Jul 18, 2013 at 16:48
  • $this is it the class instanciate Mage_Core_Model_Resource_Setup
    – jruzafa
    Commented Dec 20, 2013 at 19:55
  • Mage_Core_Model_Resource_Setup does not have addAttribute().
    – benmarks
    Commented Dec 21, 2013 at 16:55

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.