eZ Publish  [4.0]
ezsimpleshippingtype.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZSimpleShippingType class
00004 //
00005 // Created on: <09-δΕΛ-2002 14:42:23 sp>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*! \file ezsimpleshippingtype.php
00032 */
00033 
00034 /*!
00035   \class eZSimpleShippingType ezsimpleshippingtype.php
00036   \brief The class eZSimpleShippingType handles adding shipping cost to an order
00037 
00038 */
00039 //include_once( 'kernel/classes/ezorder.php' );
00040 
00041 class eZSimpleShippingType extends eZWorkflowEventType
00042 {
00043     const WORKFLOW_TYPE_STRING = 'ezsimpleshipping';
00044 
00045     /*!
00046      Constructor
00047     */
00048     function eZSimpleShippingType()
00049     {
00050         $this->eZWorkflowEventType( eZSimpleShippingType::WORKFLOW_TYPE_STRING, ezi18n( 'kernel/workflow/event', "Simple shipping" ) );
00051         $this->setTriggerTypes( array( 'shop' => array( 'confirmorder' => array ( 'before' ) ) ) );
00052     }
00053 
00054     function execute( $process, $event )
00055     {
00056         $ini = eZINI::instance( 'workflow.ini' );
00057 
00058         $cost = $ini->variable( "SimpleShippingWorkflow", "ShippingCost" );
00059         $description = $ini->variable( "SimpleShippingWorkflow", "ShippingDescription" );
00060 
00061         $parameters = $process->attribute( 'parameter_list' );
00062 
00063         if ( isset( $parameters['order_id'] ) )
00064         {
00065             $orderID = $parameters['order_id'];
00066 
00067             $order = eZOrder::fetch( $orderID );
00068             $orderItems = $order->attribute( 'order_items' );
00069             $addShipping = true;
00070             foreach ( $orderItems as $orderItem )
00071             {
00072                 if ( $orderItem->attribute( 'type' ) == 'ezsimpleshipping' )
00073                 {
00074                     $addShipping = false;
00075                     break;
00076                 }
00077             }
00078             if ( $addShipping )
00079             {
00080                 $productCollection = $order->attribute( 'productcollection' );
00081                 $orderCurrency = $productCollection->attribute( 'currency_code' );
00082 
00083                 //include_once( 'kernel/shop/classes/ezshopfunctions.php' );
00084                 $cost = eZShopFunctions::convertAdditionalPrice( $orderCurrency, $cost );
00085 
00086                 $orderItem = new eZOrderItem( array( 'order_id' => $orderID,
00087                                                      'description' => $description,
00088                                                      'price' => $cost,
00089                                                      'type' => 'ezsimpleshipping' )
00090                                               );
00091                 $orderItem->store();
00092             }
00093         }
00094         return eZWorkflowType::STATUS_ACCEPTED;
00095     }
00096 }
00097 
00098 eZWorkflowEventType::registerEventType( eZSimpleShippingType::WORKFLOW_TYPE_STRING, "eZSimpleShippingType" );
00099 
00100 ?>