00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 include_once( 'kernel/classes/ezorder.php' );
00040
00041
00042 define( 'EZ_WORKFLOW_TYPE_SIMPLESHIPPING_ID', 'ezsimpleshipping' );
00043
00044 class eZSimpleShippingType extends eZWorkflowEventType
00045 {
00046
00047
00048
00049 function eZSimpleShippingType()
00050 {
00051 $this->eZWorkflowEventType( EZ_WORKFLOW_TYPE_SIMPLESHIPPING_ID, ezi18n( 'kernel/workflow/event', "Simple shipping" ) );
00052 $this->setTriggerTypes( array( 'shop' => array( 'confirmorder' => array ( 'before' ) ) ) );
00053 }
00054
00055 function execute( &$process, &$event )
00056 {
00057 $ini =& eZINI::instance( 'workflow.ini' );
00058
00059 $cost = $ini->variable( "SimpleShippingWorkflow", "ShippingCost" );
00060 $description = $ini->variable( "SimpleShippingWorkflow", "ShippingDescription" );
00061
00062 $parameters = $process->attribute( 'parameter_list' );
00063
00064 if ( isset( $parameters['order_id'] ) )
00065 {
00066 $orderID = $parameters['order_id'];
00067
00068 $order = eZOrder::fetch( $orderID );
00069 $orderItems = $order->attribute( 'order_items' );
00070 $addShipping = true;
00071 foreach ( array_keys( $orderItems ) as $key )
00072 {
00073 $orderItem =& $orderItems[$key];
00074 if ( $orderItem->attribute( 'type' ) == 'ezsimpleshipping' )
00075 {
00076 $addShipping = false;
00077 break;
00078 }
00079 }
00080 if ( $addShipping )
00081 {
00082 $productCollection =& $order->attribute( 'productcollection' );
00083 $orderCurrency =& $productCollection->attribute( 'currency_code' );
00084
00085 include_once( 'kernel/shop/classes/ezshopfunctions.php' );
00086 $cost = eZShopFunctions::convertAdditionalPrice( $orderCurrency, $cost );
00087
00088 $orderItem = new eZOrderItem( array( 'order_id' => $orderID,
00089 'description' => $description,
00090 'price' => $cost,
00091 'type' => 'ezsimpleshipping' )
00092 );
00093 $orderItem->store();
00094 }
00095 }
00096 return EZ_WORKFLOW_TYPE_STATUS_ACCEPTED;
00097 }
00098 }
00099
00100 eZWorkflowEventType::registerType( EZ_WORKFLOW_TYPE_SIMPLESHIPPING_ID, "ezsimpleshippingtype" );
00101
00102 ?>