[solved] Problems creating custom workflowevent: "Call to...

Author Message

Achim Bleidiessel

Tuesday 14 February 2006 6:39:21 am

Hi!
I started creating a new Workflow Event as mentioned in the documentation on page http://ez.no/products/ez_publish_open_source_enterprise_cms/documentation/development/extensions/workflow_events/creating_a_new_event

My goal is to write an advanced shipping workflow with more shipping-rules(like "free shipping for orders over 20 euros" etc).
For the start i simply copied the contents of the ezsimpleshippingtype.php into my newly ezadvancedshippingtype.php (which i created like suggested by the documentation i mentioned above).
then i only changed the ezsimpleshipping-references to my ezadvancedshipping and included the "kernel/classes/ezworkflowtype.php" and the code now ooks like this:

<?php
//
// Definition of eZAdvancedShippingType class
//
// Created on: <09-äÅË-2002 14:42:23 sp>
//
// This file may be distributed and/or modified under the terms of the
// "GNU General Public License" version 2 as published by the Free
// Software Foundation and appearing in the file LICENSE included in
// the packaging of this file.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
// THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE.
//
// The "GNU General Public License" (GPL) is available at
// http://www.gnu.org/copyleft/gpl.html.
//
//

/*! \file ezadvancedshippingtype.php
*/

/*!
  \class eZAdvancedShippingType ezadvancedshippingtype.php
  \brief The class eZAdvancedshippingType handles adding shipping cost to an order plus the abillity to set an freeshipping border and an advanced shipping-calculation(depending on the shipping cost of each item)

*/
include_once( 'kernel/classes/ezorder.php' );
include_once('kernel/classes/ezworkflowtype.php');


define( 'EZ_WORKFLOW_TYPE_ADVANCEDSHIPPING_ID', 'ezadvancedshipping' );

class eZAdvancedShippingType extends eZWorkflowEventType
{
    /*!
     Constructor
    */
    function eZAdvancedShippingType()
    {
        $this->eZWorkflowEventType( EZ_WORKFLOW_TYPE_ADVANCEDSHIPPING_ID, ezi18n( 'kernel/workflow/event', "AdvancedShipping" ) );
        $this->setTriggerTypes( array( 'shop' => array( 'confirmorder' => array ( 'before' ) ) ) );
    }

    function execute( &$process, &$event )
    {
        $ini =& eZINI::instance( 'workflow.ini' );

        $cost = $ini->variable( "SimpleShippingWorkflow", "ShippingCost" );
        $description = $ini->variable( "SimpleShippingWorkflow", "ShippingDescription" );

        $parameters = $process->attribute( 'parameter_list' );
        $orderID = $parameters['order_id'];

        $order = eZOrder::fetch( $orderID );
        $orderItems = $order->attribute( 'order_items' );
        $addShipping = true;
        foreach ( array_keys( $orderItems ) as $key )
        {
            $orderItem =& $orderItems[$key];
            if ( $orderItem->attribute( 'description' ) == $description )
            {
                $addShipping = false;
                break;
            }
        }
        if ( $addShipping )
        {
            $orderItem = new eZOrderItem( array( 'order_id' => $orderID,
                                                 'description' => $description,
                                                 'price' => $cost,
                                                 'vat_is_included' => true,
                                                 'vat_type_id' => 1 )
                                          );
            $orderItem->store();
        }
        return EZ_WORKFLOW_TYPE_STATUS_ACCEPTED;
    }
}

eZWorkflowEventType::registerType( EZ_WORKFLOW_TYPE_ADVANCEDSHIPPING_ID, "advancedshippingtype" );

?>

unfortunalty evertime i create a new workflow, select the new event an want to add the new event i become this error:
<i>
Fatal error: Call to a member function on a non-object in /www/sujls136/htdocs/lvstein/kernel/workflow/edit.php on line 329
Fatal error: eZ publish did not finish its request

The execution of eZ publish was abruptly ended, the debug output is present below.
</i>

I dont understand the problem, because i simply took prebuild ezsimpleshippingtype.php and customized it only a bit.
I looked at other extensions (the shopsender-extension for example) and they're build analogical.
Anyone who can solve my problem???
Many thanks
Achim Bleidiessel

Juan Pablo Vercesi

Tuesday 14 February 2006 9:16:31 am

Hi Achim,

if you only have copied and modified the files, I think there might be problem with the .ini files. Are you sure they are completed in the right way?
Remember that when you create an extension of your own, there are certain rules that you should keep in mind in matter of paths (names, locations and structure, etc).

It would also help to trace the problem if you paste the line that is mentioned in the fatal error.

Greetings

JP,
may the source be with you.

Achim Bleidiessel

Tuesday 14 February 2006 3:39:09 pm

Hi Juan,
thanks for your reply, first of all the line which is mentioned in the error:

321: if ( $http->hasPostVariable( "NewButton" ) )
322: {
323:     $new_event = eZWorkflowEvent::create( $WorkflowID, $cur_type );
324:     $new_event_type =& $new_event->eventType();
325:     $db =& eZDB::instance();
326:     $db->begin();
327: 
328:     if ($canStore) $workflow->store( $event_list );
329:     $new_event_type->initializeEvent( $new_event );
330:     $new_event->store();
331:
332:     $db->commit();
333:     $event_list[] =& $new_event;
334: }

so the initialization of the events fails but i dont know what this means.

concerning the ini-files and structure of the extension i strictly followed the documentation:
the path of the event is:
'extension/ezadvancedonlineshop/eventtypes/event/ezadvancedshipping/ezadvancedshippingtype.php'

and i inserted the following lines in
'extension/ezadvancedonlineshop/settings/workflow.ini.append'

[EventSettings]
ExtensionDirectories[]=ezadvancedonlineshop
AvailableEventTypes[]=event_ezadvancedshipping

as consequence i can activate the extension in the admin-interface ('setup > extensions')
but i always get this failure i mentioned in my post before. I hoped its a typo but i really couldnt find anything, so i have to missunderstood something about creating extensions i think. any suggestions???

thanks
achim

Kristof Coomans

Wednesday 15 February 2006 12:23:58 am

Did you enable eZ debug output? If so, do you get any debug errors or warnings?

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Kristof Coomans

Wednesday 15 February 2006 12:33:50 am

I found the error:

eZWorkflowEventType::registerType( EZ_WORKFLOW_TYPE_ADVANCEDSHIPPING_ID, "advancedshippingtype" );

has to be:

eZWorkflowEventType::registerType( EZ_WORKFLOW_TYPE_ADVANCEDSHIPPING_ID, "ezadvancedshippingtype" );

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Achim Bleidiessel

Thursday 16 February 2006 3:06:05 am

Ah now it works, many thanks!!
I really didnt recognized this mad mistake....
Thanks!

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.