2

What is the proper way to add new custom attribute to sales_flat_invoice table?

I need to extend this table in order to mark that the payment was made, so subsequent updates do not trigger connection to external system.

2
  • custom attribute mean new field to sales_flat_invoice table?
    – Amit Bera
    Sep 29, 2015 at 9:44
  • yes new field to sales_flat_invoice table
    – bogumbiker
    Sep 30, 2015 at 2:10

1 Answer 1

0

The steps for create an custom attribute:

In order to full fill to create a custom attribute in the table,you need to Create a module.

On this extension using mysql installer,create new field.

Step1: create config.xml where define the installer.location: app/code/local/[ModuleNameSpace]/[ModuleName]/etc

Code:

<?xml version="1.0"?>
<config>
  <modules>
    <[ModuleNameSpace]_[ModuleName]>
      <version>1.0.0</version>
    </[ModuleNameSpace]_[ModuleName]>
  </modules>
  <global>
  <models>
    <modulename>
      <class>[ModuleNameSpace]_[ModuleName]_Model</class>

    </modulename>
  </models>
  <resources>
    <addsalesattribute_setup>
      <setup>
        <module>[ModuleNameSpace]_[ModuleName]</module>
        <class>Mage_Sales_Model_Mysql4_Setup</class>
      </setup>
      <connection>
        <use>core_setup</use>
      </connection>
    </addsalesattribute_setup>
    <addsalesattribute_write>
      <connection>
        <use>core_write</use>
      </connection>
    </addsalesattribute_write>
    <addsalesattribute_read>
      <connection>
        <use>core_read</use>
      </connection>
    </addsalesattribute_read>
  </resources>
  </global>
</config>

Step2: installer file which will add new columns at table

location: app/code/local/[ModuleNameSpace]/[ModuleName]/sql/addsalesattribute_setup/mysql4-install-0.1.0.php

Code:

<?php
$installer = $this;
$installer->startSetup();

$installer->addAttribute("invoice", "custom_field_one", array("type"=>"text"));
$installer->endSetup();

Step3: create module file [ModuleNameSpace]_[ModuleName].xml at app/etc/modules/

<?xml version="1.0"?>
<config>
  <modules>
    <[ModuleNameSpace]_[ModuleName]>
      <active>true</active>
      <codePool>local</codePool>
  <depends>Mage_Sales</depends>      
 </[ModuleNameSpace]_[ModuleName]>
  </modules>
</config>
4
  • thanks what will be setter and getter for that field? setCustomFieldOne and getCustomFieldOne?
    – bogumbiker
    Sep 30, 2015 at 2:11
  • after running above I am trying to do: desc sales_flat_invoice; but there is no "custom_field_one" attribute there. I have checked and the code in the installer is being run.
    – bogumbiker
    Sep 30, 2015 at 5:52
  • having the same problem, did you find a solution?
    – encodes
    Oct 20, 2015 at 10:33
  • What does the handlers <addsalesattribute_write> and <addsalesattribute_read> do? I created a module without these handler. All working fine. What is the need of it?
    – Anto S
    Jul 9, 2016 at 8:07

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.