0

I am using Below code for add custom filed in checkout page it's working fine i want to call in backend how to achieve this. Follow this Link

config.xml

<setup>
    <module>Excellence_Address</module>
    <class>Mage_Customer_Model_Resource_Setup</class>
</setup>

sql

$entityTypeId = $setup->getEntityTypeId('customer_address');
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

//this is for creating a new attribute for customer address entity
$setup->addAttribute("customer_address", "delivery_instruction", array(
    "type" => "varchar",
    "backend" => "",
    "label" => "Delivery Instruction",
    "input" => "text",
    "source" => "",
    "visible" => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique" => false,
    "note" => "Custom Attribute Will Be Used Show Delivery Instruction Field In Checkout Page"
));

$attribute = Mage::getSingleton("eav/config")->getAttribute("customer_address", "delivery_instruction");

$setup->addAttributeToGroup(
        $entityTypeId, $attributeSetId, $attributeGroupId, 'delivery_instruction', '999'  //sort_order
);

$used_in_forms = array();

//$used_in_forms[]="adminhtml_customer";
//$used_in_forms[]="checkout_register";
//$used_in_forms[]="customer_account_create";
$used_in_forms[] = "customer_address_edit"; //this form code is used in checkout billing/shipping address
//$used_in_forms[]="adminhtml_checkout";
$attribute->setData("used_in_forms", $used_in_forms)
        ->setData("is_used_for_customer_segment", true)
        ->setData("is_system", 0)
        ->setData("is_user_defined", 1)
        ->setData("is_visible", 1)
        ->setData("sort_order", 100)
;
$attribute->save();

billing.phtml

<div class="field">
    <label for="billing:delivery_instruction" class="required">
        <?php echo $this->__('Delivery Instructions') ?>
    </label>
    <div class="input-box">
        <input type="text" name="billing[delivery_instruction]" id="billing:delivery_instruction" value="<?php echo $this->escapeHtml($this->getAddress()->getDeliveryInstruction()) ?>" title="<?php echo $this->__('Delivery Instructions') ?>" class="input-text required-entry" />
    </div>
</div>

sales_flat_quote_address

/**
 * Adding Extra Column to sales_flat_quote_address
 * to store the delivery instruction field
 */
$sales_quote_address = $installer->getTable('sales/quote_address');
$installer->getConnection()
        ->addColumn($sales_quote_address, 'delivery_instruction', array(
            'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
            'comment' => 'New Delivery Instruction Field Added'
        ));

/**
 * Adding Extra Column to sales_flat_order_address
 * to store the delivery instruction field
 */
$sales_order_address = $installer->getTable('sales/order_address');
$installer->getConnection()
        ->addColumn($sales_order_address, 'delivery_instruction', array(
            'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
            'comment' => 'New Delivery Instruction Field Added'
        ));

1 Answer 1

0

Your missing some code in config.xml file

<global>
   <fieldsets>
       <sales_convert_quote_address>
           <delivery_instruction>
               <to_order_address>*</to_order_address>
           </delivery_instruction>
       </sales_convert_quote_address>
   </fieldsets>
</global>

Note: Above code to copy the field value from quote address object to order address object.

When you place an order, address information should show up in both order and quote address database tables.

Also clear magento all cashe

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.