2

Magento ver. 1.9.3.2

C:\xampp\htdocs\magento1\app\code\local\Maddy\Checkout\etc\config.xml

 <?xml version="1.0"?>
<config>
    <modules>
        <Maddy_Checkout>
            <version>0.0.1</version>
        </Maddy_Checkout>
    </modules>
    <global>
         <models>
            <maddy>
                <class>Maddy_Checkout_Model</class>                
            </maddy>
        <events>
        <sales_order_place_after>
                <observers>
                    <maddy_sendsms>
                        <class>Maddy_Checkout_Model_Observer</class>
                        <method>orderSms</method>
                        <type>singleton</type>
                    </maddy_sendsms>
                </observers>
        </sales_order_place_after>
        </events>
    </global>
</config>

C:\xampp\htdocs\magento1\app\code\local\Maddy\Checkout\Model\Observer.php

  <?php
class Maddy_Checkout_Model_Observer
{
    public function orderSms(Varien_Event_Observer $observer)
    {
        $incrementId = $observer->getEvent()->getOrder()->getIncrementId();
        $custName    = $observer->getEvent()->getOrder()->getCustomerFirstname();
        $orderPrice  = $observer->getEvent()->getOrder()->getGrandTotal();
        $orderId     = $observer->getEvent()->getOrder()->getId();
        $order       = $observer->getEvent()->getOrder()
        $mobile      = trim($order->getShippingAddress()->getData('telephone'));
        echo "I am here";
        die;
        /* I will write sms api here  */
        echo "Mobile" . $mobile;
        echo "<script>alert('Just to check')</script>";

    }
}

C:\xampp\htdocs\magento1\app\etc\modules\Maddy_Checkout.xml

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

When order is placed no alert is shown.

UPDATE:
if I use event based trigger I am not able to do add to cart. If I delete this module g then add cart is working.There is no log for this.

UPDATE:1.1

After creating some observers i am came to know that never echo any thing directly in observers , even dump in log to see the output. It will not break the functionality than.

2 Answers 2

4

Try below code

app/etc/Modules/Maddy_Checkout.xml

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

app/code/local/Maddy/Checkout/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Maddy_Checkout>
            <version>0.0.1</version>
        </Maddy_Checkout>
    </modules>
    <global>
         <models>
            <maddy>
                <class>Maddy_Checkout_Model</class>                
            </maddy>
         </models>
        <events>
        <sales_order_place_after>
                <observers>
                    <maddy_sendsms>
                        <class>Maddy_Checkout_Model_Observer</class>
                        <method>orderSms</method>
                        <type>singleton</type>
                    </maddy_sendsms>
                </observers>
        </sales_order_place_after>
        </events>
    </global>
</config>

app/code/local/Maddy/Checkout/Model/Observer.php

<?php
class Maddy_Checkout_Model_Observer
{
    public function orderSms(Varien_Event_Observer $observer)
    {

        $order = $observer->getEvent()->getOrder();
        echo $incrementId = $order->getIncrementId();
        echo $custName    = $order->getCustomerFirstname();
        echo $orderPrice  = $order->getGrandTotal();
        echo $orderId     = $order->getId();        
        echo $mobile      = trim($order->getShippingAddress()->getData('telephone'));
        echo "I am here";
        die;              

    }
}
20
  • app/code/etc/Modules/Maddy_Checkout.xml is this path correct ?
    – inrsaurabh
    Commented Apr 28, 2017 at 12:44
  • ah no. app/etc/Modules/Maddy_Checkout.xml Commented Apr 28, 2017 at 12:45
  • updated my answer Commented Apr 28, 2017 at 12:45
  • i used app/etc/Modules/Maddy_Checkout.xml . still no result .
    – inrsaurabh
    Commented Apr 28, 2017 at 12:46
  • placed all code same as above ? Commented Apr 28, 2017 at 12:46
0

just replace with .

Instead of

  <checkout_onepage_controller_success_action>

replace with

<sales_order_place_after>

and your Observer.php class name should be Maddy_Checkout_Model_Observer

17
  • I chnged as you suggested but nothing shown
    – inrsaurabh
    Commented Apr 28, 2017 at 11:39
  • 1
    am i using wrong path
    – inrsaurabh
    Commented Apr 28, 2017 at 11:39
  • put die; in observer method and check because i doubted that alert will not work at there Commented Apr 28, 2017 at 11:48
  • i used die() still order is placed successfully.
    – inrsaurabh
    Commented Apr 28, 2017 at 11:56
  • this is a after event means after order successfuly placed this event will fire Commented Apr 28, 2017 at 12:05

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.