2

I am using Magento 1.9.2 and i am working on a custom extension.

My question is: How can i run custom php function when the checkout page is opened?

I know i have to mess around with the events of the extension config file but i am not exactly sure how i can point the function in the observer which i want to run when the checkout page is opened.

Here is events part of my config:

    <events>
        <sales_order_place_before>
            <observers>
                    <class>opc/observer</class>
                    <method>checkitemsincartv</method>
            </observers>
        </sales_order_place_before>               
        <controller_action_postdispatch_opc_json_saveOrder>
            <observers>
                <hss_save_order_onepage>
                    <class>paypal/observer</class>
                    <method>setResponseAfterSaveOrder</method>
                </hss_save_order_onepage>
            </observers>
        </controller_action_postdispatch_opc_json_saveOrder>
        <sales_order_place_before>
            <observers>
            <custom_ads>
                    <class>opc/observer</class>
                    <method>checkitemsincartv</method>
            </custom_ads>
            </observers>
        </sales_order_place_before>                 
        <sales_order_place_after>
            <observers>
                <newsletter_order_place_after>
                    <class>opc/observer</class>
                    <method>newsletter</method>
                </newsletter_order_place_after>
            </observers>
        </sales_order_place_after>

         <checkout_submit_all_after>
            <observers>
                <opc_checkout_submit_all_after>
                    <class>opc/observer</class>
                    <method>applyComment</method>
                </opc_checkout_submit_all_after>
            </observers>
        </checkout_submit_all_after>

    </events>

And in the observer i have added this:

public function checkitemsincartv($observer)
{
    Mage::getSingleton('core/session')->setItemsInCart("Works");
    $data = $observer->getEvent()->getOrder();
    Mage::log($data->debug(), null, "order.log", true);
}   

But it seems to be not working.

How can i achieve that?

2
  • are you want order object at event?
    – Amit Bera
    Jul 15, 2016 at 10:11
  • The important this is this function to run before the items are cleared and the order is placed. For that reason i asked how this function can be runned when the checkout page is opened. If other method will do the trick it's ok. Thanks for the help man! Jul 15, 2016 at 10:13

1 Answer 1

3

Assume that you have default magento onepage checkout.

So you event should be

controller_action_postdispatch_checkout_onepage_index

Instead of

controller_action_postdispatch_opc_json_saveOrder

EDit:

As you have using IWD extension ,then your event may be:

controller_action_postdispatch_opc_index_index
8
  • I do not use the default checkout page. I use the onepage checkout extension by IWD. Jul 15, 2016 at 10:04
  • I have updated my question. Jul 15, 2016 at 10:05
  • let me check .. it may be different
    – Amit Bera
    Jul 15, 2016 at 10:05
  • Is it possible ? Jul 15, 2016 at 10:22
  • I have updated the config.xml in my question but still it seems that this function is not called... Jul 15, 2016 at 10:30

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.