0

I added two custom attributes in the order and quote table.

One is delivery_date : the delivery timeslot chosen by the user. The other is additionnal_information

The two rows are created but only one of them (delivery_date) is filled when an order is submitted. The other is NULL

If I try this in the observer : mage::log($order->getAdditionnalInformation()), it returns something

Does someone knows why ?

My install script :

<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute("order", "delivery_date", array("type"=>"varchar"));
$installer->addAttribute("quote", "delivery_date", array("type"=>"varchar"));
$installer->addAttribute("order", "additionnal_information", array("type"=>"varchar"));
$installer->addAttribute("quote", "additionnal_information", array("type"=>"varchar"));
$installer->endSetup();

My config file (only the global part) :

<global>
    <events>
        <sales_quote_save_before>
            <observers>
                <save_before>
                    <type>singleton</type>
                    <class>CoursierPrive_Transport_Model_Observer</class>
                    <method>saveQuoteBefore</method>
                </save_before>
            </observers>
        </sales_quote_save_before>
        <checkout_type_onepage_save_order>
            <observers>
                <delivery_date_observer>
                    <type>singleton</type>
                    <class>CoursierPrive_Transport_Model_Observer</class>
                    <method>saveCustomData</method>
                </delivery_date_observer>
            </observers>
        </checkout_type_onepage_save_order>
    </events>
    <fieldsets>
        <sales_convert_quote>
            <delivery_date>
                <to_order>*</to_order>
            </delivery_date>
            <additionnal_information>
                <to_order>*</to_order>
            </additionnal_information>
        </sales_convert_quote>
        <sales_convert_order>
            <delivery_date>
                <to_quote>*</to_quote>
            </delivery_date>
            <additionnal_information>
                <to_quote>*</to_quote>
            </additionnal_information>
        </sales_convert_order>
    </fieldsets>
     <resources>
        <transport_setup>
            <setup>
                <module>CoursierPrive_Transport</module>
                <class>Mage_Sales_Model_Resource_Setup</class>
            </setup>
        </transport_setup>
    </resources>
</global>

And my observer :

<?php
class CoursierPrive_Transport_Model_Observer
{
    public function saveCustomData($observer)
    {
        $event = $observer->getEvent();
        $order = $event->getOrder();
        $timestamp = Mage::getSingleton('core/session')->getData('delivery_date');
        $additionnalInformation = Mage::getSingleton('core/session')->getData('additionnal_information');
        $order->setAdditionnalInformation($additionnalInformation);
        $order->setDeliveryDate($timestamp);
    }

    public function saveQuoteBefore($observer)
    {
        $post = Mage::app()->getFrontController()->getRequest()->getPost();

        if(isset($post['field']['delivery_date']))
        {
            $var = $post['field']['delivery_date'];
            Mage::getSingleton('core/session')->setData('delivery_date', $var);
        }
        if(isset($post['field']['additionnal_information']))
        {
            $var = $post['field']['additionnal_information'];
            Mage::getSingleton('core/session')->setData('additionnal_information', $var);
        }
    }
}
?>
  • did you clear the cache? – Marius Apr 6 '16 at 14:28
  • Caches are disabled. – cdauphin Apr 6 '16 at 14:30
  • Please delete the cache. even if it's disabled, the table schema is still cached. – Marius Apr 6 '16 at 14:33
  • Oh you were right. Deleting the cache resolved my problem. Thanks you ! – cdauphin Apr 6 '16 at 14:45
0

Based on the comments.
The table schema is cached even if the cache is off.
Deleting the cache should solve the problem.

| improve this answer | |

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.