[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

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

   1  <?php
   2  //
   3  // Definition of eZWishList class
   4  //
   5  // Created on: <01-Aug-2002 10:22:02 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  /*!
  31    \class eZWishList ezwishlist.php
  32    \brief eZWishList handles shopping wish lists
  33    \ingroup eZKernel
  34  
  35    \sa eZProductCollection
  36  */
  37  
  38  include_once ( "kernel/classes/ezpersistentobject.php" );
  39  include_once ( "kernel/classes/ezproductcollection.php" );
  40  include_once ( "kernel/classes/ezproductcollectionitem.php" );
  41  include_once ( "kernel/classes/datatypes/ezuser/ezuser.php" );
  42  include_once ( "kernel/classes/ezuserdiscountrule.php" );
  43  include_once ( "kernel/classes/ezcontentobjecttreenode.php" );
  44  
  45  class eZWishList extends eZPersistentObject
  46  {
  47      /*!
  48      */
  49      function eZWishList( $row )
  50      {
  51          $this->eZPersistentObject( $row );
  52      }
  53  
  54      /*!
  55       \return the persistent object definition for the eZCard class.
  56      */
  57      function definition()
  58      {
  59          return array( "fields" => array( "id" => array( 'name' => 'ID',
  60                                                          'datatype' => 'integer',
  61                                                          'default' => 0,
  62                                                          'required' => true ),
  63                                           "user_id" => array( 'name' => "UserID",
  64                                                               'datatype' => 'integer',
  65                                                               'default' => 0,
  66                                                               'required' => true,
  67                                                               'foreign_class' => 'eZUser',
  68                                                               'foreign_attribute' => 'contentobject_id',
  69                                                               'multiplicity' => '1..*' ),
  70                                           "productcollection_id" => array( 'name' => "ProductCollectionID",
  71                                                                            'datatype' => 'integer',
  72                                                                            'default' => 0,
  73                                                                            'required' => true,
  74                                                                            'foreign_class' => 'eZProductCollection',
  75                                                                           'foreign_attribute' => 'id',
  76                                                                           'multiplicity' => '1..*' ) ),
  77                        "keys" => array( "id" ),
  78                        'function_attributes' => array( 'items' => 'items' ),
  79                        "increment_key" => "id",
  80                        "class_name" => "eZWishList",
  81                        "name" => "ezwishlist" );
  82      }
  83  
  84  
  85      function discountPercent()
  86      {
  87          $discountPercent = 0;
  88          $user =& eZUser::currentUser();
  89          $userID = $user->attribute( 'contentobject_id' );
  90          $nodes = eZContentObjectTreeNode::fetchByContentObjectID( $userID );
  91          $idArray = array();
  92          $idArray[] = $userID;
  93          foreach ( $nodes as $node )
  94          {
  95              $parentNodeID = $node->attribute( 'parent_node_id' );
  96              $idArray[] = $parentNodeID;
  97          }
  98          $rules = eZUserDiscountRule::fetchByUserIDArray( $idArray );
  99          foreach ( $rules as $rule )
 100          {
 101              $percent = $rule->attribute( 'discount_percent' );
 102              if ( $discountPercent < $percent )
 103                  $discountPercent = $percent;
 104          }
 105          return $discountPercent;
 106      }
 107  
 108      function itemCount( $alternativeProductionID = false )
 109      {
 110          $custom = array( array( 'operation' => 'count( id )',
 111                                  'name' => 'count' ) );
 112          $countRes = eZPersistentObject::fetchObjectList( eZProductCollectionItem::definition(),
 113                                                         array(),
 114                                                         array( "productcollection_id" => ( $alternativeProductionID === false )? $this->ProductCollectionID: $alternativeProductionID ),
 115                                                         null,
 116                                                         null,
 117                                                         false,
 118                                                         false,
 119                                                         $custom );
 120          return $countRes[0]['count'];
 121      }
 122  
 123      function &items( $asObject = true, $alternativeProductionID = false, $offset = false, $limit = false )
 124      {
 125          $productItems = eZPersistentObject::fetchObjectList( eZProductCollectionItem::definition(),
 126                                                         null,
 127                                                         array( 'productcollection_id' => ( $alternativeProductionID === false )? $this->ProductCollectionID: $alternativeProductionID ),
 128                                                         null,
 129                                                         array( 'offset' => $offset,
 130                                                                'length' => $limit ),
 131                                                         $asObject );
 132  //        $discountPercent = $this->discountPercent();
 133          $addedProducts = array();
 134          foreach ( $productItems as  $productItem )
 135          {
 136              $discountPercent = 0.0;
 137              $isVATIncluded = true;
 138              $id = $productItem->attribute( 'id' );
 139              $contentObject = $productItem->attribute( 'contentobject' );
 140  
 141              if ( $contentObject !== null )
 142              {
 143                  $vatValue = $productItem->attribute( 'vat_value' );
 144                  $count = $productItem->attribute( 'item_count' );
 145                  $discountPercent = $productItem->attribute( 'discount' );
 146                  $nodeID = $contentObject->attribute( 'main_node_id' );
 147                  $objectName = $contentObject->attribute( 'name' );
 148  
 149                  $isVATIncluded = $productItem->attribute( 'is_vat_inc' );
 150                  $price = $productItem->attribute( 'price' );
 151  
 152                  if ( $isVATIncluded )
 153                  {
 154                      $priceExVAT = $price / ( 100 + $vatValue ) * 100;
 155                      $priceIncVAT = $price;
 156                  }
 157                  else
 158                  {
 159                      $priceExVAT = $price;
 160                      $priceIncVAT = $price * ( 100 + $vatValue ) / 100;
 161                  }
 162  
 163                  $totalPriceExVAT = $count * $priceExVAT  * ( 100 - $discountPercent ) / 100;
 164                  $totalPriceIncVAT = $count * $priceIncVAT * ( 100 - $discountPercent ) / 100 ;
 165  
 166                  $addedProduct = array( "id" => $id,
 167                                         "vat_value" => $vatValue,
 168                                         "item_count" => $count,
 169                                         "node_id" => $nodeID,
 170                                         "object_name" => $objectName,
 171                                         "price_ex_vat" => $priceExVAT,
 172                                         "price_inc_vat" => $priceIncVAT,
 173                                         "discount_percent" => $discountPercent,
 174                                         "total_price_ex_vat" => $totalPriceExVAT,
 175                                         "total_price_inc_vat" => $totalPriceIncVAT,
 176                                         'item_object' =>$productItem );
 177                  $addedProducts[] = $addedProduct;
 178              }
 179          }
 180          return $addedProducts;
 181      }
 182  
 183      /*!
 184       \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
 185       the calls within a db transaction; thus within db->begin and db->commit.
 186       */
 187      function removeItem( $itemID )
 188      {
 189          $item = eZProductCollectionItem::fetch( $itemID );
 190          $item->remove();
 191      }
 192  
 193      /*!
 194       Will return the wish list for the current user. If a wish list does not exist one will be created.
 195       \return current eZWishList object
 196       \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
 197       the calls within a db transaction; thus within db->begin and db->commit.
 198      */
 199      function &currentWishList( $asObject=true )
 200      {
 201          $http =& eZHTTPTool::instance();
 202  
 203          $user =& eZUser::currentUser();
 204          $userID = $user->attribute( 'contentobject_id' );
 205          $WishListArray = eZPersistentObject::fetchObjectList( eZWishList::definition(),
 206                                                            null, array( "user_id" => $userID
 207                                                                         ),
 208                                                            null, null,
 209                                                            $asObject );
 210  
 211          $currentWishList = false;
 212          if ( count( $WishListArray ) == 0 )
 213          {
 214              $collection = eZProductCollection::create();
 215              $collection->store();
 216  
 217              $currentWishList = new eZWishList( array( "user_id" => $userID,
 218                                                "productcollection_id" => $collection->attribute( "id" ) ) );
 219              $currentWishList->store();
 220          }
 221          else
 222          {
 223              $currentWishList =& $WishListArray[0];
 224          }
 225          return $currentWishList;
 226      }
 227  
 228      /*!
 229       \static
 230       Removes all wishlists from the database.
 231       \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
 232       the calls within a db transaction; thus within db->begin and db->commit.
 233      */
 234      function cleanup()
 235      {
 236          $db =& eZDB::instance();
 237          $db->begin();
 238          $rows = $db->arrayQuery( "SELECT productcollection_id FROM ezwishlist" );
 239          if ( count( $rows ) > 0 )
 240          {
 241              $productCollectionIDList = array();
 242              foreach ( $rows as $row )
 243              {
 244                  $productCollectionIDList[] = $row['productcollection_id'];
 245              }
 246              eZProductCollection::cleanupList( $productCollectionIDList );
 247          }
 248          $db->query( "DELETE FROM ezwishlist" );
 249          $db->commit();
 250      }
 251  }
 252  
 253  ?>


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