Wrapping workflow
Allows you to ask the user, before he confirms the order, if he wants to pack his goods into Christmas paper.
To create this workflow you need to do the following steps
- Create new event_type
- Create workflow with that event
- Connect that workflow to the shop/confirm operation
To know how to create event type read the tutorial Custom workflows,
go to the part called "Creating workflows". Create a skeleton of a workflow event.
File ezwrappingtype.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 )
{
return EZ_WORKFLOW_TYPE_STATUS_FETCH_TEMPLATE_REPEAT;
}
}
eZWorkflowEventType::registerType( EZ_WORKFLOW_TYPE_WRAPPING_ID, "ezwrappingtype" );
We will modify the "execute" function to improve the functionality of the workflow.
function execute( &$process, &$event )
{
1
2 $http =& eZHTTPTool::instance();
3
4 if ( $http->hasPostVariable( "Next" ) )
5 {
6 if ( $http->hasPostVariable( "answer" ) )
7 {
8 $answer = $http->postVariable( "answer" );
9 eZDebug::writeDebug( 'got answer' );
10 if( $answer == 'yes' )
11 {
12 $parameters = $process->attribute( 'parameter_list' );
13 eZDebug::writeDebug( 'got yes' );
14 $orderID = $parameters['order_id'];
15
16 $orderItem = new eZOrderItem( array( 'order_id' => $orderID,
17 'description' => 'Wrapping',
18 'price' => '100',
19 'vat_is_included' => true,
20 'vat_type_id' => 1 )
21 );
22 $orderItem->store();
23
24 }else
25 {
26 eZDebug::writeDebug( 'got no' );
27
28 }
29 return EZ_WORKFLOW_TYPE_STATUS_ACCEPTED;
30 }
31 }
32 $requestUri = eZSys::requestUri();
33 $process->Template = array( 'templateName' => 'design:workflow/eventtype/result/' . 'event_ezwrapping' . '.tpl',
34 'templateVars' => array( 'request_uri' => $requestUri )
35 );
36 return EZ_WORKFLOW_TYPE_STATUS_FETCH_TEMPLATE_REPEAT;
}
Comments
line 2 - get eZHTTPTool instance to fetch postvariable from.
Conditional operators (4-6) which check if the needed http variables exist.
This is needed to check whether this is the answer from the user.
If we get an answer from user and if answer is yes we need to create an order item with wrapping.
OrderID is a workflow parameter (defined by operation) so you can fetch it from parameters list (12,14)
If the answer is "no" we "accept" event.
When the event runs first we need to say to the system that we need to halt an operation
and show an additional page to the user (32-36)
Create result template
<form action={$return_uri|ezurl} method="post" >
<div class="maincontentheader">
<h1>{"Hello"|i18n('workflow/eventtype/result/event_hellouser')} {$user_name}</h1>
</div>
<div class="buttonblock">
<input type="submit" name="Next" value="next" />
</div>
</form>
The page will look like this:
Creating and connecting the workflow
To know how to connect the workflow to the operation look through the Approval workflow
tutorial.
When connecting to the operation (triggers) select the name of the created workflow in the front of "shop-confirm-before".
So now you can use the workflow.
|