views:

428

answers:

4

Hi-

I created a simple custom attribute on the sales/order entity. Now, for new orders, order number is null. I looked at the sales_order table, and sure enough, increment_id is null... can anyone help me out, I am stumped?

This is my setup.php:

`public function getDefaultEntities() {

     return array(
         'order' => array(
             'entity_model'      => 'sales/order',
            //'attribute_model'   => 'catalog/resource_eav_attribute',
             'table'             => 'sales/order',
             'attributes'        => array(
             'pr_email_sent'     => array(
                    'label'             => 'prEmailSent',
                     'type'              => 'varchar',
                     'default'           => 'false'
                 ),

            )
        )
   );

}`

This is my config.xml

<fieldsets>
             <sales_order>
                 <pr_email_sent><create>1</create><update>1</update></pr_email_sent>
             </sales_order>
         </fieldsets>

Thanks.

A: 

Has your new attribute been created successfully? You can check the eav_attribute table to see if your attribute is listed.

Chris Norton
Hey, thanks for the response. Yes, the attribute successfully makes it to the eav_attribute table. I can getData() and setData() on it as well... its just that the order numbers are null now. Maybe I need to set some more properties on setup.php? this is very confusing.
frank
A: 

I solved this by scrapping my setup.php file, and in my mysql4-install-0.1.0.php did the following:

<?php

// file mysql4-install-0.1.0.php


$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('sales_setup');
$installer->startSetup();

$setup->addAttribute('order', 'pr_email_sent', array('type'    => 'text',
                                                     'default' => 'false'
                                                    )
                    );

$installer->endSetup();

?>

Works like a charm now. Not sure what the difference is, besides the obvious... The lack of documentation in Magento is pretty uninspiring.

frank
A: 

Just ran into this myself and managed to figure it out. By using a getDefaultEntities function, we end up overriding the increment_model attribute for sales_order in the eav_entity_type table.

Seems to over-write the increment_model and increment_per_store fields.

Glad to see you got it figured out using the above. I'll be using that myself :-)

BTW, will be submitting this to Magento's bug tracker.

David
A: 

I don't believe that this is a bug. I ran into the same exact issue myself a while back. The problem lies in that you are not including all the necessary information in getDefaultEntities(). The way you ended up doing it works, but isn't the best way to do it. You were just lacking a few parts of setting up the order array. This is how it should look:

public function getDefaultEntities()
{
    return array(
        'order' => array(
            'entity_model' => 'sales/order',
            'table' => 'sales/order',
            'increment_model' => 'eav/entity_increment_numeric',
            'increment_per_store' => true,
            'backend_prefix' => 'sales_entity/order_attribute_backend',
            'attributes' => array(
                'pr_email_sent' => array(
                    'label' => 'prEmailSent',
                    'type' => 'varchar',
                    'default' => 'false'
                )
            )
        )
    );
}
Prattski