Wrapping event

Wrapping event

An event for asking if the user wants the products he has bought wrapped into wrapping papers. This event is included as an example for how to use templates and user input in an event.
kernel/classes/workflowtypes/event/ezwrapping/ezwrappingtype.php:

<?php

 

include_once( 'lib/ezutils/classes/ezhttptool.php' );

include_once( 'lib/ezutils/classes/ezorderitem.php' );

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

 

define( "EZ_WORKFLOW_TYPE_WRAPPING_ID", "ezwrapping" );

 

class eZWrappingType extends eZWorkflowEventType

{

   /*!

    Constructor

   */

   function eZWrappingType()

   {

       $this->eZWorkflowEventType( EZ_WORKFLOW_TYPE_WRAPPING_ID, "Wrapping" );

   }

 

   function execute( &$process, &$event )

   {

       eZDebug::writeNotice( $process, "process" );

       $parameters =& $process->attribute( 'parameter_list' );

       $http =& eZHTTPTool::instance();

       if ( $http->hasPostVariable( "Next" ) )

       {

           if ( $http->hasPostVariable( "answer" ) )

           {

               $answer = $http->postVariable( "answer" );

               eZDebug::writeDebug( 'got answer' );

               if ( $answer == 'yes' )

               {

                   $parameters = $process->attribute( 'parameter_list' );

                   eZDebug::writeDebug( 'got yes' );

                   $orderID = $parameters['order_id'];

                   $orderItem = new eZOrderItem( array( 'order_id' => $orderID,

                                                        'description' => 'Wrapping',

                                                        'price' => '100',

                                                        'vat_is_included' => true,

                                                        'vat_type_id' => 1 ) );

                   $orderItem->store();

               }

               else

               {

                   eZDebug::writeDebug( 'got no' );

               }

               return EZ_WORKFLOW_TYPE_STATUS_ACCEPTED;

           }

       }

 

       $node =& eZContentObjectTreeNode::fetch( $processParameters['node_id'] );

       $requestUri = eZSys::requestUri();

       $process->Template = array( 'templateName' => 

                                   'design:workflow/eventtype/result/' . 

                                   'event_ezwrapping' . '.tpl',

                                   'templateVars' => array( 'request_uri' => 

                                                             $requestUri )

                                 );

       return EZ_WORKFLOW_TYPE_STATUS_FETCH_TEMPLATE_REPEAT;

   }

}

 

eZWorkflowEventType::registerType( EZ_WORKFLOW_TYPE_WRAPPING_ID, "ezwrappingtype" );

 

?>

The execute method checks for an input variable called Next. If this variable is set, we have got input from the user and reacts based on this (adds wrapping paper to the order if the user answered yes) and returns accepted status. If we don't have this variable set, we show the template (we define what template to show with $process->Template) and returns EZ_WORKFLOW_TYPE_STATUS_FETCH_TEMPLATE_REPEAT. This status will show the template and rerun the event next time the workflow is triggered (when the user submittes the form in the template).

design/standard/templates/workflow/eventtype/result/event_ezwrapping.tpl:

<form action={$request_uri|ezurl} method="post" >

 

<div class="maincontentheader">

<h1>{"Wrapping"|i18n("design/standard/workflow/eventtype/result")}</h1>

</div>

 

<div class="block">

Do you want wrapping in Christmas paper?<br/>

No <input type="radio" name="answer" value="no" /><br/>

Yes <input type="radio" name="answer" value="yes" /> <br/>

</div>

 

<div class="buttonblock">

<input type="submit" name="Next" value="next" />

</div>

 

</form>

Comments

'nother Typo!

$requestUri = eZSys::requestUri();

again in 3.3-3 (5019) the function in eZSys is called requestURI()

;)

and again a nice day.

Typo in include_once

At least in 3.3-3 (5019)
ezorderitem.php resides in kernel/classes/ and not in lib/ezutils/classes/ as in the example above.

have a nice day!
armin

Log in or create a user account to comment.

Contents

Development

Extensions
    Translation
    Introduction to extensions
    Building an Exponential module
    Design extension
    Datatypes
    Workflow events
       Introduction to events
       Unpublish
       Wrapping event
       Creating a new event
    Module
    Template operator
    Template function
Exponential datamodel
Exponential tuning and stability
Importing attribute data
Kernel
Libraries
Scripting
Standards
System overview
Test Suite
Using Doxygen to create API documenta...


Created

10/07/2003
10:15:42 am
by Jo Henrik Endrerud

Last updated

10/07/2003
10:15:42 am
by Jo Henrik Endrerud

Authors

Jo Henrik Endrerud



This page is part of the Exponential documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.