eZ Publish  [4.0]
ezorderitem.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Created on: <05-Dec-2002 09:12:43 bf>
00004 //
00005 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00006 // SOFTWARE NAME: eZ Publish
00007 // SOFTWARE RELEASE: 4.0.x
00008 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00009 // SOFTWARE LICENSE: GNU General Public License v2.0
00010 // NOTICE: >
00011 //   This program is free software; you can redistribute it and/or
00012 //   modify it under the terms of version 2.0  of the GNU General
00013 //   Public License as published by the Free Software Foundation.
00014 //
00015 //   This program is distributed in the hope that it will be useful,
00016 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 //   GNU General Public License for more details.
00019 //
00020 //   You should have received a copy of version 2.0 of the GNU General
00021 //   Public License along with this program; if not, write to the Free
00022 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00023 //   MA 02110-1301, USA.
00024 //
00025 //
00026 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00027 //
00028 
00029 /*!
00030   \class eZOrderItem ezorderitem.php
00031   \brief eZOrderItem handles custom order items
00032   \ingroup eZKernel
00033 
00034   Custom order items are used to automatically add new items to
00035   a specific order. You can use it to e.g. specify shipping and
00036   handling, special discount or wrapping costs.
00037 
00038   The order items is different from the product collection items
00039   in the way that there is no product for each order item.
00040 
00041   \sa eZProductCollection eZBasket eZOrder
00042 */
00043 
00044 //include_once( "kernel/classes/ezpersistentobject.php" );
00045 //include_once( "kernel/classes/ezvattype.php" );
00046 
00047 class eZOrderItem extends eZPersistentObject
00048 {
00049     function eZOrderItem( $row )
00050     {
00051         $this->eZPersistentObject( $row );
00052     }
00053 
00054     static function definition()
00055     {
00056         return array( "fields" => array( 'id' => array( 'name' => 'ID',
00057                                                         'datatype' => 'integer',
00058                                                         'default' => 0,
00059                                                         'required' => true ),
00060                                          'order_id' => array( 'name' => 'OrderID',
00061                                                               'datatype' => 'integer',
00062                                                               'default' => 0,
00063                                                               'required' => true,
00064                                                               'foreign_class' => 'eZOrder',
00065                                                               'foreign_attribute' => 'id',
00066                                                               'multiplicity' => '1..*' ),
00067                                          'description' => array( 'name' => 'Description',
00068                                                                  'datatype' => 'string',
00069                                                                  'default' => '',
00070                                                                  'required' => true ),
00071                                          'price' => array( 'name' => 'Price',
00072                                                            'datatype' => 'float',
00073                                                            'default' => 0,
00074                                                            'required' => true ),
00075                                          'vat_value' => array( 'name' => 'VATValue',
00076                                                                'datatype' => 'float',
00077                                                                'default' => 0,
00078                                                                'required' => true ),
00079                                          'is_vat_inc' => array( 'name' => 'IsVATIncluded',
00080                                                                 'datatype' => 'integer',
00081                                                                 'default' => 0,
00082                                                                 'required' => true ),
00083                                          'type' => array( 'name' => 'Type',
00084                                                           'datatype' => 'string',
00085                                                           'required' => false ) ),
00086                       'keys' => array( 'id' ),
00087                       'function_attributes' => array( 'vat_value' => 'vatValue',
00088                                                       'price_inc_vat' => 'priceIncVat',
00089                                                       'price_ex_vat' => 'priceExVAT' ),
00090                       'increment_key' => 'id',
00091                       'class_name' => 'eZOrderItem',
00092                       'name' => 'ezorder_item' );
00093     }
00094 
00095     static function fetchList( $orderID, $asObject = true )
00096     {
00097         return eZPersistentObject::fetchObjectList( eZOrderItem::definition(),
00098                                                     null,
00099                                                     array( "order_id" => $orderID ),
00100                                                     null,
00101                                                     null,
00102                                                     $asObject );
00103     }
00104 
00105     static function fetchListByType( $orderID, $itemType, $asObject = true )
00106     {
00107         return eZPersistentObject::fetchObjectList( eZOrderItem::definition(),
00108                                                     null,
00109                                                     array( 'order_id' => $orderID, 'type' => $itemType ),
00110                                                     null,
00111                                                     null,
00112                                                     $asObject );
00113 
00114     }
00115 
00116     function vatValue()
00117     {
00118         return $this->VATValue;
00119     }
00120 
00121     function priceIncVAT()
00122     {
00123         if ( $this->attribute( 'is_vat_inc' ) == 1 )
00124         {
00125             return $this->Price;
00126         }
00127         else
00128         {
00129             $incVATPrice = $this->Price * ( $this->vatValue() + 100 ) / 100;
00130             return $incVATPrice;
00131         }
00132 
00133     }
00134 
00135     function priceExVAT()
00136     {
00137         if ( $this->attribute( 'is_vat_inc' ) == 1 )
00138         {
00139             return $this->Price / ( $this->vatValue() + 100 ) * 100;
00140         }
00141 
00142         return $this->Price;
00143     }
00144 
00145     /*!
00146      \static
00147      Removes all order items from the database.
00148      \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
00149      the calls within a db transaction; thus within db->begin and db->commit.
00150     */
00151     function cleanup()
00152     {
00153         $db = eZDB::instance();
00154         $db->query( "DELETE FROM ezorder_item" );
00155     }
00156 }
00157 
00158 ?>