3

I have created a custom field from sales_flat_quote & sales_flat_order tables and in checkout page have field called delivery_date. When an order is being placed, it's not saving my custom field value.

My code is:

etc/modules/Easylife_Ats.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Ats>
            <active>true</active>
            <codePool>local</codePool>
        </Easylife_Ats>
    </modules>
</config>

Ats/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Ats>
            <version>0.1.0</version>
        </Easylife_Ats>
    </modules>
    <global>
        <models>
            <ats>
                <class>Easylife_Ats_Model</class>
                <resourceModel>ats_resource</resourceModel>
            </ats>
            <ats_resource>
                <class>Easylife_Ats_Model_Resource</class>
            </ats_resource>
        </models>
        <blocks>
            <ats>
                <class>Easylife_Ats_Block</class>
            </ats>
        </blocks>
        <helpers>
            <ats>
                <class>Easylife_Ats_Helper</class>
            </ats>
        </helpers>
        <resources>
            <ats_setup>
                <setup>
                    <module>Easylife_Ats</module>
                </setup>
            </ats_setup>
        </resources>
        <events>
          <checkout_type_onepage_save_order>
                <observers>
                    <ats>
                        <type>singleton</type>
                        <class>ats/observer</class>
                        <method>saveCustomData</method>
                    </ats>
                </observers>
            </checkout_type_onepage_save_order>

        </events>
    </global>
</config>

Ats/Model/Observer.php

<?php

class Easylife_Ats_Model_Observer
{

    public function saveCustomData(Varien_Event $observer)
    {
        $event = $observer->getEvent();
        $order = $event->getOrder();
        $fieldVal = Mage::app()->getFrontController()->getRequest()->getParams();
        Mage::log($fieldVal);
        $order->setDeliveryDate($fieldVal['delivery_date']);
    }
}

Ats/sql/ats_setup/installer-0.1.0.php

<?php

/* @var $installer Mage_Core_Model_Resource_Setup */
require_once('app/Mage.php');

$installer = $this;

$installer->startSetup();

Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Resource_Setup('core_setup');

$attribute  = array(
    'type' => 'varchar',
    'backend_type' => 'varchar',
    'frontend_input' => 'varchar',
    'is_user_defined' => true,
    'label' => 'Delivery Date',
    'visible' => true,
    'required' => false,
    'user_defined' => false,
    'default' => '0',
    'comparable' => false,
    'searchable' => false,
    'filterable' => false
);

$installer->addAttribute('order','delivery_date',$attribute);
$installer->addAttribute('quote','delivery_date',$attribute);

$installer->endSetup();

design\frontend\base\default\template\checkout\onepage\shipping_method.phtml

<div id="onepage-checkout-shipping-method-additional-load">
        <?php echo $this->getChildHtml('additional') ?>
    </div>
    <div>
        <input id="delivery_date" name="delivery_date" value="" class="input-text" type="text">

design\adminhtml\default\default\template\sales\order\view\info.phtml

<?php if($_order->getDeliveryDate()): ?>
                    <tr>
                        <td class="label"><label><?php echo Mage::helper('sales')->__('Delivery Date') ?></label></td>
                        <td class="value"><strong><?php echo $_order->getDeliveryDate(); ?></strong></td>
                    </tr>
                <?php endif; ?>

Can you tell me where I went wrong?

  • Do you see the column delivery_date in the tables sales_flat_quote and sales_flat_order? If so, try clearing the cache. Even if the cache is disabled the table schema cache still exists. – Marius Jun 12 '14 at 6:39
  • @Marius, Yah! created. I seen. – Manoj Kumar Jun 12 '14 at 6:42
  • @Marius, not saving value even I cleared cache. – Manoj Kumar Jun 12 '14 at 6:49
  • @Marius, Any suggestions. – Manoj Kumar Jun 12 '14 at 7:36
  • Not for now. Sorry. – Marius Jun 12 '14 at 7:42
3

You need to add the attribute to the quote to order service model configuration:

<global>
    <fieldsets>
        <sales_convert_quote>
            <delivery_date>
                <to_order>*</to_order>
            </delivery_date>
        </sales_convert_quote>
    </fieldsets>
</global>
0

Change your function code

public function saveCustomData(Varien_Event $observer)
{
    $event = $observer->getEvent();
    $order = $event->getOrder();
    $fieldValobj = Mage::app()->getFrontController()->getRequest();
    if($fieldValobj)
    {
        $fieldVal = $fieldValobj->getParams();
    }
    Mage::log($fieldVal);
    $order->setDeliveryDate($fieldVal['delivery_date']);
}

otherwise it will give Fatal Error

  • I don't think this is needed. One can be quite sure, that a request object exists – Fabian Blechschmidt Jun 1 '15 at 12:47

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.