cancel
Showing results for 
Search instead for 
Did you mean: 

Can't figure out why my class from event isn't executed

SOLVED

Can't figure out why my class from event isn't executed

Hi all!

My version of Magento CE is v1.9.2

 

My target is: run my code when order is fully completed (with captured transaction and created invoice).

 

Here is my config.xml (a part from <event>).

I'm using sales_order_save_commit_after

 

<events>
            <sales_order_save_commit_after>
                <observers>
                    <order_status_change>
                        <type>singleton</type>
                        <class>apiplugin/cwOrderObserver</class>
                        <method>statusChange</method>
                    </order_status_change>
                </observers>
            </sales_order_save_commit_after>
</events>

 

 

Basicly my code and observer works when new order is came AND I from admin area make a invoice to order under Order-> Invoices -> Invoice -> [REVIEW] -> Send invoice.

 

I have a 3rd party plugin from popular moneybooker (Przelewy24). This script at the end generate the invoice by self.

Here is a dump from code where invoice is generated by this script.

It looks usual. Invoice is generated and order status are set to Complete, but my code isn't run!

 

 

if($order->canInvoice()) {
				$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
				if ($invoice->getTotalQty()) {
					$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
					$invoice->register();
					$transactionSave = Mage::getModel('core/resource_transaction')
						->addObject($invoice)
						->addObject($invoice->getOrder());
					$transactionSave->save();
				}
			}
		} catch

I can't figure out why my event sales_order_save_commit_after with my class isn't run when I use this code above.

 

I just used other code to make a invoice from Processing orders (came from here: how-to-create-cron-for-partial-invoice-of-an-order ) and situation is the same. Order is completed by above script but my class from sales_order_save_commit_after is not executed ;(

 

It's looks like a bug or something...

 

In brief:

* When I create invoice from order manually (from Admin Area) my class from sales_order_save_commit_after  is executed.

* When I make a order and register a transaction, and start making invocie using scripts above my class from sales_order_save_commit_after  is NOT executed.

 

Thank you in advance for your help.

Michael

 

 

 

 

 

6 REPLIES

Re: Can't figure out why my class from event isn't executed

Can you post your entire config.xml and observer class please?

 

Problem solved? Click Accept as Solution!
www.iwebsolutions.co.uk | Magento Small Business Partner

Re: Can't figure out why my class from event isn't executed

Sure. 

 

config.xml

 

<?xml version="1.0"?>
<config>

    <modules>

        <CWA_ApiPlugin>
            <version>1.0.0</version>
        </CWA_ApiPlugin>

    </modules>

    <global>

        <helpers>
            <apiplugin>
                <class>CWA_ApiPlugin_Helper</class>
            </apiplugin>
        </helpers>

        <blocks>
            <apiplugin>
                <class>CWA_ApiPlugin_Block</class>
            </apiplugin>
        </blocks>

        <models>
            <apiplugin>
                <class>CWA_ApiPlugin_Model</class>
            </apiplugin>
        </models>

        <resources>

            <apiplugin_setup>
                <setup>
                    <module>CWA_ApiPlugin</module>
                    <class>CWA_ApiPlugin_Model_Resource_Eav_Mysql4_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </apiplugin_setup>

            <apiplugin_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </apiplugin_write>

            <apiplugin_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </apiplugin_read>

        </resources>

        <template>
            <email>
                <send_CWA_mail>
                    <label>Mail</label>
                    <file>CWA_send_mail.html</file>
                    <type>html</type>
                </send_CWA_mail>
            </email>
        </template>

        <template>
            <email>
                <send_CWAprd_mail>
                    <label>PreOrder Mail</label>
                    <file>CWA_send_prd_mail.html</file>
                    <type>html</type>
                </send_CWAprder_mail>
            </email>
        </template>

        <template>
            <email>
                <send_admin_error_mail>
                    <label>Error Mail</label>
                    <file>CWA_admin_error_mail.html</file>
                    <type>html</type>
                </send_admin_error_mail>
            </email>
        </template>

        <template>
            <email>
                <send_admin_info_mail>
                    <label>Info Mail</label>
                    <file>CWA_info_admin_mail.html</file>
                    <type>html</type>
                </send_admin_info_mail>
            </email>
        </template>

        <template>
            <email>
                <send_admin_info_prder_mail>
                    <label>Info About Prd Mail</label>
                    <file>CWA_notify_about_prder.html</file>
                    <type>html</type>
                </send_admin_info_prder_mail>
            </email>
        </template>

    </global>

    <frontend>

        <routers>
            <CWA_controller>
                <use>standard</use>
                <args>
                    <module>CWA_ApiPlugin</module>
                    <frontName>CWA</frontName>
                </args>
            </CWA_controller>
        </routers>


    </frontend>

    <default>
        <payment>
            <CWAorder_payment_method>
                <active>1</active>
                <model>CWA_ApiPlugin_Model_Payment_CWAOrder</model>
                <order_status>CWA_completed</order_status>
                <allowspecific>0</allowspecific>
                <payment_action>init</payment_action>
                <group>offline</group>
            </CWAorder_payment_method>
        </payment>
    </default>

    <adminhtml>

        <layout>
            <updates>
                <apiplugin>
                    <file>apiplugin.xml</file>
                </apiplugin>
            </updates>
        </layout>

        <events>
            <catalog_product_save_after>
                <observers>
                    <apiplugin_save_product_data>
                        <type>singleton</type>
                        <class>apiplugin/observer</class>
                        <method>saveProductTabData</method>
                    </apiplugin_save_product_data>
                </observers>
            </catalog_product_save_after>

            <sales_order_save_commit_after>
                <observers>
                    <order_status_change>
                        <type>singleton</type>
                        <class>apiplugin/CWAOrderObserver</class>
                        <method>statusChange</method>
                    </order_status_change>
                </observers>
            </sales_order_save_commit_after>

            <CWA_send_after_buy>
                <observers>
                    <apiplugin_send_after_buy>
                        <type>singleton</type>
                        <class>apiplugin/CWASendKeysObserver</class>
                        <method>sendKeys</method>
                    </apiplugin_send_after_buy>
                </observers>
            </CWA_send_after_buy>

        </events>

        <acl>
            <resources>
                <admin>
                    <children>
                        <system>
                            <children>
                                <config>
                                    <children>
                                        <apiplugin_connection>
                                            <title>Connection status</title>
                                            <sort_order>2</sort_order>
                                        </apiplugin_connection>
                                    </children>
                                </config>
                            </children>
                        </system>
                    </children>
                </admin>
            </resources>
        </acl>

    </adminhtml>

</config> 

And code from my observer:

 

<?php

require_once 'vendor/autoload.php';
use CWA\CWA;

class CWA_ApiPlugin_Model_CWAOrderObserver
{
    static protected $_singletonFlag = false;

 
    public function statusChange($observer)
    {

    }

    private function createCWAClient()
    {
        return Mage::helper('apiplugin/data')->connectToCWA();
    }
}

 

Re: Can't figure out why my class from event isn't executed

If you put a die() just inside the function does that stop execution? I.e. is your function being called at all.

 

Is there a reason you are using composer to load your model files. Magento has mechanisms to do this already.

Problem solved? Click Accept as Solution!
www.iwebsolutions.co.uk | Magento Small Business Partner

Re: Can't figure out why my class from event isn't executed

I tried with die() also.


There are 2 cases:


If I will make a new order (with example offline payment) and go to AdminArea-> Orders -> Order with status Processing -> Invoices -> Invoice -> [REVIEW] -> Submit Invoice answer to Your question is yes. Script dies. So my class is executed.

 

But when I run script manually to generate a invoice (like this from first post) or use online payment (when plugin from moneybooker create the invoice) then script does not die. Invoice is generated with success and order status is set to Complete ;(
My class is NOT executed.

 

It's a very strange. I can't figure out why on this conditions my script are not executed, and in other conditions is executed.

 

Composer need to be loaded because I'm using provided SDK to connect to other service.

 

 

 

 

Re: Can't figure out why my class from event isn't executed

Move the event in to the <global> node rather than just <adminhtml>

Problem solved? Click Accept as Solution!
www.iwebsolutions.co.uk | Magento Small Business Partner

Re: Can't figure out why my class from event isn't executed

Thank You! Now I see that my observer is working Smiley Wink