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:
TODO — Image not available in archive
Title: Wrapping Workflow — Shop Confirm Page Screenshot
ID: wrappingworkflow-confirm
In: sdk/tutorials/view/wrappingworkflow/index.html
What this image shows:
Screenshot of the Exponential CMS shop confirmation page as rendered by the wrapping workflow tutorial. Shows the custom confirmation form with a "Next" submit button inside a buttonblock container, rendered as HTML in the browser. The image was not captured by the Wayback Machine (replaced with 1×1 spacer).
Replacement instructions:
Install Exponential 3.1 with the shop module, implement the wrapping workflow from sdk/tutorials/view/wrappingworkflow, add a product to the cart, proceed to checkout, and take a browser screenshot of the confirm step. Save as /doc/images/wrappingworkflow_confirm.png
See /sdk/missing.html for the full list of missing images.
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".
TODO — Image not available in archive
Title: Wrapping Workflow — Triggers Configuration Screenshot (Admin UI)
ID: wrappingworkflow-triggers
In: sdk/tutorials/view/wrappingworkflow/index.html
What this image shows:
Screenshot of the Exponential admin Triggers configuration page showing the "shop-confirm-before" operation trigger with the wrapping workflow selected from the dropdown. Used in the wrapping workflow tutorial to demonstrate how to connect the custom workflow to the shop confirm operation. The image was not archived by the Wayback Machine (replaced with 1×1 spacer).
Replacement instructions:
Admin > Setup > Triggers, connect the wrapping workflow to "shop-confirm-before", screenshot the trigger list page. Save as /doc/images/wrappingworkflow_triggers.png
See /sdk/missing.html for the full list of missing images.
So now you can use the workflow.
|