0

I have created a custom module to add a custom column to sales_flat_quote and sales_flat_order. I have been successful in creating the columns in the database. The problem is the module also has a observer for event controller_action_predispatch_checkout_onepage_index, but when the event is triggered i get 500 error message, and no error details is displayed.

/app/code/local/JestaSoft/AddTripId/etc/config.xml

<?xml version="1.0"?>
<config>
        <modules>
            <JestaSoft_AddTripId>
                    <version>0.1.0</version>
            </JestaSoft_AddTripId>
        </modules>
    <global>
            <resources>
                    <jestasoft_addtripid_setup>
                        <setup>
                                <module>JestaSoft_AddTripId</module>
                        </setup>
                        <connection>
                                <use>core_setup</use>
                        </connection>
                    </jestasoft_addtripid_setup>
            </resources>
            <fieldsets>
                <sales_convert_quote>
                    <trip_id>
                            <to_order>*</to_order>
                        </trip_id>
                </sales_convert_quote>

                <sales_convert_order>
                        <trip_id>
                            <to_order>*</to_order>
                        </trip_id>
                </sales_convert_order>
        </fieldsets>

            <events>
                <controller_action_predispatch_checkout_onepage_index>
                        <observers>
                            <jestasoft_addtripid>
                                    <class>JestaSoft_AddTripId_Model_Observer</class>
                                    <method>addTripId</method>
                            </jestasoft_addtripid>
                        </observers>
                </controller_action_predispatch_checkout_onepage_index>
            </events>
    </global>
</config>

/app/code/local/JestaSoft/Model/Observer.php

<?php

public function addTripId(Varien_Event_Observer $observer) {
    $item = $observer->getQuote();
    $tripId = Mage::getSingleton('checkout/session')->getNTripId();
    $item->setTripId($tripId);
    $item->save();
    return $this;
}
?>
1
  • Could you check your server error log, the error should be there ;) Commented Apr 21, 2016 at 13:04

2 Answers 2

0

Your observer should be as below:

<?php
class JestaSoft_AddTripId_Model_Observer
{
  public function addTripId(Varien_Event_Observer $observer) {
    $item = $observer->getQuote();
    $tripId = Mage::getSingleton('checkout/session')->getNTripId();
    $item->setTripId($tripId);
    $item->save();
    return $this;
  }
}
?>
2
  • Looking through error logs, previously I was getting unexpected public. After making the changes, I am getting setTripId() on null. How do I get the current quote object in the observer. Commented Apr 21, 2016 at 13:18
  • I have tried getQuote and also getQuoteItem both seem to return null Commented Apr 21, 2016 at 13:23
0

controller_action_predispatch_checkout_onepage_index does *not give you Quote object.So ,you need to get Quote object from session Mage::getSingleton('checkout/session')->getQuote() and set value at Quote

Also,your observer(Observer.php) file should be located at JestaSoft/AddTripId/Model/ So,your observer should be:

<?php
class JestaSoft_AddTripId_Model_Observer{
public function addTripId(Varien_Event_Observer $observer) {
    $Quote = Mage::getSingleton('checkout/session')->getQuote();
    $tripId = Mage::getSingleton('checkout/session')->getNTripId();
    $Quote->setTripId($tripId);
    $Quote->save();
    return $this;
}
}
?>
0

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.