0

I want to add a custom attribute which i have already created to the order page in the back end. I have used this in my config.xml file to add the attribute to the customer account page, but I want to access the same field from the Order page.

<?xml version="1.0"?>
<config>
    <modules>
        <Shailendra_CustomField>
            <version>0.1.0</version>
        </Shailendra_CustomField>
    </modules>
    <frontend>
        <routers>
            <customfield>
                <use>standard</use>
                <args>
                    <module>Shailendra_CustomField</module>
                    <frontName>customfield</frontName>
                </args>
            </customfield>
        </routers>
        <layout>
            <updates>
                <customfield>
                    <file>customfield.xml</file>
                </customfield>
            </updates>
        </layout>
    </frontend>
    <admin>
        <routers>
            <customfield>
                <use>admin</use>
                <args>
                    <module>Shailendra_CustomField</module>
                    <frontName>customfield</frontName>
                </args>
            </customfield>
        </routers>
    </admin>
    <global>
     <fieldsets>
        <customer_account>
            <occupation>
                <to_quote>occupation</to_quote>
            </occupation>
        </customer_account>       
      </fieldsets>
    </global>
    <global>
        <fieldsets>
            <customer_account>
                 <occupation><create>1</create><update>1</update><name>1</name></occupation>
            </customer_account>
        </fieldsets>
    </global>
    <global>
        <resources>
            <customfield_setup>
                <setup>
                    <module>Shailendra_CustomField</module>
                    <class>Mage_Customer_Model_Entity_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </customfield_setup>
            <customfield_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </customfield_write>
            <customfield_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </customfield_read>
        </resources>
    </global>
</config>

Would i have to just add something to this config file. If so what would i have to add.

0

Assuming that you want to add my_custom_input_field to your order and add a field to your admin create order page (to add the field to the frontend you just need to add the input field to the front template and double check the observer)

In /app/code/local/MageIgniter/CustomOrderStatus/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <MageIgniter_CustomOrderStatus>
            <version>1.1</version>
        </MageIgniter_CustomOrderStatus>
    </modules>

    <global> 
         <fieldsets>
            <sales_convert_quote>                           
                <my_custom_input_field><to_order>*</to_order></my_custom_input_field>
            </sales_convert_quote>

            <sales_convert_order>                                              
                <my_custom_input_field><to_quote>*</to_quote></my_custom_input_field>
            </sales_convert_order>
        </fieldsets>
        <helpers>
            <customorderstatus>
                <class>MageIgniter_CustomOrderStatus_Helper</class>
            </customorderstatus>            
        </helpers>

        <models>
            <customorderstatus>
                <class>MageIgniter_CustomOrderStatus_Model</class>
                <resourceModel>customorderstatus_mysql4</resourceModel>
            </customorderstatus>
        </models>
        <resources>
            <customorderstatus_setup>
                <setup>
                    <module>MageIgniter_CustomOrderStatus</module>
                    <class>Mage_Sales_Model_Mysql4_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </customorderstatus_setup>
            <customorderstatus_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </customorderstatus_write>
            <customorderstatus_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </customorderstatus_read>
        </resources>

        <events>
            <adminhtml_sales_order_create_process_data_before>
                <observers>
                    <customorderstatus>
                        <type>singleton</type>
                        <class>customorderstatus/observer</class>
                        <method>saveCustomData</method>
                    </customorderstatus>
                </observers>
            </adminhtml_sales_order_create_process_data_before>
        </events>

        <blocks>
            <customorderstatus>
                <class>MageIgniter_CustomOrderStatus_Block</class>
            </customorderstatus>
        </blocks>
    </global>
</config>

In /app/code/local/MageIgniter/CustomOrderStatus/sql/customorderstatus_setup/mysql4-install-1.1.php

<?php
$installer = $this;
$installer->startSetup();

$installer->addAttribute("order", "my_custom_input_field", array("type"=>"varchar"));
$installer->addAttribute("quote", "my_custom_input_field", array("type"=>"varchar"));
$installer->endSetup();

In /app/code/local/MageIgniter/CustomOrderStatus/Model/Observer.php

class MageIgniter_CustomOrderStatus_Model_Observer 
{
    public function saveCustomData($event)
    {
        $quote = $event->getSession()->getQuote();
        $quote->setData('my_custom_input_field', $event->getRequestModel()->getPost('my_custom_input_field'));

        return $this;
    }
}

(You should avoid make changes to core default - you should do some research on way around this)

In /app/design/adminhtml/default/default/template/sales/order/view/info.phtml

<?php if($_order->getMyCustomInputField()): ?>
<tr>
    <td class="label"><label><?php echo Mage::helper('sales')->__('My Custom Input Field') ?></label></td>
    <td class="value"><strong><?php echo $_order->getMyCustomInputField() ?></strong></td>
</tr>
<?php endif; ?>

In /app/design/adminhtml/default/default/template/sales/order/create/form/account.phtml

(to add to frontend change the value="<?php echo Mage...>")

<input id="my_custom_input_field" name="my_custom_input_field" value="<?php echo Mage::getSingleton('adminhtml/session_quote')->getQuote()->getMyCustomInputField() ?>" class="input-text" type="text">
  • But i have already created the field as it is in my customer account page. I just want to get drag the information that is stored in the account into the order – Adam Allen Oct 1 '15 at 11:49
  • you can get help from this code. look below of this line : "(You should avoid make changes to core default - you should do some research on way around this)" – Arunendra Oct 1 '15 at 11:54
  • Thank you i ahve tried to modify it to suite my needs and came up with this : <?php $acc = $this->getCustomerAccountData(accref);?> As my field in the Account data is called accref then i can juest echo $acc. but it doesnt work. – Adam Allen Oct 1 '15 at 12:06
  • Change from <?php $acc = $this->getCustomerAccountData(accref);?> to <?php $acc = $this->getCustomerAccountData('accref');?> and see what happen – Arunendra Oct 1 '15 at 12:17
  • When i echo $acc it returns "Array". When i var_dump it is says "array(0) { }". – Adam Allen Oct 1 '15 at 13:06

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.