Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezwishlistitem.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezwishlistitem.php 7465 2001-09-26 07:09:33Z ce $
5 //
6 // Definition of eZWishItem class
7 //
8 // Created on: <21-Oct-2000 18:08:30 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
30
46 // include_once( "classes/ezdb.php" );
47
48 // include_once( "eztrade/classes/ezwishlistoptionvalue.php" );
49 // include_once( "eztrade/classes/ezproduct.php" );
50 // include_once( "eztrade/classes/ezcartitem.php" );
51 // include_once( "eztrade/classes/ezcart.php" );
52
53
54 class eZWishListItem
55 {
62 function __construct( $id="", $fetch=true )
63 {
64 $this->IsBought = 0;
65
66 if ( $id != "" )
67 {
68 $this->ID = $id;
69 $this->get( $this->ID );
70 }
71 else
72 {
73 $this->Count = 1;
74 }
75 }
76
80 function store()
81 {
82 $db =& eZDB::globalDatabase();
83 $db->begin();
84
85 if ( !isset( $this->ID ) )
86 {
87 $db->lock( "eZTrade_WishListItem" );
88 $nextID = $db->nextID( "eZTrade_WishListItem", "ID" );
89
90 $res = $db->query( "INSERT INTO eZTrade_WishListItem
91 ( ID, ProductID, WishListID, Count, IsBought )
92 VALUES
93 ( '$nextID',
94 '$this->ProductID',
95 '$this->WishListID',
96 '$this->Count',
97 '$this->IsBought' )
98 " );
99 $db->unlock();
100 $this->ID = $nextID;
101 }
102 else
103 {
104 $res = $db->query( "UPDATE eZTrade_WishListItem SET
105 ProductID='$this->ProductID',
106 WishListID='$this->WishListID',
107 Count='$this->Count',
108 IsBought='$this->IsBought'
109 WHERE ID='$this->ID'
110 " );
111 }
112
113 if ( $res == false )
114 $db->rollback( );
115 else
116 $db->commit();
117
118 return true;
119 }
120
124 function get( $id="" )
125 {
126 $db =& eZDB::globalDatabase();
127 $ret = false;
128
129 if ( $id != "" )
130 {
131 $db->array_query( $wishlist_array, "SELECT * FROM eZTrade_WishListItem WHERE ID='$id'" );
132 if ( count( $wishlist_array ) > 1 )
133 {
134 die( "Error: Wishlist's with the same ID was found in the database. This shouldent happen." );
135 }
136 else if( count( $wishlist_array ) == 1 )
137 {
138 $this->ID = $wishlist_array[0][$db->fieldName( "ID" )];
139 $this->ProductID = $wishlist_array[0][$db->fieldName( "ProductID" )];
140 $this->WishListID = $wishlist_array[0][$db->fieldName( "WishListID" )];
141 $this->Count = $wishlist_array[0][$db->fieldName( "Count" )];
142 $this->IsBought = $wishlist_array[0][$db->fieldName( "IsBought" )];
143 $ret = true;
144 }
145 }
146 return $ret;
147 }
148
153 function delete()
154 {
155 $db =& eZDB::globalDatabase();
156 $db->begin();
157
158 $res[] = $db->query( "DELETE FROM eZTrade_WishListOptionValue WHERE WishListItemID='$this->ID'" );
159
160 $res[] = $db->query( "DELETE FROM eZTrade_WishListItem WHERE ID='$this->ID'" );
161
162 if ( in_array( false, $res ) )
163 $db->rollback( );
164 else
165 $db->commit();
166
167 return true;
168 }
169
173 function id()
174 {
175 return $this->ID;
176 }
177
182 function &product()
183 {
184 $ret = false;
185
186 $prod = new eZProduct( );
187 if ( $prod->get( $this->ProductID ) )
188 {
189 $ret = $prod;
190 }
191
192 return $ret;
193 }
194
198 function &wishlist()
199 {
200 $ret = false;
201
202 $wishlist = new eZWishList( );
203 if ( $wishlist->get( $this->WishListID ) )
204 {
205 $ret = $wishlist;
206 }
207
208 return $ret;
209 }
210
214 function count( )
215 {
216 return $this->Count;
217 }
218
222 function setProduct( $product )
223 {
224 if ( is_a( $product, "eZProduct" ) )
225 {
226 $this->ProductID = $product->id();
227 }
228 }
229
233 function setWishList( $wishlist )
234 {
235 if ( is_a( $wishlist, "eZWishList" ) )
236 {
237 $this->WishListID = $wishlist->id();
238 }
239 }
240
246 function setIsBought( $value )
247 {
248 if ( $value == true )
249 {
250 $this->IsBought = 1;
251 }
252 else
253 {
254 $this->IsBought = 0;
255 }
256 }
257
261 function isBought()
262 {
263 $ret = false;
264
265 if ( $this->IsBought == 1 )
266 {
267 $ret = true;
268 }
269
270 return $ret;
271 }
272
278 function &optionValues( )
279 {
280 $return_array = array();
281 $db =& eZDB::globalDatabase();
282
283 $db->array_query( $res_array, "SELECT ID FROM eZTrade_WishListOptionValue
284 WHERE
285 WishListItemID='$this->ID'
286 " );
287
288 foreach ( $res_array as $item )
289 {
290 $return_array[] = new eZWishListOptionValue( $item[$db->fieldName( "ID" )] );
291 }
292 return $return_array;
293 }
294
298 function moveToCart()
299 {
300 // fetch the cart or create one
301 $cart = new eZCart();
302 $session = new eZSession();
303
304 // if no session exist create one.
305 if ( !$session->fetch() )
306 {
307 $session->store();
308 }
309
310 $user =& eZUser::currentUser();
311
312 $cart = $cart->getBySession( $session );
313
314 if ( !$cart )
315 {
316 $cart = new eZCart();
317 $cart->setSession( $session );
318
319 $cart->store();
320 }
321
322 $product = $this->product();
323
324 $cartItem = new eZCartItem();
325
326 $cartItem->setProduct( $product );
327 $cartItem->setCart( $cart );
328
329 // set the wishlist item
330 $cartItem->setWishListItem( $this );
331
332 $cartItem->store();
333
334 $optionValues = $this->optionValues();
335
336
337 if ( count( $optionValues ) > 0 )
338 {
339 foreach ( $optionValues as $value )
340 {
341 $cartOption = new eZCartOptionValue();
342 $cartOption->setCartItem( $cartItem );
343
344 $cartOption->setOption( $value->option() );
345 $cartOption->setOptionValue( $value->optionValue() );
346
347 $cartOption->store();
348 }
349 }
350
351 }
352
356 function setCount( $count )
357 {
358 if ( isset( $this->State_ ) && $this->State_ == "Dirty" )
359 $this->get( $this->ID );
360
361 $this->Count = $count;
362 }
363
364
370 function price()
371 {
372 $optionValues =& $this->optionValues();
373 $product =& $this->product();
374
375 $optionPrice = 0.0;
376 foreach ( $optionValues as $optionValue )
377 {
378 $option =& $optionValue->option();
379 $value =& $optionValue->optionValue();
380
381 // the pricegroup is set in the datasupplier
382
383 $PriceGroup = $GLOBALS["PriceGroup"];
384
385 // get the value price if exists
386 $price = eZPriceGroup::correctPrice( $product->id(), $PriceGroup, $option->id(), $value->id() );
387
388 $found_price = false;
389
390 if ( $price )
391 {
392 $found_price = true;
393 }
394
395 // if not fetch the standard price
396 if ( !$found_price )
397 {
398 $price = $value->price();
399 }
400
401 $optionPrice += $price;
402 }
403
404 $price = ( $product->price() + $optionPrice ) * $this->count();
405
406 return $price;
407 }
408
409 var $ID;
410 var $ProductID;
411 var $WishListID;
412 var $Count;
413 var $IsBought;
414 }
415 ?>
$session
$session
Definition: admin/articlelist.php:44
$cart
$cart
Definition: buy.php:27
eZCartItem
Definition: ezcartitem.php:56
eZCartOptionValue
Definition: ezcartoptionvalue.php:43
eZCart
Definition: ezcart.php:71
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZPriceGroup\correctPrice
static correctPrice( $productid, $priceid, $optionid=0, $valueid=0)
Definition: ezpricegroup.php:414
eZProduct
Definition: ezproduct.php:71
eZSession
Definition: lib/ezsession/classes/ezsession.php:65
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
eZWishListItem
Definition: ezwishlistitem.php:55
eZWishListItem\setCount
setCount( $count)
Definition: ezwishlistitem.php:356
eZWishListItem\$Count
$Count
Definition: ezwishlistitem.php:412
eZWishListItem\$ID
$ID
Definition: ezwishlistitem.php:409
eZWishListItem\isBought
isBought()
Definition: ezwishlistitem.php:261
eZWishListItem\wishlist
& wishlist()
Definition: ezwishlistitem.php:198
eZWishListItem\optionValues
& optionValues()
Definition: ezwishlistitem.php:278
eZWishListItem\product
& product()
Definition: ezwishlistitem.php:182
eZWishListItem\price
price()
Definition: ezwishlistitem.php:370
eZWishListItem\$IsBought
$IsBought
Definition: ezwishlistitem.php:413
eZWishListItem\count
count()
Definition: ezwishlistitem.php:214
eZWishListItem\setWishList
setWishList( $wishlist)
Definition: ezwishlistitem.php:233
eZWishListItem\store
store()
Definition: ezwishlistitem.php:80
eZWishListItem\$ProductID
$ProductID
Definition: ezwishlistitem.php:410
eZWishListItem\setProduct
setProduct( $product)
Definition: ezwishlistitem.php:222
eZWishListItem\moveToCart
moveToCart()
Definition: ezwishlistitem.php:298
eZWishListItem\id
id()
Definition: ezwishlistitem.php:173
eZWishListItem\__construct
__construct( $id="", $fetch=true)
Definition: ezwishlistitem.php:62
eZWishListItem\setIsBought
setIsBought( $value)
Definition: ezwishlistitem.php:246
eZWishListItem\$WishListID
$WishListID
Definition: ezwishlistitem.php:411
eZWishListOptionValue
Definition: ezwishlistoptionvalue.php:42
eZWishList
Definition: ezwishlist.php:63
$item
$item
Definition: classes/admin/linklist.php:228
$id
$id
Definition: companytypelist.php:193
$wishlist
$wishlist
Definition: customerview.php:149
$db
$db
Definition: ezarticle/user/authorlist.php:53
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$product
$product
Definition: homepage.php:202
$count
$count
Definition: onlinetypelist.php:108
$price
$price
Definition: pricegroupedit.php:39
$PriceGroup
$PriceGroup
Definition: productedit.php:1073
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.