0

How can I create new order attribut using install script? All my attempts failed and I don't know how to do this. No one custom order attribute doesn't added to eav_attribute teble. Help me pls)

1 Answer 1

0

Here's an example one I've used on a client site before. This adds a simple quote & order attribute that gets populated by the customer in the frontend and then transferred over from the quote to the order (see the etc/config.xml example underneath for that part)

The install script:

<?php
/* @var $installer Mage_Core_Model_Resource_Setup */
$installer = $this;

$installer->startSetup();
$installer->addAttribute(
    'order',
    'my_custom_attribute',
    [
        'type'          => 'varchar',
        'label'         => 'My Custom Attribute',
        'source'        => '',
        'backend'       => '',
        'frontend'      => '',
        'visible'       => true,
        'required'      => false,
        'visible_on_front' => true,
        'user_defined'  =>  true
    ]
);
$installer->addAttribute(
    'quote',
    'my_custom_attribute',
    [
        'type'          => 'varchar',
        'label'         => 'My Custom Attribute',
        'source'        => '',
        'backend'       => '',
        'frontend'      => '',
        'visible'       => true,
        'required'      => false,
        'visible_on_front' => true,
        'user_defined'  =>  true
    ]
);

$installer->endSetup();

The XML that converts quote attribute to order attribute:

<config>
    ....
    <global>
        ....
        <fieldsets>
            <sales_convert_quote>
                <my_custom_attribute><to_order>*</to_order></my_custom_attribute>
            </sales_convert_quote>

            <sales_convert_order>
                <my_custom_attribute><to_quote>*</to_quote></my_custom_attribute>
            </sales_convert_order>
        </fieldsets>
        ....
    </global>
    ....
</config>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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