4

I'm working with Magento version 1.4.1.1, and I want to save a value in sales_flat_quote_item table (and pass it to sales_flat_order_item).

I've found this tutorial, but I'm not sure if it's still relevant (to Magento version 1.4.1.1) since it talks about a table called sales_order, which I believe is now sales_flat_order and looks a bit different.

Should this method still work? If so - Can I use it for sales_flat_quote_item and sales_flat_order_item and what entity_type_id should I put in the commend :

`insert into eav_attribute('entity_type_id','attribute_code','attribute_model','backend_model','backend_type','backend_table','frontend_model','frontend_input','frontend_input_renderer','frontend_label','frontend_class','source_model','is_global','is_visible','is_required','is_user_defined','default_value','is_searchable','is_filterable','is_comparable','is_visible_on_front','is_html_allowed_on_front','is_unique','is_used_for_price_rules','is_filterable_in_search','used_in_product_listing','used_for_sort_by','is_configurable','apply_to','position','note','is_visible_in_advanced_search'  )  
values(11, 'my_new_column', null, '', 'static', '', '', 'text', '','',null, '', 1,1,1,0,'',0,0,0,0,0,0,1,0,0,0,1,'',0,'',0);`

If this is not the way to do that in the new Magento version, how should I do that?

Thanks, Shani

Joe Mastey
  • 26,809
  • 13
  • 80
  • 104
Shani1351
  • 509
  • 4
  • 10
  • 25

2 Answers2

12
  1. Create a new module with own setup class extended from Mage_Sales_Model_Mysql4_Setup or just use it as module setup class in config.xml:

     <global>
         <resources>
             <your_module_setup>
                  <setup>
                      <module>Your_Module</module>
                      <class>Mage_Sales_Model_Mysql4_Setup</class>
                  </setup>
             </your_module_setup>
         </resources>
     </global>
    
  2. Use addAttribute($entity, $attributeCode, $options) method inside of your setup script, it will automatically add a new column to sales_flat_order tale. The same for other entites.

    $installer = $this;
    $installer->startSetup();
    $installer->addAttribute(
        'order', 
        'your_attribute_code', 
        array(
            'type' => 'int', /* varchar, text, decimal, datetime */,
            'grid' => false /* or true if you wan't use this attribute on orders grid page */
        )
    );
    $installer->endSetup();
    
Ivan Chepurnyi
  • 9,233
  • 1
  • 43
  • 43
  • Thanks for your reply. As I said - I want to add the column to sales_flat_quote_item and sales_flat_order_item (item, not sales_flat_order). Does it still work the same? – Shani1351 Dec 08 '10 at 09:59
  • @Shani1351 It works the same, just specify `order_item` and `quote_item` instead of `order` in first argument. `order` was used as an example. – Ivan Chepurnyi Dec 08 '10 at 10:24
  • 3
    Thanks Ivan - as a note for future reference, the key point in this answer is to use `Mage_Sales_Model_Mysql4_Setup`, not the standard `Mage_Eav_Model_Entity_Setup`. The `Mage_Sales_Model_Mysql4_Setup` method will intercept `addAttribute` for the `order_item` and `quote_item` objects which don't have formal `entity_type_id` values that the standard Setup class looks for. – Jonathan Day Dec 22 '10 at 22:59
  • thank ivan, there is an typo at 'datetime */,' comma after comment closed , – anshuman Jun 09 '12 at 14:50
  • I have also added a new custom attribute to `order_item` and `quote_item`. How do you set a value and save an order item in code? – A.W. Jan 15 '13 at 11:11
  • @Guus little late but hope it helps: you just use the Setters/Getters of Magento (camelcased). So if your attribute is called "mycustomattribute" you do $order->setMycustomattribute($value) – Barbarossa Aug 07 '13 at 13:30
4

important thing to know when adding attributes to orders: you need to add the same attributes to quotes, too (at least in my case this solved all problems)

Barbarossa
  • 808
  • 12
  • 24