0

I'd created a custom attribute for customer and in order collection I need to show that attribute. How could I do that?

for now I'd got the order collection as

$collection = Mage::getModel('sales/order')->getCollection()
                ->addAttributeToSelect('*')
                ->addFieldToFilter('status', array('eq' => 'complete'))
                ->addAttributeToFilter('customer_group_id', $customer_group)
        ;

The attribute I'd created is coachid which need to displayed in this collection. Anyone could help?

  • Could you perhaps provide the information on how you created the custom attribute as i'm having a similar problem to yourself thanks Mohammed – Zabs May 8 '14 at 11:50
  • @Zabs: see this blog – Mohammad Faisal May 8 '14 at 13:36
2

I think the best approach is to "copy" the customer field to the order object, because the data might change or the customer can be deleted, but the order info must remain.

For this, add the field coachid to the quote and order tables but prefix it with customer_.

Here is an update script you can use:

$this->run("ALTER TABLE `{$this->getTable('sales/quote')}` ADD COLUMN `customer_coachid` VARCHAR(255) NOT NULL DEFAULT ''");
$this->run("ALTER TABLE `{$this->getTable('sales/order')}` ADD COLUMN `customer_coachid` VARCHAR(255) NOT NULL DEFAULT ''");

Then, tell magento to copy this attribute to the quote and the order.
Add this in the config.xml of one of your modules inside the <global> tag.

<fieldsets>
    <customer_account>
        <coachid>
            <to_quote>customer_coachid</to_quote>
        </coachid>
    </customer_account>
    <sales_convert_quote>
        <customer_coachid>
             <to_order>*</to_order>
        </customer_coachid>
    </sales_convert_quote>
</fieldsets>

Clear the cache.

As a positive side effect you will see the value of this field in the admin order view screen through the magic of Mage_Adminhtml_Block_Sales_Order_View_Info::getCustomerAccountData.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.