[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/classes/ -> ezproductcollectionitem.php (source)

   1  <?php
   2  //
   3  // Definition of eZProductCollectionItem class
   4  //
   5  // Created on: <04-Jul-2002 13:45:10 bf>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*!
  30    \class eZProductCollectionItem ezproductcollection.php
  31    \brief eZProductCollectionItem handles one product item
  32    \ingroup eZKernel
  33  
  34  */
  35  
  36  include_once ( "kernel/classes/ezpersistentobject.php" );
  37  include_once ( "kernel/classes/ezcontentobject.php" );
  38  include_once ( "kernel/classes/ezproductcollectionitemoption.php" );
  39  
  40  
  41  class eZProductCollectionItem extends eZPersistentObject
  42  {
  43      function eZProductCollectionItem( $row )
  44      {
  45          $this->eZPersistentObject( $row );
  46      }
  47  
  48      function definition()
  49      {
  50          return array( "fields" => array( "id" => array( 'name' => 'ID',
  51                                                          'datatype' => 'integer',
  52                                                          'default' => 0,
  53                                                          'required' => true ),
  54                                           "productcollection_id" => array( 'name' => "ProductCollectionID",
  55                                                                            'datatype' => 'integer',
  56                                                                            'default' => 0,
  57                                                                            'required' => true,
  58                                                                            'foreign_class' => 'eZProductCollection',
  59                                                                            'foreign_attribute' => 'id',
  60                                                                            'multiplicity' => '1..*' ),
  61                                           "contentobject_id" => array( 'name' => "ContentObjectID",
  62                                                                        'datatype' => 'integer',
  63                                                                        'default' => 0,
  64                                                                        'required' => true,
  65                                                                        'foreign_class' => 'eZContentObject',
  66                                                                        'foreign_attribute' => 'id',
  67                                                                        'multiplicity' => '1..*' ),
  68                                           "item_count" => array( 'name' => "ItemCount",
  69                                                                  'datatype' => 'integer',
  70                                                                  'default' => 0,
  71                                                                  'required' => true ),
  72                                           "price" => array( 'name' => "Price",
  73                                                             'datatype' => 'float',
  74                                                             'default' => 0,
  75                                                             'required' => true ),
  76                                           'is_vat_inc' => array( 'name' => "IsVATIncluded",
  77                                                                  'datatype' => 'integer',
  78                                                                  'default' => 0,
  79                                                                  'required' => true ),
  80                                           'vat_value' => array( 'name' => "VATValue",
  81                                                                 'datatype' => 'float',
  82                                                                 'default' => 0,
  83                                                                 'required' => true ),
  84                                           'discount' => array( 'name' => "DiscountValue",
  85                                                                'datatype' => 'integer',
  86                                                                'default' => 0,
  87                                                                'required' => true ),
  88                                           'name' => array( 'name' => 'Name',
  89                                                            'datatype' => 'string',
  90                                                            'default' => '',
  91                                                            'required' => true ) ),
  92                        'function_attributes' => array( 'contentobject' => 'contentObject',
  93                                                        'option_list' => 'optionList' ),
  94                        "keys" => array( "id" ),
  95                        "increment_key" => "id",
  96                        "relations" => array( "contentobject_id" => array( "class" => "ezcontentobject",
  97                                                                           "field" => "id" ),
  98                                              "productcollection_id" => array( "class" => "ezproductcollection",
  99                                                                               "field" => "id" ) ),
 100                        "class_name" => "eZProductCollectionItem",
 101                        "name" => "ezproductcollection_item" );
 102      }
 103  
 104      /*!
 105       Creates a new empty collection item which belongs to
 106       collection \a $collectionID and returns it.
 107      */
 108      function create( $productCollectionID )
 109      {
 110          $row = array( "productcollection_id" => $productCollectionID );
 111          return new eZProductCollectionItem( $row );
 112      }
 113  
 114      /*!
 115       Clones the collection item object and returns it. The ID of the clone is erased.
 116      */
 117      function clone()
 118      {
 119          $item = $this;
 120          $item->setAttribute( 'id', null );
 121          return $item;
 122      }
 123  
 124      /*!
 125       Copies the collection object item and the option,
 126       the new copy will point to the collection \a $collectionID.
 127       \return the new collection item object.
 128       \note The new collection item will already be present in the database.
 129       \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
 130       the calls within a db transaction; thus within db->begin and db->commit.
 131      */
 132      function &copy( $collectionID )
 133      {
 134          $item = $this->clone();
 135          $item->setAttribute( 'productcollection_id', $collectionID );
 136          $item->store();
 137          $oldItemOptionList =& $this->optionList();
 138          foreach ( array_keys( $oldItemOptionList ) as $oldItemOptionKey )
 139          {
 140              $oldItemOption =& $oldItemOptionList[$oldItemOptionKey];
 141              $itemOption =& $oldItemOption->copy( $item->attribute( 'id' ) );
 142          }
 143          return $item;
 144      }
 145  
 146      function fetch( $id, $asObject = true )
 147      {
 148          return eZPersistentObject::fetchObject( eZProductCollectionItem::definition(),
 149                                                  null,
 150                                                  array( "id" => $id ),
 151                                                  $asObject );
 152      }
 153  
 154      function fetchList( $conditions = null, $asObjects = true, $offset = false, $limit = false )
 155      {
 156          $limitation = null;
 157          if ( $offset !== false or $limit !== false )
 158              $limitation = array( 'offset' => $offset, 'length' => $limit );
 159  
 160          return eZPersistentObject::fetchObjectList( eZProductCollectionItem::definition(),
 161                                                      null,
 162                                                      $conditions,
 163                                                      null,
 164                                                      $limitation,
 165                                                      $asObjects );
 166      }
 167  
 168      /*!
 169       \return the discount percent for the current item
 170      */
 171      function discountPercent()
 172      {
 173          $discount = false;
 174          return $discount;
 175      }
 176  
 177      /*!
 178       \return Returns the content object defining the product.
 179      */
 180      function &contentObject()
 181      {
 182          if ( $this->ContentObject === null )
 183          {
 184              if ( $this->ContentObjectID == 0 )
 185              {
 186                  $retValue = null;
 187                  return $retValue;
 188              }
 189              $this->ContentObject =& eZContentObject::fetch( $this->ContentObjectID );
 190          }
 191          return $this->ContentObject;
 192      }
 193  
 194      function &optionList()
 195      {
 196          $optionList = eZProductCollectionItemOption::fetchList( $this->attribute( 'id' ) );
 197          return $optionList;
 198      }
 199  
 200      /*!
 201       \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
 202       the calls within a db transaction; thus within db->begin and db->commit.
 203       */
 204      function remove()
 205      {
 206          $itemOptionList = eZProductCollectionItemOption::fetchList( $this->attribute( 'id' ) );
 207  
 208          $db =& eZDB::instance();
 209          $db->begin();
 210          foreach( array_keys( $itemOptionList ) as $key )
 211          {
 212              $itemOption =& $itemOptionList[$key];
 213              $itemOption->remove();
 214          }
 215          eZPersistentObject::remove();
 216          $db->commit();
 217      }
 218  
 219      /*!
 220       Goes trough all options and finds the attribute they points to and calls productOptionInformation()
 221       to fetch the option data.
 222       \return The total price of all options.
 223      */
 224      function calculatePriceWithOptions( $currency = false )
 225      {
 226          include_once ( 'kernel/shop/classes/ezshopfunctions.php' );
 227  
 228          $optionList = eZProductCollectionItemOption::fetchList( $this->attribute( 'id' ) );
 229          $contentObject =& $this->contentObject();
 230          $contentObjectVersion =& $contentObject->attribute( 'current_version' );
 231          $optionsPrice = 0.0;
 232          if ( count( $optionList ) > 0 )
 233          {
 234              $db =& eZDB::instance();
 235              $db->begin();
 236              foreach( $optionList as $option )
 237              {
 238                  $objectAttribute = eZContentObjectAttribute::fetch( $option->attribute( 'object_attribute_id' ), $contentObjectVersion );
 239                  if ( $objectAttribute == null )
 240                  {
 241                      $optionsPrice += 0.0;
 242                      continue;
 243                  }
 244  
 245                  $dataType = $objectAttribute->dataType();
 246                  $optionData = $dataType->productOptionInformation( $objectAttribute, $option->attribute( 'option_item_id' ), $this, $option );
 247  
 248                  if ( $optionData )
 249                  {
 250                      $optionData['additional_price'] = eZShopFunctions::convertAdditionalPrice( $currency, $optionData['additional_price'] );
 251                      $option->setAttribute( 'price', $optionData['additional_price'] );
 252                      $option->store();
 253  
 254                      $optionsPrice += $optionData['additional_price'];
 255                  }
 256  
 257              }
 258              $db->commit();
 259          }
 260          return $optionsPrice;
 261      }
 262  
 263      function verify( $currency = false )
 264      {
 265          $contentObject =& $this->attribute( 'contentobject' );
 266          if ( $contentObject != null && $contentObject->attribute( 'main_node_id' ) > 0 )
 267          {
 268              include_once ( 'kernel/shop/classes/ezshopfunctions.php' );
 269  
 270              $attributes = $contentObject->contentObjectAttributes();
 271              $optionsPrice = $this->calculatePriceWithOptions( $currency );
 272  /*            if (  $optionsPrice === false )
 273              {
 274                  eZDebug::writeDebug( $optionPrice , "Option price is not the same" );
 275  
 276                  return false;
 277              } */
 278              foreach ( $attributes as $attribute )
 279              {
 280                  $dataType = $attribute->dataType();
 281                  if ( eZShopFunctions::isProductDatatype( $dataType->isA() ) )
 282                  {
 283                      $priceObj =& $attribute->content();
 284  
 285                      $price = $priceObj->attribute( 'price' );
 286                      $priceWithOptions = $price + $optionsPrice;
 287                      if ( $priceWithOptions != $this->attribute( 'price' ) )
 288                      {
 289                          return false;
 290                      }
 291                      if ( $priceObj->attribute( 'is_vat_included' ) != ( $this->attribute( 'is_vat_inc' ) > 0 ) )
 292                      {
 293                          return false;
 294                      }
 295                      if ( $priceObj->attribute( 'vat_percent' ) != $this->attribute( 'vat_value' ) )
 296                      {
 297                          return false;
 298                      }
 299                      if ( $priceObj->discount() != $this->attribute( 'discount' ) )
 300                      {
 301                          return false;
 302                      }
 303                      return true;
 304                  }
 305              }
 306  
 307          }
 308          return false;
 309      }
 310  
 311      /*!
 312       \static
 313       Removes all product collection items which related to the product collections specified in the array \a $productCollectionIDList.
 314       \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
 315       the calls within a db transaction; thus within db->begin and db->commit.
 316      */
 317      function cleanupList( $productCollectionIDList )
 318      {
 319          $db =& eZDB::instance();
 320          $db->begin();
 321          $idText = $db->implodeWithTypeCast( ', ', $productCollectionIDList, 'int' );
 322          $rows = $db->arrayQuery( "SELECT id FROM ezproductcollection_item WHERE productcollection_id IN ( $idText )" );
 323          if ( count( $rows ) > 0 )
 324          {
 325              $itemIDList = array();
 326              foreach ( $rows as $row )
 327              {
 328                  $itemIDList[] = $row['id'];
 329              }
 330              include_once ( 'kernel/classes/ezproductcollectionitemoption.php' );
 331              eZProductCollectionItemOption::cleanupList( $itemIDList );
 332          }
 333          $db->query( "DELETE FROM ezproductcollection_item WHERE productcollection_id IN ( $idText )" );
 334          $db->commit();
 335  
 336      }
 337  
 338      /// Stores the content object
 339      var $ContentObject = null;
 340  }
 341  
 342  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7