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

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

eZ debug

Timing: Jan 31 2025 01:30:13
Script start
Timing: Jan 31 2025 01:30:13
Module start 'content'
Timing: Jan 31 2025 01:30:13
Module end 'content'
Timing: Jan 31 2025 01:30:13
Script end

Main resources:

Total runtime0.2085 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0093 588.0859370.2734
Module start 'content' 0.00930.0169 958.35941,013.7344
Module end 'content' 0.02620.1823 1,972.09383,909.0859
Script end 0.2084  5,881.1797 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00462.1885200.0002
Check MTime0.00140.6552200.0001
Mysql Total
Database connection0.00120.556410.0012
Mysqli_queries0.101848.83851410.0007
Looping result0.00160.74551390.0000
Template Total0.181887.210.1818
Template load0.00090.430810.0009
Template processing0.180986.747310.1809
Override
Cache load0.00050.254710.0005
Sytem overhead
Fetch class attribute can translate value0.00170.832210.0017
XML
Image XML parsing0.00040.174110.0004
General
dbfile0.00833.9575200.0004
String conversion0.00000.004530.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0002 secs