komodosp
komodosp

Reputation: 3658

How to display Custom order attribute in Magento back end

I'm using Magento 1.7 - I am fairly new to Magento module development.

I have created a new Order custom EAV attribute called Deliverydate which the customer will enter on the Shopping Cart page. I created a custom module and installer script, and can see it in the eav_attribute table.

$installer = $this;
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$setup->addAttribute('order', 'deliverydate', array(
 'position'      => 1,
 'input'         => 'text',
 'backend_type'  => 'varchar',
 'type'          => 'varchar',
 'label'         => 'Choose delivery date',
 'visible'       => 1,
 'required'      => 0,
 'user_defined' => 1,
 'global'        => 1,
 'visible_on_front'  => 1,
));

$installer->endSetup();

But I've read many sources and can't figure out how to 1) Save the value entered by the customer. 2) Retrieve the value for display in the Admin.

I have read on these tutorials about Observers but can't seem to get one to work:

Here's my config.xml file

<?xml version="1.0"?>
<config>
  <modules>
    <Mycompany_Deliverydate>
      <version>0.1.0</version>
    </Mycompany_Deliverydate>
  </modules>
  <global>
<resources>
  <deliverydate_setup>
    <setup>
      <module>Mycompany_Deliverydate</module>
      <class>Mycompany_Deliverydate_Model_Resource_Mysql4_Setup</class>
    </setup>
    <connection>
      <use>core_setup</use>
        </connection>
      </deliverydate_setup>
    </resources>
    <events>
    <checkout_type_onepage_save_order>
        <observers>
            <Deliverydate_observer>
                <type>singleton</type>
                <class>deliverydate/observer</class>
                <method>Deliverydate</method>
            </Deliverydate_observer>
        </observers>
    </checkout_type_onepage_save_order>
     </events>
   </global>
</config>

And my Observer.php file, most of which I borrowed from another tutorial / question on this site.

class Mycompany_Deliverydate_Model_Observer {
  public function Deliverydate($observer) {

    $event = $observer->getEvent();
    $order = $event->getOrder();

    $order->setDeliverydate(Mage::app()->getRequest()->getPost('delivery_date'));


  }
}

I don't think this is being entered at all - I put in a throw new Exception and went through an entire order without ever seeing the exception. In any case I am not sure I'm checking the right event - checkout_type_onepage_save_order - when is this fired? And I don't know where the setDeliverydate() function would be defined but as I said this sort of comes from another source and it wasn't defined there either.

And where does the value entered get stored?

Upvotes: 0

Views: 4005

Answers (1)

DRAJI
DRAJI

Reputation: 1869

Please check this following post, It would help you. If it doesn't uplift you from this issue, please comment here

http://chillydraji.wordpress.com/2014/03/03/how-to-create-new-attribute-to-order-in-magento/

Upvotes: 1

Related Questions