Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to set custom attribute for sales_flat_order table
    primarykey
    data
    text
    <p>I am using Magento ver. 1.6.2.0. </p> <p>After reading a number of posts and question (on SO and elsewhere) I have attempted to add an attribute to my sales_flat_order table. In previous versions of Magento, the sales/order model used the EAV method, but from what I can gather, after 1.4 it was moved to a flat table.</p> <p>So, here's my mysql-install file:</p> <pre><code>$installer = $this; $installer-&gt;getConnection()-&gt;addColumn($installer-&gt;getTable('sales/order'), 'khaos_soc', 'varchar(255) NULL'); </code></pre> <p>Which has added a column to my sales_flat_order table.</p> <p>My problem is that I cannot set data to be inserted into that field. I have an observer, that is called by the event 'checkout_submit_all_after'. The code retrieves the current order id, and then attempts to set the 'khaos_soc' data, here's the code:</p> <pre><code>$test = Mage::getModel('sales/order')-&gt;load($order-&gt;getId()); // write the khaos soc to the database $test-&gt;setKhaosSoc('just testing'); $test-&gt;setCustomerFirstname('Charlie'); $test-&gt;save(); </code></pre> <p>The setCustomerFirstname() method works, and changes the firstname to Charlie, but the setKhaosSoc() method doesn't save anything to the database. I have also tried using the setData('khaos_soc', 'just testing') way of doing things which doesn't work either.</p> <p>I have tested this by manually setting a value for 'khaos_soc' in the database, then called the appropriate order and echoed out the getKhaosSoc() result, and it worked, but I am still unable to set it.</p> <p>So, I can retrieve manually created entries for my custom attribute, but I can't set them. Can anyone suggest why that is?</p> <p>Kind regards,</p> <p>James</p> <hr> <p>I have tried the approach suggest by Zyava, but it still doesn't save. Here's my upgrade code:</p> <pre><code>$installer = $this; $installer-&gt;startSetup(); $installer-&gt;addAttribute( 'order', 'khaos_soc', array( 'type' =&gt; 'varchar', /* varchar, text, decimal, datetime */ 'grid' =&gt; false /* or true if you wan't use this attribute on orders grid page */ ) ); $installer-&gt;endSetup(); </code></pre> <p>Here's my config.xml:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;!-- /** * @category Symphony * @package Symphony_Khaosorders * @author ModuleCreator * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ --&gt; &lt;config&gt; &lt;modules&gt; &lt;Symphony_Khaosorders&gt; &lt;version&gt;0.1.8&lt;/version&gt; &lt;/Symphony_Khaosorders&gt; &lt;/modules&gt; &lt;frontend&gt; &lt;routers&gt; &lt;khaosorders&gt; &lt;use&gt;standard&lt;/use&gt; &lt;args&gt; &lt;module&gt;Symphony_Khaosorders&lt;/module&gt; &lt;frontName&gt;khaosorders&lt;/frontName&gt; &lt;/args&gt; &lt;/khaosorders&gt; &lt;/routers&gt; &lt;layout&gt; &lt;updates&gt; &lt;khaosorders&gt; &lt;file&gt;khaosorders.xml&lt;/file&gt; &lt;/khaosorders&gt; &lt;/updates&gt; &lt;/layout&gt; &lt;/frontend&gt; &lt;admin&gt; &lt;routers&gt; &lt;khaosorders&gt; &lt;use&gt;admin&lt;/use&gt; &lt;args&gt; &lt;module&gt;Symphony_Khaosorders&lt;/module&gt; &lt;frontName&gt;khaosorders&lt;/frontName&gt; &lt;/args&gt; &lt;/khaosorders&gt; &lt;/routers&gt; &lt;/admin&gt; &lt;adminhtml&gt; &lt;menu&gt; &lt;khaosorders module="khaosorders"&gt; &lt;title&gt;Khaosorders&lt;/title&gt; &lt;sort_order&gt;71&lt;/sort_order&gt; &lt;children&gt; &lt;items module="khaosorders"&gt; &lt;title&gt;Manage Items&lt;/title&gt; &lt;sort_order&gt;0&lt;/sort_order&gt; &lt;action&gt;khaosorders/adminhtml_khaosorders&lt;/action&gt; &lt;/items&gt; &lt;/children&gt; &lt;/khaosorders&gt; &lt;/menu&gt; &lt;acl&gt; &lt;resources&gt; &lt;all&gt; &lt;title&gt;Allow Everything&lt;/title&gt; &lt;/all&gt; &lt;admin&gt; &lt;children&gt; &lt;Symphony_Khaosorders&gt; &lt;title&gt;Khaosorders Module&lt;/title&gt; &lt;sort_order&gt;10&lt;/sort_order&gt; &lt;/Symphony_Khaosorders&gt; &lt;/children&gt; &lt;/admin&gt; &lt;/resources&gt; &lt;/acl&gt; &lt;layout&gt; &lt;updates&gt; &lt;khaosorders&gt; &lt;file&gt;khaosorders.xml&lt;/file&gt; &lt;/khaosorders&gt; &lt;/updates&gt; &lt;/layout&gt; &lt;/adminhtml&gt; &lt;global&gt; &lt;models&gt; &lt;khaosorders&gt; &lt;class&gt;Symphony_Khaosorders_Model&lt;/class&gt; &lt;resourceModel&gt;khaosorders_mysql4&lt;/resourceModel&gt; &lt;/khaosorders&gt; &lt;khaosorders_mysql4&gt; &lt;class&gt;Symphony_Khaosorders_Model_Mysql4&lt;/class&gt; &lt;entities&gt; &lt;khaosorders&gt; &lt;table&gt;khaosorders&lt;/table&gt; &lt;/khaosorders&gt; &lt;/entities&gt; &lt;/khaosorders_mysql4&gt; &lt;/models&gt; &lt;resources&gt; &lt;khaosorders_setup&gt; &lt;setup&gt; &lt;module&gt;Symphony_Khaosorders&lt;/module&gt; &lt;class&gt;Mage_Sales_Model_Mysql4_Setup&lt;/class&gt; &lt;/setup&gt; &lt;connection&gt; &lt;use&gt;core_setup&lt;/use&gt; &lt;/connection&gt; &lt;/khaosorders_setup&gt; &lt;khaosorders_write&gt; &lt;connection&gt; &lt;use&gt;core_write&lt;/use&gt; &lt;/connection&gt; &lt;/khaosorders_write&gt; &lt;khaosorders_read&gt; &lt;connection&gt; &lt;use&gt;core_read&lt;/use&gt; &lt;/connection&gt; &lt;/khaosorders_read&gt; &lt;/resources&gt; &lt;blocks&gt; &lt;khaosorders&gt; &lt;class&gt;Symphony_Khaosorders_Block&lt;/class&gt; &lt;/khaosorders&gt; &lt;/blocks&gt; &lt;helpers&gt; &lt;khaosorders&gt; &lt;class&gt;Symphony_Khaosorders_Helper&lt;/class&gt; &lt;/khaosorders&gt; &lt;/helpers&gt; &lt;/global&gt; &lt;/config&gt; </code></pre> <p>And here's my observer method:</p> <pre><code>$test = Mage::getModel('sales/order')-&gt;load($order-&gt;getId()); // write the khaos soc to the database $test-&gt;setKhaosSoc('just testing'); $test-&gt;setCustomerFirstname('Charlie'); $test-&gt;save(); </code></pre> <p>Is there something I am missing?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload