1

I have this in config.xml

<global>
    <events>
        <sales_quote_save_after>
            <observers>
                <save_after>
                    <type>singleton</type>
                    <class>Practice_Payment_Model_Observer</class>
                    <method>saveQuoteAfter</method>
                </save_after>
            </observers>
        </sales_quote_save_after>
        .
        .

And my Observer.php

public function saveQuoteAfter($evt){
    $quote = $evt->getQuote();

    // $post variable is checkbox in the Billing Information
    $post = Mage::app()->getFrontController()->getRequest()->getPost();

    if(isset($post['custom']['consultancyservice'])){
        $var = $post['custom']['consultancyservice'];
        $quote->setConsultancyservice($var);
    } else {
        $var = 'false';
        $quote->setConsultancyservice($var);
    }
    $model = Mage::getModel('custom/custom_quote');
    $model->deteleByQuote($quote->getId(),'consultancyservice');
    $model->setQuoteId($quote->getId());
    $model->setKey('consultancyservice');
    $model->setValue($var);
    $model->save();
}

$post is variable is checkbox in the Billing Information

This updates the value in the database. But whenever I go beyond 'Billing Information' it resets. Maybe because sales_quote_save_after runs at all steps in the checkout?

I have also tried controller_action_predispatch_checkout_onepage_savebilling and controller_action_postdispatch_checkout_onepage_savebilling but they are not working.

Thanks to anyone who can help!!

1
  • Each step in the checkout has a variable indicating the step (not able to check the name at the moment). Filter the event based upon that variable. Also the reason why your event should be in the frontend space only. In the admin this will be different.
    – user4351
    Oct 9 '14 at 6:57
1

Hi instead of using sales_quote_save_after use

sales_quote_address_save_after or sales_quote_address_save_before

and youobserver code is wroong

public function saveQuoteAfter($observer){
    /* change here */
$addressObject=$observer->getEvent()->getQuoteAddress();


    $quote = $observer->getEvent()->getQuoteAddress()->getQuote();

    // $post variable is checkbox in the Billing Information
    $post = Mage::app()->getFrontController()->getRequest()->getPost();

    if(isset($post['custom']['consultancyservice'])){
        $var = $post['custom']['consultancyservice'];
        $quote->setConsultancyservice($var);
    } else {
        $var = 'false';
        $quote->setConsultancyservice($var);
    }
    $model = Mage::getModel('custom/custom_quote');
    $model->deteleByQuote($quote->getId(),'consultancyservice');
    $model->setQuoteId($quote->getId());
    $model->setKey('consultancyservice');
    $model->setValue($var);
    $model->save();
}
2
  • Both are giving this error: Call to a member function functionnamehere() on a non-object Oct 9 '14 at 6:13
  • 1
    Hi, thanks for the reply. It works sales_quote_save_after because it updates the value after Billing Information, but resets back to 'false' once I move on.. Oct 9 '14 at 6:52

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.