[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.

eZ debug

Timing: Jan 19 2025 00:18:02
Script start
Timing: Jan 19 2025 00:18:02
Module start 'layout'
Timing: Jan 19 2025 00:18:02
Module start 'content'
Timing: Jan 19 2025 00:18:03
Module end 'content'
Timing: Jan 19 2025 00:18:03
Script end

Main resources:

Total runtime0.7643 sec
Peak memory usage4,096.0000 KB
Database Queries68

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0063 588.1406152.6406
Module start 'layout' 0.00630.0050 740.781339.4766
Module start 'content' 0.01130.7515 780.2578646.2500
Module end 'content' 0.76280.0015 1,426.507820.1094
Script end 0.7642  1,446.6172 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00350.4565160.0002
Check MTime0.00150.1996160.0001
Mysql Total
Database connection0.00070.087810.0007
Mysqli_queries0.694990.9232680.0102
Looping result0.00090.1162660.0000
Template Total0.728795.320.3643
Template load0.00180.239020.0009
Template processing0.726995.104020.3634
Template load and register function0.00050.069110.0005
states
state_id_array0.00130.172010.0013
state_identifier_array0.00140.178020.0007
Override
Cache load0.00160.2128550.0000
Sytem overhead
Fetch class attribute can translate value0.00100.132630.0003
Fetch class attribute name0.00140.181680.0002
XML
Image XML parsing0.00130.170630.0004
class_abstraction
Instantiating content class attribute0.00000.002690.0000
General
dbfile0.00120.1531220.0001
String conversion0.00000.001540.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
12content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
17content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 45
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs