1

I just started to write a module which adds a specific comment to all orders. Therefore im hooking into sales_order_place_after

The code below unfortunaley not works...

app/etc/modules/Easylife_Meta.xml

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

app/code/local/Easylife/Meta/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Meta>
            <version>0.0.1</version>
        </Easylife_Meta>
    </modules>
    <global>
        <models>
            <easylife_meta>
                <class>Easylife_Meta_Model</class>
            </easylife_meta>
        </models>
    <frontend>
        <events>
            <sales_order_place_after><!-- observe the event -->
                <observers>
                    <easylife_meta>
                        <class>easylife_meta/observer</class>
                        <method>autocomment</method>
                        <type>singleton</type>
                    </easylife_meta>
                </observers>
            </sales_order_place_after>
        </events>
    </frontend>
    </global>
</config>

app/code/local/Easylife/Meta/Model/Observer.php

<?php 
class Easylife_Meta_Model_Observer {
    public function autocomment($observer) {
        $order = $observer->getEvent()->getOrder();
        $history = $order->addStatusHistoryComment("comment");
        $history->setIsCustomerNotified(false);
        $order->save();
    }
} 
?>
1
  • Try this $order->addStatusHistoryComment($data['comment']]) ->setIsVisibleOnFront(true) ->setIsCustomerNotified(false); $order->save();
    – kunj
    Commented Jun 6, 2018 at 5:06

1 Answer 1

0

Your config xml seems incorrect, frontend should be outside from global

OR

You are using checkout_submit_all_after event which is dispatched if you create order from Backoffice and your observer is defined in frontend in config xml, Use sales_order_place_after.

1
  • 2
    Please don't put the different answers to the same question.Merge it
    – Amit Bera
    Commented Jun 7, 2018 at 11:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.