how to get value of custom attribute of customer in sales_orde_ place_after





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I have created custom EAV attribute for customer called branch which is select field customer need to select one branch which he/she belongs to and its working fine.
Note: Customer can change the branch for each order he/she placed.



I have to store it in another table when customer place order with other customer attribute, so I used sales_order_place_after observer method. I am using



$orderInfo       = $observer->getEvent()->getOrder();


Where I can get all the information about order. I am getting all the information using this code.



$customerInfo = array(
'customer_id'=> $orderInfo->getCustomerId(),
'first_name' => $orderInfo->getBillingAddress()->getFirstname(),
'last_name' => $orderInfo->getBillingAddress()->getLastname(),
'phone' => $orderInfo->getBillingAddress()->getTelephone(),
'email' => $orderInfo->getCustomerEmail(),
'address' => $orderInfo->getBillingAddress()->getData('street'),
'zip_code' => $orderInfo->getBillingAddress()->getData('postcode'),
'city' => $orderInfo->getBillingAddress()->getCity(),
'region' => $orderInfo->getBillingAddress()->getRegion()
);


But I am not able to get my custom attribute, I used many ways to get it as follows.



1. Mage::log(print_r($orderInfo->getCustomerBranch(), true));
2. Mage::log(print_r($orderInfo->getBranch(), true));
3. Mage::log(print_r($orderInfo->getBillingAddress()->getData('branch'), true));
4. Mage::log(print_r($orderInfo->getBillingAddress()->getBranch(), true));


Here is the code I used to create custom attribute



install.php code



<?php
$installer = $this;
$installer->startSetup();
$setup = Mage::getModel('customer/entity_setup', 'core_setup');
$setup->addAttribute('customer', 'branch', array(
'type' => 'varchar',
'input' => 'select',
'label' => 'Branch',
'global' => 1,
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'default' => NULL,
'visible_on_front' => 1,
'source' => 'customerbranch/entity_branch',
));
if (version_compare(Mage::getVersion(), '1.6.0', '<='))
{
$customer = Mage::getModel('customer/customer');
$attrSetId = $customer->getResource()->getEntityType()->getDefaultAttributeSetId();
$setup->addAttributeToSet('customer', $attrSetId, 'General', 'branch');
}
if (version_compare(Mage::getVersion(), '1.4.2', '>='))
{
Mage::getSingleton('eav/config')
->getAttribute('customer', 'branch')
->setData('used_in_forms', array('adminhtml_customer','customer_account_create','customer_account_edit','checkout_register'))
->save();
}
$tablequote = $this->getTable('sales/quote');
$installer->run("
ALTER TABLE $tablequote ADD `customer_branch` varchar(255) NULL
");
$installer->endSetup();


Config.xml code



<global>
<resources>
<customerbranch_setup>
<setup>
<module>Npm_CustomerBranch</module>
<class>Mage_Customer_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</customerbranch_setup>
</resources>

<fieldsets>
<customer_branch>
<branch><create>1</create><update>1</update><name>1</name></branch>
</customer_branch>
</fieldsets>
<fieldsets>
<checkout_onepage_quote>
<customer_branch>
<to_customer>branch</to_customer>
</customer_branch>
</checkout_onepage_quote>
<customer_account>
<branch>
<to_quote>customer_branch</to_quote>
</branch>
</customer_account>
</fieldsets>
<fieldsets>
<checkout_onepage_billing>
<branch>
<to_customer>*</to_customer>
</branch>
</checkout_onepage_billing>
</fieldsets>
</global>


Nothing is working.:{
How can I get my attribute value in sales_order_place_after observer method?



Thanks in advance










share|improve this question
















bumped to the homepage by Community 6 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • How have you 'created custom EAV attribute'?

    – Jonathan Hussey
    Nov 17 '14 at 15:40











  • @JonathanHussey, I will add my install.php code

    – Charlie
    Nov 17 '14 at 15:44


















0















I have created custom EAV attribute for customer called branch which is select field customer need to select one branch which he/she belongs to and its working fine.
Note: Customer can change the branch for each order he/she placed.



I have to store it in another table when customer place order with other customer attribute, so I used sales_order_place_after observer method. I am using



$orderInfo       = $observer->getEvent()->getOrder();


Where I can get all the information about order. I am getting all the information using this code.



$customerInfo = array(
'customer_id'=> $orderInfo->getCustomerId(),
'first_name' => $orderInfo->getBillingAddress()->getFirstname(),
'last_name' => $orderInfo->getBillingAddress()->getLastname(),
'phone' => $orderInfo->getBillingAddress()->getTelephone(),
'email' => $orderInfo->getCustomerEmail(),
'address' => $orderInfo->getBillingAddress()->getData('street'),
'zip_code' => $orderInfo->getBillingAddress()->getData('postcode'),
'city' => $orderInfo->getBillingAddress()->getCity(),
'region' => $orderInfo->getBillingAddress()->getRegion()
);


But I am not able to get my custom attribute, I used many ways to get it as follows.



1. Mage::log(print_r($orderInfo->getCustomerBranch(), true));
2. Mage::log(print_r($orderInfo->getBranch(), true));
3. Mage::log(print_r($orderInfo->getBillingAddress()->getData('branch'), true));
4. Mage::log(print_r($orderInfo->getBillingAddress()->getBranch(), true));


Here is the code I used to create custom attribute



install.php code



<?php
$installer = $this;
$installer->startSetup();
$setup = Mage::getModel('customer/entity_setup', 'core_setup');
$setup->addAttribute('customer', 'branch', array(
'type' => 'varchar',
'input' => 'select',
'label' => 'Branch',
'global' => 1,
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'default' => NULL,
'visible_on_front' => 1,
'source' => 'customerbranch/entity_branch',
));
if (version_compare(Mage::getVersion(), '1.6.0', '<='))
{
$customer = Mage::getModel('customer/customer');
$attrSetId = $customer->getResource()->getEntityType()->getDefaultAttributeSetId();
$setup->addAttributeToSet('customer', $attrSetId, 'General', 'branch');
}
if (version_compare(Mage::getVersion(), '1.4.2', '>='))
{
Mage::getSingleton('eav/config')
->getAttribute('customer', 'branch')
->setData('used_in_forms', array('adminhtml_customer','customer_account_create','customer_account_edit','checkout_register'))
->save();
}
$tablequote = $this->getTable('sales/quote');
$installer->run("
ALTER TABLE $tablequote ADD `customer_branch` varchar(255) NULL
");
$installer->endSetup();


Config.xml code



<global>
<resources>
<customerbranch_setup>
<setup>
<module>Npm_CustomerBranch</module>
<class>Mage_Customer_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</customerbranch_setup>
</resources>

<fieldsets>
<customer_branch>
<branch><create>1</create><update>1</update><name>1</name></branch>
</customer_branch>
</fieldsets>
<fieldsets>
<checkout_onepage_quote>
<customer_branch>
<to_customer>branch</to_customer>
</customer_branch>
</checkout_onepage_quote>
<customer_account>
<branch>
<to_quote>customer_branch</to_quote>
</branch>
</customer_account>
</fieldsets>
<fieldsets>
<checkout_onepage_billing>
<branch>
<to_customer>*</to_customer>
</branch>
</checkout_onepage_billing>
</fieldsets>
</global>


Nothing is working.:{
How can I get my attribute value in sales_order_place_after observer method?



Thanks in advance










share|improve this question
















bumped to the homepage by Community 6 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • How have you 'created custom EAV attribute'?

    – Jonathan Hussey
    Nov 17 '14 at 15:40











  • @JonathanHussey, I will add my install.php code

    – Charlie
    Nov 17 '14 at 15:44














0












0








0


1






I have created custom EAV attribute for customer called branch which is select field customer need to select one branch which he/she belongs to and its working fine.
Note: Customer can change the branch for each order he/she placed.



I have to store it in another table when customer place order with other customer attribute, so I used sales_order_place_after observer method. I am using



$orderInfo       = $observer->getEvent()->getOrder();


Where I can get all the information about order. I am getting all the information using this code.



$customerInfo = array(
'customer_id'=> $orderInfo->getCustomerId(),
'first_name' => $orderInfo->getBillingAddress()->getFirstname(),
'last_name' => $orderInfo->getBillingAddress()->getLastname(),
'phone' => $orderInfo->getBillingAddress()->getTelephone(),
'email' => $orderInfo->getCustomerEmail(),
'address' => $orderInfo->getBillingAddress()->getData('street'),
'zip_code' => $orderInfo->getBillingAddress()->getData('postcode'),
'city' => $orderInfo->getBillingAddress()->getCity(),
'region' => $orderInfo->getBillingAddress()->getRegion()
);


But I am not able to get my custom attribute, I used many ways to get it as follows.



1. Mage::log(print_r($orderInfo->getCustomerBranch(), true));
2. Mage::log(print_r($orderInfo->getBranch(), true));
3. Mage::log(print_r($orderInfo->getBillingAddress()->getData('branch'), true));
4. Mage::log(print_r($orderInfo->getBillingAddress()->getBranch(), true));


Here is the code I used to create custom attribute



install.php code



<?php
$installer = $this;
$installer->startSetup();
$setup = Mage::getModel('customer/entity_setup', 'core_setup');
$setup->addAttribute('customer', 'branch', array(
'type' => 'varchar',
'input' => 'select',
'label' => 'Branch',
'global' => 1,
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'default' => NULL,
'visible_on_front' => 1,
'source' => 'customerbranch/entity_branch',
));
if (version_compare(Mage::getVersion(), '1.6.0', '<='))
{
$customer = Mage::getModel('customer/customer');
$attrSetId = $customer->getResource()->getEntityType()->getDefaultAttributeSetId();
$setup->addAttributeToSet('customer', $attrSetId, 'General', 'branch');
}
if (version_compare(Mage::getVersion(), '1.4.2', '>='))
{
Mage::getSingleton('eav/config')
->getAttribute('customer', 'branch')
->setData('used_in_forms', array('adminhtml_customer','customer_account_create','customer_account_edit','checkout_register'))
->save();
}
$tablequote = $this->getTable('sales/quote');
$installer->run("
ALTER TABLE $tablequote ADD `customer_branch` varchar(255) NULL
");
$installer->endSetup();


Config.xml code



<global>
<resources>
<customerbranch_setup>
<setup>
<module>Npm_CustomerBranch</module>
<class>Mage_Customer_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</customerbranch_setup>
</resources>

<fieldsets>
<customer_branch>
<branch><create>1</create><update>1</update><name>1</name></branch>
</customer_branch>
</fieldsets>
<fieldsets>
<checkout_onepage_quote>
<customer_branch>
<to_customer>branch</to_customer>
</customer_branch>
</checkout_onepage_quote>
<customer_account>
<branch>
<to_quote>customer_branch</to_quote>
</branch>
</customer_account>
</fieldsets>
<fieldsets>
<checkout_onepage_billing>
<branch>
<to_customer>*</to_customer>
</branch>
</checkout_onepage_billing>
</fieldsets>
</global>


Nothing is working.:{
How can I get my attribute value in sales_order_place_after observer method?



Thanks in advance










share|improve this question
















I have created custom EAV attribute for customer called branch which is select field customer need to select one branch which he/she belongs to and its working fine.
Note: Customer can change the branch for each order he/she placed.



I have to store it in another table when customer place order with other customer attribute, so I used sales_order_place_after observer method. I am using



$orderInfo       = $observer->getEvent()->getOrder();


Where I can get all the information about order. I am getting all the information using this code.



$customerInfo = array(
'customer_id'=> $orderInfo->getCustomerId(),
'first_name' => $orderInfo->getBillingAddress()->getFirstname(),
'last_name' => $orderInfo->getBillingAddress()->getLastname(),
'phone' => $orderInfo->getBillingAddress()->getTelephone(),
'email' => $orderInfo->getCustomerEmail(),
'address' => $orderInfo->getBillingAddress()->getData('street'),
'zip_code' => $orderInfo->getBillingAddress()->getData('postcode'),
'city' => $orderInfo->getBillingAddress()->getCity(),
'region' => $orderInfo->getBillingAddress()->getRegion()
);


But I am not able to get my custom attribute, I used many ways to get it as follows.



1. Mage::log(print_r($orderInfo->getCustomerBranch(), true));
2. Mage::log(print_r($orderInfo->getBranch(), true));
3. Mage::log(print_r($orderInfo->getBillingAddress()->getData('branch'), true));
4. Mage::log(print_r($orderInfo->getBillingAddress()->getBranch(), true));


Here is the code I used to create custom attribute



install.php code



<?php
$installer = $this;
$installer->startSetup();
$setup = Mage::getModel('customer/entity_setup', 'core_setup');
$setup->addAttribute('customer', 'branch', array(
'type' => 'varchar',
'input' => 'select',
'label' => 'Branch',
'global' => 1,
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'default' => NULL,
'visible_on_front' => 1,
'source' => 'customerbranch/entity_branch',
));
if (version_compare(Mage::getVersion(), '1.6.0', '<='))
{
$customer = Mage::getModel('customer/customer');
$attrSetId = $customer->getResource()->getEntityType()->getDefaultAttributeSetId();
$setup->addAttributeToSet('customer', $attrSetId, 'General', 'branch');
}
if (version_compare(Mage::getVersion(), '1.4.2', '>='))
{
Mage::getSingleton('eav/config')
->getAttribute('customer', 'branch')
->setData('used_in_forms', array('adminhtml_customer','customer_account_create','customer_account_edit','checkout_register'))
->save();
}
$tablequote = $this->getTable('sales/quote');
$installer->run("
ALTER TABLE $tablequote ADD `customer_branch` varchar(255) NULL
");
$installer->endSetup();


Config.xml code



<global>
<resources>
<customerbranch_setup>
<setup>
<module>Npm_CustomerBranch</module>
<class>Mage_Customer_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</customerbranch_setup>
</resources>

<fieldsets>
<customer_branch>
<branch><create>1</create><update>1</update><name>1</name></branch>
</customer_branch>
</fieldsets>
<fieldsets>
<checkout_onepage_quote>
<customer_branch>
<to_customer>branch</to_customer>
</customer_branch>
</checkout_onepage_quote>
<customer_account>
<branch>
<to_quote>customer_branch</to_quote>
</branch>
</customer_account>
</fieldsets>
<fieldsets>
<checkout_onepage_billing>
<branch>
<to_customer>*</to_customer>
</branch>
</checkout_onepage_billing>
</fieldsets>
</global>


Nothing is working.:{
How can I get my attribute value in sales_order_place_after observer method?



Thanks in advance







magento-1.8 attributes customer event-observer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 8 '15 at 7:47









Marius

167k28322687




167k28322687










asked Nov 17 '14 at 15:26









CharlieCharlie

1,87652755




1,87652755





bumped to the homepage by Community 6 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 6 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • How have you 'created custom EAV attribute'?

    – Jonathan Hussey
    Nov 17 '14 at 15:40











  • @JonathanHussey, I will add my install.php code

    – Charlie
    Nov 17 '14 at 15:44



















  • How have you 'created custom EAV attribute'?

    – Jonathan Hussey
    Nov 17 '14 at 15:40











  • @JonathanHussey, I will add my install.php code

    – Charlie
    Nov 17 '14 at 15:44

















How have you 'created custom EAV attribute'?

– Jonathan Hussey
Nov 17 '14 at 15:40





How have you 'created custom EAV attribute'?

– Jonathan Hussey
Nov 17 '14 at 15:40













@JonathanHussey, I will add my install.php code

– Charlie
Nov 17 '14 at 15:44





@JonathanHussey, I will add my install.php code

– Charlie
Nov 17 '14 at 15:44










1 Answer
1






active

oldest

votes


















0














You need to add a column customer_branch on the sales_flat_quote and sales_flat_order tables.

then add this in your config.xml under the fieldsets tag.



<customer_account>
<branch>
<to_quote>customer_branch</to_quote>
</branch>
</customer_account>
<sales_convert_quote>
<customer_branch>
<to_order>*</to_order>
</customer_branch>
</sales_convert_quote>


Clear the cache.

For the next orders you whould be able to get the branch like this $orderInfo->getCustomerBranch().



As a side effect, you will see the branch value in the order view page in the admin panel, below the name and e-mail address.






share|improve this answer
























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "479"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f44361%2fhow-to-get-value-of-custom-attribute-of-customer-in-sales-orde-place-after%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You need to add a column customer_branch on the sales_flat_quote and sales_flat_order tables.

    then add this in your config.xml under the fieldsets tag.



    <customer_account>
    <branch>
    <to_quote>customer_branch</to_quote>
    </branch>
    </customer_account>
    <sales_convert_quote>
    <customer_branch>
    <to_order>*</to_order>
    </customer_branch>
    </sales_convert_quote>


    Clear the cache.

    For the next orders you whould be able to get the branch like this $orderInfo->getCustomerBranch().



    As a side effect, you will see the branch value in the order view page in the admin panel, below the name and e-mail address.






    share|improve this answer




























      0














      You need to add a column customer_branch on the sales_flat_quote and sales_flat_order tables.

      then add this in your config.xml under the fieldsets tag.



      <customer_account>
      <branch>
      <to_quote>customer_branch</to_quote>
      </branch>
      </customer_account>
      <sales_convert_quote>
      <customer_branch>
      <to_order>*</to_order>
      </customer_branch>
      </sales_convert_quote>


      Clear the cache.

      For the next orders you whould be able to get the branch like this $orderInfo->getCustomerBranch().



      As a side effect, you will see the branch value in the order view page in the admin panel, below the name and e-mail address.






      share|improve this answer


























        0












        0








        0







        You need to add a column customer_branch on the sales_flat_quote and sales_flat_order tables.

        then add this in your config.xml under the fieldsets tag.



        <customer_account>
        <branch>
        <to_quote>customer_branch</to_quote>
        </branch>
        </customer_account>
        <sales_convert_quote>
        <customer_branch>
        <to_order>*</to_order>
        </customer_branch>
        </sales_convert_quote>


        Clear the cache.

        For the next orders you whould be able to get the branch like this $orderInfo->getCustomerBranch().



        As a side effect, you will see the branch value in the order view page in the admin panel, below the name and e-mail address.






        share|improve this answer













        You need to add a column customer_branch on the sales_flat_quote and sales_flat_order tables.

        then add this in your config.xml under the fieldsets tag.



        <customer_account>
        <branch>
        <to_quote>customer_branch</to_quote>
        </branch>
        </customer_account>
        <sales_convert_quote>
        <customer_branch>
        <to_order>*</to_order>
        </customer_branch>
        </sales_convert_quote>


        Clear the cache.

        For the next orders you whould be able to get the branch like this $orderInfo->getCustomerBranch().



        As a side effect, you will see the branch value in the order view page in the admin panel, below the name and e-mail address.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 8 '15 at 7:50









        MariusMarius

        167k28322687




        167k28322687






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f44361%2fhow-to-get-value-of-custom-attribute-of-customer-in-sales-orde-place-after%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Alcázar de San Juan

            Griza ansero

            Heinkel He 51