ez.no / exponential / documentation / development / extensions / workflow events / 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>
Log in or create a user account to comment.
Comments
'nother Typo!
Armin Lukas
Tuesday 01 June 2004 10:04:30 am
again in 3.3-3 (5019) the function in eZSys is called requestURI()
;)
and again a nice day.
Typo in include_once
Armin Lukas
Tuesday 01 June 2004 9:27:06 am
ezorderitem.php resides in kernel/classes/ and not in lib/ezutils/classes/ as in the example above.
have a nice day!
armin