1
votes

I have created an custom attribute using the Magento installer script below:

$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->endSetup();

On the onepage checkout screen I have a dropdown where a customer selects an organisation from a dropdown menu - once they click the 'Continue' button it posts an ajax request and goes to the next step 'Billing' e.g the post request looks like this..

org[organisation_id] - 12345
org[name] - ACME Inc

My function that deals with this is follows - can anyone assist how to add this to the customer & order object?

public function saveOrgAction()
{
    if ($this->_expireAjax()) {
        return;
    }
    if ($this->getRequest()->isPost()) {
        $data = $this->getRequest()->getPost('org', array());

        // todo:hook up saving the org id passed here to customer & order object

        // UPDATE... I believe this is correct?
        $customer = Mage::getSingleton('customer/session')->getCustomer(); // get customer object
        $customer->setOrganisationId($org_id)->save();

        if (!isset($result['error'])) {
            $result['goto_section'] = 'billing';
        }

        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }
}

What is the best way to add this 'organisation_id' attribute to the customer object (note I am using Magento 1.7.2)

1
Follow this link it may help you indiestechtips.wordpress.com/2011/07/30/…Keyur Shah
I have made an edit with something I believe may workZabs

1 Answers

2
votes
$customer->setOrganisationId('123')->save();

if you need it in the order you have to set it in the current quote object via

$quote->setOrganisationId('123');

and use this explanation to push the attribute automatically through quote to order conversion. But dont forget to create the correct labled column in sales_flat_order!

explanation how to push any attribute automatically through quote to order conversion