1
votes

I've been having trouble with this for a few days, essentially I need to add a custom organisation_id attribute (that I have created via an installer script) to be added to both the customer object and order object at the end of the onepage checkout.

The installer script works fine (I can see the values within the eav_attribute and core_resources table in the database.

During the checkout phase on the final 'Order Review' section, once the Place Order button is clicked this executes the following observer:

sales_order_place_after

Once this has been executed it runs the following function within an Observer:

public function afterOrderPlaced($observer)
{
    // this id below comes from a select dropdown within the checkout onepage & already saved to session
    $organisation_id = Mage::getSingleton('customer/session')->getCustomerOrganisationId();

    $this->_order = $observer->getEvent()->getOrder();
    $this->_order->setOrganisationId($organisation_id)->save(); // e.g 25621

    // Customer stuff
    $this->_customer_id = $this->_order->getCustomerId();
    $this->_customer = $this->_order->getCustomer();
    $this->_customer->setOrganisationId($organisation_id)->save(); // e.g 25621
}

In this instance, I simply want to set the organisationId value on both the customer and order objects to '25621'.

Once I have completed the checkout process and hit the 'order confirmation' page I'd like to be able to confirm this organisation_id has indeed been correctly added to the customer and order object, can anyone confirm the easiest/best way to do this? I presume this will need to include some modification to the admin html for Sales to include this information as well.

Please note - My Magento skillset is rather limited

My Installer Script below:

$installer = new Mage_Eav_Model_Entity_Setup();
$installer->startSetup();

$installer = new Mage_Eav_Model_Entity_Setup();
$installer->startSetup();

$installer->addAttribute('customer', 'organisation_id', array(
    'input'         => 'select', //or select or whatever you like
    'type'          => 'int', //or varchar or anything you want it
    'label'         => 'Organisation ID',
    'visible'       => 1,
    'required'      => 0, //mandatory? then 1
    'user_defined'  => 1,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));

$installer->addAttribute('quote', 'organisation_id', array(
    'input'         => 'select', //or select or whatever you like
    'type'          => 'int', //or varchar or anything you want it
    'label'         => 'Organisation ID',
    'visible'       => 1,
    'required'      => 0, //mandatory? then 1
    'user_defined'  => 1,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));

$installer->addAttribute('order', 'organisation_id', array(
    'input'         => 'select', //or select or whatever you like
    'type'          => 'int', //or varchar or anything you want it
    'label'         => 'Organisation ID',
    'visible'       => 1,
    'required'      => 0, //mandatory? then 1
    'user_defined'  => 1,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));

$installer->endSetup();
1
The approach with the fieldset conversion could be used here, too. See my answer here: stackoverflow.com/a/19892930/2455224Simon H
You are missing the attribute for quote and order. They are separate entities. Add them with $installer->addAttribute('quote','organisation_id', array(...); and $installer->addAttribute('order', 'organisation_id' array(...);. The table columns should be created automatically.Simon H
@SimonH - i have changed my script, would this appear correct?Zabs
I've tried my new installer script and get a Wrong entity ID error? Any ideas?Zabs

1 Answers

1
votes

You can check your custom value in your database sales_flat_order_address table and sales_flat_quote_address table .

Let me know if you have any query