[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

/kernel/shop/ -> wishlist.php (source)

   1  <?php
   2  //
   3  // Created on: <01-Aug-2002 09:58:09 bf>
   4  //
   5  // SOFTWARE NAME: eZ publish
   6  // SOFTWARE RELEASE: 3.9.0
   7  // BUILD VERSION: 17785
   8  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
   9  // SOFTWARE LICENSE: GNU General Public License v2.0
  10  // NOTICE: >
  11  //   This program is free software; you can redistribute it and/or
  12  //   modify it under the terms of version 2.0  of the GNU General
  13  //   Public License as published by the Free Software Foundation.
  14  //
  15  //   This program is distributed in the hope that it will be useful,
  16  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  17  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18  //   GNU General Public License for more details.
  19  //
  20  //   You should have received a copy of version 2.0 of the GNU General
  21  //   Public License along with this program; if not, write to the Free
  22  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  23  //   MA 02110-1301, USA.
  24  //
  25  //
  26  
  27  include_once ( "kernel/classes/ezwishlist.php" );
  28  
  29  $http =& eZHTTPTool::instance();
  30  $module =& $Params["Module"];
  31  $offset = $Params['Offset'];
  32  
  33  $user =& eZUser::currentUser();
  34  if ( !$user->isLoggedIn() )
  35      return $Module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
  36  
  37  if ( $http->hasPostVariable( "ActionAddToWishList" ) )
  38  {
  39      $objectID = $http->postVariable( "ContentObjectID" );
  40      $object = eZContentObject::fetch( $objectID );
  41      if ( $http->hasPostVariable( 'eZOption' ) )
  42          $optionList = $http->postVariable( 'eZOption' );
  43      else
  44          $optionList = array();
  45  
  46      //$price = 0.0;
  47      //$isVATIncluded = true;
  48      //$attributes = $object->contentObjectAttributes();
  49      //foreach ( $attributes as $attribute )
  50      //{
  51      //    $dataType = $attribute->dataType();
  52      //
  53      //    if ( $dataType->isA() == "ezprice" )
  54      //    {
  55      //        $content =& $attribute->content();
  56      //        $price += $content->attribute( 'price' );
  57      //        $priceObj =& $content;
  58      //    }
  59      //}
  60  
  61      $wishList =& eZWishList::currentWishList();
  62  
  63      /* Find out, if the item with the same options is not already in the wishlist: */
  64      $itemID = false;
  65      $collection = eZProductCollection::fetch( $wishList->attribute( 'productcollection_id' ) );
  66      if ( $collection )
  67      {
  68          $count = 0;
  69          /* Calculate number of options passed via the HTTP variable: */
  70          foreach ( array_keys( $optionList ) as $key )
  71          {
  72              if ( is_array( $optionList[$key] ) )
  73                  $count += count( $optionList[$key] );
  74              else
  75                  $count++;
  76          }
  77          $collectionItems =& $collection->itemList( false );
  78          foreach ( $collectionItems as $item )
  79          {
  80              /* For all items in the wishlist which have the same object_id: */
  81              if ( $item['contentobject_id'] == $objectID )
  82              {
  83                  $options = eZProductCollectionItemOption::fetchList( $item['id'], false );
  84                  /* If the number of option for this item is not the same as in the HTTP variable: */
  85                  if ( count( $options ) != $count )
  86                  {
  87                      break;
  88                  }
  89                  $theSame = true;
  90                  foreach ( $options as $option )
  91                  {
  92                      /* If any option differs, go away: */
  93                      if ( ( is_array( $optionList[$option['object_attribute_id']] ) &&
  94                             !in_array( $option['option_item_id'], $optionList[$option['object_attribute_id']] ) )
  95                        || ( !is_array( $optionList[$option['object_attribute_id']] ) &&
  96                             $option['option_item_id'] != $optionList[$option['object_attribute_id']] ) )
  97                      {
  98                          $theSame = false;
  99                          break;
 100                      }
 101                  }
 102                  if ( $theSame )
 103                  {
 104                      $itemID = $item['id'];
 105                      break;
 106                  }
 107              }
 108          }
 109      }
 110  
 111      if ( $itemID == false )
 112      {
 113          $item = eZProductCollectionItem::create( $wishList->attribute( "productcollection_id" ) );
 114  
 115          $item->setAttribute( 'name', $object->attribute( 'name' ) );
 116          $item->setAttribute( "contentobject_id", $objectID );
 117          $item->setAttribute( "item_count", 1 );
 118          //$item->setAttribute( "price", $price );
 119  
 120  
 121          $db =& eZDB::instance();
 122          $db->begin();
 123  
 124          $item->store();
 125  
 126          //if ( $priceObj->attribute( 'is_vat_included' ) )
 127          //{
 128          //    $item->setAttribute( "is_vat_inc", '1' );
 129          //}
 130          //else
 131          //{
 132          //    $item->setAttribute( "is_vat_inc", '0' );
 133          //}
 134          //$item->setAttribute( "vat_value", $priceObj->attribute( 'vat_percent' ) );
 135          //$item->setAttribute( "discount", $priceObj->attribute( 'discount_percent' ) );
 136          $item->store();
 137          //$priceWithoutOptions = $price;
 138  
 139          $optionIDList = array();
 140          foreach ( array_keys( $optionList ) as $key )
 141          {
 142              $attributeID = $key;
 143              $optionString = $optionList[$key];
 144              if ( is_array( $optionString ) )
 145              {
 146                  foreach ( $optionString as $optionID )
 147                  {
 148                      $optionIDList[] = array( 'attribute_id' => $attributeID,
 149                                               'option_string' => $optionID );
 150                  }
 151              }
 152              else
 153              {
 154                  $optionIDList[] = array( 'attribute_id' => $attributeID,
 155                                           'option_string' => $optionString );
 156              }
 157          }
 158  
 159          foreach ( $optionIDList as $optionIDItem )
 160          {
 161              $attributeID = $optionIDItem['attribute_id'];
 162              $optionString = $optionIDItem['option_string'];
 163  
 164              $attribute = eZContentObjectAttribute::fetch( $attributeID, $object->attribute( 'current_version' ) );
 165              $dataType = $attribute->dataType();
 166              $optionData = $dataType->productOptionInformation( $attribute, $optionString, $item );
 167              if ( $optionData )
 168              {
 169                  $optionItem = eZProductCollectionItemOption::create( $item->attribute( 'id' ), $optionData['id'], $optionData['name'],
 170                  //                                                      $optionData['value'], $optionData['additional_price'], $attributeID );
 171                                                                        $optionData['value'], 0, $attributeID );
 172                  $optionItem->store();
 173                  //$price += $optionData['additional_price'];
 174              }
 175          }
 176          $db->commit();
 177  
 178          //if ( $price != $priceWithoutOptions )
 179          //{
 180          //    $item->setAttribute( "price", $price );
 181          //    $item->store();
 182          //}
 183      }
 184  
 185      $module->redirectTo( $module->functionURI( "wishlist" ) . "/" );
 186      return;
 187  }
 188  
 189  if ( $http->hasPostVariable( "RemoveProductItemButton" ) )
 190  {
 191      $itemList = $http->postVariable( "RemoveProductItemDeleteList" );
 192  
 193      $wishList =& eZWishList::currentWishList();
 194  
 195      $db =& eZDB::instance();
 196      $db->begin();
 197      foreach ( $itemList as $item )
 198      {
 199          $wishList->removeItem( $item );
 200      }
 201      $db->commit();
 202      $module->redirectTo( $module->functionURI( "wishlist" ) . "/" );
 203      return;
 204  }
 205  
 206  if ( $http->hasPostVariable( "StoreChangesButton" ) )
 207  {
 208      $wishList = eZWishList::currentWishList();
 209      $collection = eZProductCollection::fetch( $wishList->attribute( 'productcollection_id' ) );
 210      if ( $collection and $http->hasPostVariable( "ProductItemIDList" ) )
 211      {
 212          $collectionItems =& $collection->itemList();
 213          $productItemIDlist = $http->postVariable( "ProductItemIDList" );
 214          $productItemCountList = $http->hasPostVariable( "ProductItemCountList" ) ? $http->postVariable( "ProductItemCountList" ) : false;
 215          if ( $productItemCountList == false )
 216          {
 217             $module->redirectTo( $module->functionURI( "wishlist" ) . "/" );
 218             return;
 219          }
 220          $productItemsCount = array();
 221          // Create array of productItemID (as index) and productItemCount (as value)
 222          foreach ( $productItemIDlist as $key => $productItemID )
 223          {
 224              if ( isset( $productItemCountList[$key] ) )
 225                  $productItemsCount[$productItemID] = $productItemCountList[$key];
 226          }
 227          $db =& eZDB::instance();
 228          $db->begin();
 229          foreach ( $collectionItems as $item )
 230          {
 231              $itemID = $item->attribute( 'id' );
 232              if ( isset( $productItemsCount[$itemID] ) )
 233              {
 234                  $item->setAttribute( 'item_count', $productItemsCount[$itemID] );
 235                  $item->store();
 236              }
 237          }
 238          $db->commit();
 239          $module->redirectTo( $module->functionURI( "wishlist" ) . "/" );
 240          return;
 241      }
 242  }
 243  include_once ( "kernel/common/template.php" );
 244  
 245  $tpl =& templateInit();
 246  
 247  $wishList =& eZWishList::currentWishList();
 248  
 249  $tpl->setVariable( "wish_list", $wishList );
 250  
 251  $viewParameters = array( 'offset' => $offset );
 252  $tpl->setVariable( 'view_parameters', $viewParameters );
 253  
 254  $Result = array();
 255  $Result['content'] =& $tpl->fetch( "design:shop/wishlist.tpl" );
 256  $Result['path'] = array( array( 'url' => false,
 257                                  'text' => ezi18n( 'kernel/shop', 'Wishlist' ) ) );
 258  
 259  ?>


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