Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezcartitem.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezcartitem.php 9407 2002-04-10 11:49:02Z br $
5 //
6 // Definition of eZCartItem class
7 //
8 // Created on: <27-Sep-2000 15:19:05 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 //
28
31
47 // include_once( "classes/ezdb.php" );
48 // include_once( "eztrade/classes/ezcartoptionvalue.php" );
49
50 // include_once( "eztrade/classes/ezwishlistitem.php" );
51 // include_once( "eztrade/classes/ezproduct.php" );
52 // include_once( "eztrade/classes/ezpricegroup.php" );
53 // include_once( "eztrade/classes/ezvoucherinformation.php" );
54
55 class eZCartItem
56 {
63 function __construct( $id="" )
64 {
65 $this->VoucherInformationID = 0;
66 $this->WishListItemID = 0;
67
68 if ( $id != "" )
69 {
70 $this->ID = $id;
71 $this->get( $this->ID );
72 }
73 else
74 {
75 $this->Count = 1;
76 }
77 }
78
82 function store()
83 {
84 $db =& eZDB::globalDatabase();
85 $db->begin();
86
87 if ( !isset( $this->ID ) )
88 {
89 $db->lock( "eZTrade_CartItem" );
90 $nextID = $db->nextID( "eZTrade_CartItem", "ID" );
91 $query = "INSERT INTO eZTrade_CartItem
92 ( ID, ProductID, CartID, Count, WishListItemID, VoucherInformationID )
93 VALUES
94 ( '$nextID',
95 '$this->ProductID',
96 '$this->CartID',
97 '$this->Count',
98 '$this->WishListItemID',
99 '$this->VoucherInformationID' )
100 ";
101 $res = $db->query( $query );
102 $db->unlock();
103
104 $this->ID = $nextID;
105 }
106 else
107 {
108 $res = $db->query( "UPDATE eZTrade_CartItem SET
109 ProductID='$this->ProductID',
110 CartID='$this->CartID',
111 Count='$this->Count',
112 WishListItemID='$this->WishListItemID',
113 VoucherInformationID='$this->VoucherInformationID'
114 WHERE ID='$this->ID'
115 " );
116 }
117
118 if ( $res == false )
119 $db->rollback( );
120 else
121 $db->commit();
122
123 return true;
124 }
125
129 function get( $id="" )
130 {
131 $db =& eZDB::globalDatabase();
132 $ret = false;
133
134 if ( $id != "" )
135 {
136 $db->array_query( $cart_array, "SELECT * FROM eZTrade_CartItem WHERE ID='$id'" );
137 if ( count( $cart_array ) > 1 )
138 {
139 die( "Error: Cart's with the same ID was found in the database. This shouldent happen." );
140 }
141 else if( count( $cart_array ) == 1 )
142 {
143 $this->ID = $cart_array[0][$db->fieldName( "ID" )];
144 $this->ProductID = $cart_array[0][$db->fieldName( "ProductID" )];
145 $this->CartID = $cart_array[0][$db->fieldName( "CartID" )];
146 $this->Count = $cart_array[0][$db->fieldName( "Count" )];
147 $this->WishListItemID = $cart_array[0][$db->fieldName( "WishListItemID" )];
148 $this->VoucherInformationID = $cart_array[0][$db->fieldName( "VoucherInformationID" )];
149 $ret = true;
150 }
151 }
152 return $ret;
153 }
154
159 function delete()
160 {
161 $db =& eZDB::globalDatabase();
162 $db->begin();
163
164 $res[] = $db->query( "DELETE FROM eZTrade_CartOptionValue WHERE CartItemID='$this->ID'" );
165
166 $res[] = $db->query( "DELETE FROM eZTrade_CartItem WHERE ID='$this->ID'" );
167
168 if ( in_array( false, $res ) )
169 $db->rollback( );
170 else
171 $db->commit();
172
173 return true;
174 }
175
179 function id()
180 {
181 return $this->ID;
182 }
183
188 function &product()
189 {
190 $ret = false;
191
192 $prod = new eZProduct( );
193 if ( $prod->get( $this->ProductID ) )
194 {
195 $ret = $prod;
196 }
197
198 return $ret;
199 }
200
204 function cart()
205 {
206 $ret = false;
207
208 $cart = new eZCart( );
209 if ( $cart->get( $this->CartID ) )
210 {
211 $ret = $cart;
212 }
213
214 return $ret;
215 }
216
220 function count( )
221 {
222 return $this->Count;
223 }
224
228 function localePrice( $calcCount=true, $withOptions=true, $calcVAT = false, $withPriceGroups=true )
229 {
230 $ini =& eZINI::instance( 'site.ini' );
231 $inLanguage = $ini->variable( "eZTradeMain", "Language" );
232
233 $locale = new eZLocale( $inLanguage );
234 $currency = new eZCurrency();
235
236 $price = $this->correctPrice( $calcCount, $withOptions, $calcVAT, $withPriceGroups );
237
238 $currency->setValue( $price );
239 return $locale->format( $currency );
240 }
241
246 function correctPrice( $calcCount=true, $withOptions=true, $calcVAT = false, $withPriceGroups=true )
247 {
248 $optionValues =& $this->optionValues();
249 $product =& $this->product();
250
251 $optionPrice = 0.0;
252 if ( $withOptions )
253 {
254 foreach ( $optionValues as $optionValue )
255 {
256 $option =& $optionValue->option();
257 $value =& $optionValue->optionValue();
258
259 $price = $value->correctPrice( $calcVAT, $product, $withPriceGroups );
260
261 if ( $calcCount == true )
262 $price = $price * $optionValue->count();
263
264 $optionPrice+=$price;
265 }
266 }
267
268 if ( $calcCount == true )
269 {
270 $price = ( $product->correctPrice( $calcVAT, $withPriceGroups ) * $this->count() ) + $optionPrice;
271 }
272 else
273 {
274 $price = ( $product->correctPrice( $calcVAT, $withPriceGroups ) + $optionPrice );
275 }
276
277 $voucherInfo =& $this->voucherInformation();
278
279 if ( $voucherInfo )
280 {
281 if ( $calcCount == true )
282 {
283 $price = ( $voucherInfo->correctPrice( $calcVAT, $product ) * $this->count() ) + $optionPrice;
284 }
285 else
286 {
287 $price = ( $voucherInfo->correctPrice( $calcVAT, $product ) + $optionPrice );
288 }
289 }
290
291 return $price;
292 }
293
297 function localeSavings( $calcCount=true, $withOptions=true, $calcVAT = false )
298 {
299 $ini =& eZINI::instance( 'site.ini' );
300 $inLanguage = $ini->variable( "eZTradeMain", "Language" );
301
302 $locale = new eZLocale( $inLanguage );
303 $currency = new eZCurrency();
304
305 $price = $this->correctSavings( $calcCount, $withOptions, $calcVAT );
306
307 $currency->setValue( $price );
308 return $locale->format( $currency );
309 }
310
315 function correctSavings( $calcCount=true, $withOptions=true, $calcVAT = false )
316 {
317 $optionValues =& $this->optionValues();
318 $product =& $this->product();
319
320 $optionPrice = 0.0;
321 if ( $withOptions )
322 {
323 foreach ( $optionValues as $optionValue )
324 {
325 $option =& $optionValue->option();
326 $value =& $optionValue->optionValue();
327
328 $price = $value->correctSavings( $calcVAT, $product );
329
330 if ( $calcCount == true )
331 $price = $price * $optionValue->count();
332
333 $optionPrice+=$price;
334 }
335 }
336
337 if ( $calcCount == true )
338 {
339 $price = ( $product->correctSavings( $calcVAT ) * $this->count() ) + $optionPrice;
340 }
341 else
342 {
343 $price = ( $product->correctSavings( $calcVAT ) + $optionPrice );
344 }
345
346 return $price;
347 }
348
354 function price( $calcCount=true, $withOptions=true )
355 {
356 $optionValues =& $this->optionValues();
357 $product =& $this->product();
358
359 $optionPrice = 0.0;
360 if ( $withOptions )
361 {
362 foreach ( $optionValues as $optionValue )
363 {
364 $option =& $optionValue->option();
365 $value =& $optionValue->optionValue();
366
367 // the pricegroup is set in the datasupplier
368
369 $PriceGroup = $GLOBALS["PriceGroup"];
370
371 // get the value price if exists
372 $price = eZPriceGroup::correctPrice( $product->id(), $PriceGroup,
373 $option->id(), $value->id() );
374
375 $found_price = false;
376
377 if ( $price )
378 {
379 $found_price = true;
380 }
381
382 // if not fetch the standard price
383 if ( !$found_price )
384 {
385 if ( $calcCount == true )
386 $price = $value->price() * $optionValue->count();
387 else
388 $price = $value->price();
389 }
390
391 $optionPrice += $price;
392 }
393 }
394
395 if ( $calcCount == true )
396 {
397 $price = ( $product->price() * $this->count() ) + $optionPrice;
398 }
399 else
400 {
401 $price = ( $product->price() + $optionPrice );
402 }
403 return $price;
404 }
405
409 function vat( $calcCount=true, $withOptions=true )
410 {
411 $vat = $this->correctPrice( $calcCount, $withOptions, true ) -
412 $this->correctPrice( $calcCount, $withOptions, false );
413 return $vat;
414 }
415
419 function setProduct( $product )
420 {
421 if ( is_a( $product, "eZProduct" ) )
422 {
423 $this->ProductID = $product->id();
424 }
425 }
426
430 function setCart( $cart )
431 {
432 if ( is_a( $cart, "eZCart" ) )
433 {
434 $this->CartID = $cart->id();
435 }
436 }
437
441 function setCount( $count )
442 {
443 $this->Count = $count;
444 }
445
449 function setVoucherInformation( $value )
450 {
451 if ( is_a ( $value, "eZVoucherInformation" ) )
452 {
453 $this->VoucherInformationID = $value->id();
454 }
455 else if ( is_numeric ( $value ) )
456 {
457 $this->VoucherInformationID = $value;
458 }
459 }
460
464 function mail( $asObject=true )
465 {
466 if ( $asObject )
467 {
468 if ( $this->MailMethod == 1 )
469 $ret = new eZOnline( $this->MailID );
470 else if ( $this->MailID == 2 )
471 $ret = new eZAddress( $this->MailID );
472 }
473 else
474 $ret = $this->MailID;
475 return $ret;
476 }
477
481 function setWishListItem( $wishlist )
482 {
483 if ( is_a( $wishlist, "eZWishListItem" ) )
484 {
485 $this->WishListItemID = $wishlist->id();
486 }
487 }
488
492 function &wishListItem()
493 {
494 $ret = false;
495
496 if ( ( $this->WishListItemID != 0 ) && is_numeric( $this->WishListItemID ) )
497 {
498 $ret = new eZWishListItem( $this->WishListItemID );
499 }
500
501 return $ret;
502 }
503
507 function &voucherInformation()
508 {
509 $ret = false;
510
511 if ( ( $this->VoucherInformationID != 0 ) && is_numeric( $this->VoucherInformationID ) )
512 {
513 $ret = new eZVoucherInformation( $this->VoucherInformationID );
514 }
515
516 return $ret;
517 }
518
524 function &optionValues( )
525 {
526 $return_array = array();
527 $db =& eZDB::globalDatabase();
528
529 $db->array_query( $res_array, "SELECT ID FROM eZTrade_CartOptionValue
530 WHERE
531 CartItemID='$this->ID'
532 " );
533
534 foreach ( $res_array as $item )
535 {
536 $return_array[] = new eZCartOptionValue( $item[$db->fieldName( "ID" )] );
537 }
538 return $return_array;
539 }
540
541 var $ID;
542 var $ProductID;
543 var $CartID;
544 var $Count;
545 var $VoucherInformationID;
546
548 var $WishListItemID;
549 }
550
551 ?>
$locale
$locale
Definition: admin/adlist.php:127
$cart
$cart
Definition: buy.php:27
eZAddress
Definition: ezaddress.php:42
eZCartItem
Definition: ezcartitem.php:56
eZCartItem\$ID
$ID
Definition: ezcartitem.php:541
eZCartItem\price
price( $calcCount=true, $withOptions=true)
Definition: ezcartitem.php:354
eZCartItem\$WishListItemID
$WishListItemID
ID to a wishlist item. Indicates which wishlistitem the cart item comes from. 0 if added from product...
Definition: ezcartitem.php:548
eZCartItem\voucherInformation
& voucherInformation()
Definition: ezcartitem.php:507
eZCartItem\$VoucherInformationID
$VoucherInformationID
Definition: ezcartitem.php:545
eZCartItem\localeSavings
localeSavings( $calcCount=true, $withOptions=true, $calcVAT=false)
Definition: ezcartitem.php:297
eZCartItem\store
store()
Definition: ezcartitem.php:82
eZCartItem\optionValues
& optionValues()
Definition: ezcartitem.php:524
eZCartItem\vat
vat( $calcCount=true, $withOptions=true)
Definition: ezcartitem.php:409
eZCartItem\mail
mail( $asObject=true)
Definition: ezcartitem.php:464
eZCartItem\localePrice
localePrice( $calcCount=true, $withOptions=true, $calcVAT=false, $withPriceGroups=true)
Definition: ezcartitem.php:228
eZCartItem\wishListItem
& wishListItem()
Definition: ezcartitem.php:492
eZCartItem\$CartID
$CartID
Definition: ezcartitem.php:543
eZCartItem\correctSavings
correctSavings( $calcCount=true, $withOptions=true, $calcVAT=false)
Definition: ezcartitem.php:315
eZCartItem\setWishListItem
setWishListItem( $wishlist)
Definition: ezcartitem.php:481
eZCartItem\setVoucherInformation
setVoucherInformation( $value)
Definition: ezcartitem.php:449
eZCartItem\$Count
$Count
Definition: ezcartitem.php:544
eZCartItem\setProduct
setProduct( $product)
Definition: ezcartitem.php:419
eZCartItem\count
count()
Definition: ezcartitem.php:220
eZCartItem\setCart
setCart( $cart)
Definition: ezcartitem.php:430
eZCartItem\id
id()
Definition: ezcartitem.php:179
eZCartItem\$ProductID
$ProductID
Definition: ezcartitem.php:542
eZCartItem\__construct
__construct( $id="")
Definition: ezcartitem.php:63
eZCartItem\setCount
setCount( $count)
Definition: ezcartitem.php:441
eZCartItem\correctPrice
correctPrice( $calcCount=true, $withOptions=true, $calcVAT=false, $withPriceGroups=true)
Definition: ezcartitem.php:246
eZCartItem\cart
cart()
Definition: ezcartitem.php:204
eZCartItem\product
& product()
Definition: ezcartitem.php:188
eZCartOptionValue
Definition: ezcartoptionvalue.php:43
eZCart
Definition: ezcart.php:71
eZCurrency
Definition: ezcurrency.php:46
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZLocale
Definition: ezlocale.php:119
eZPriceGroup\correctPrice
static correctPrice( $productid, $priceid, $optionid=0, $valueid=0)
Definition: ezpricegroup.php:414
eZProduct
Definition: ezproduct.php:71
eZVoucherInformation
Definition: ezvoucherinformation.php:55
eZWishListItem
Definition: ezwishlistitem.php:55
$ini
$ini
Definition: classes/admin/linklist.php:64
$item
$item
Definition: classes/admin/linklist.php:228
$id
$id
Definition: companytypelist.php:193
$currency
$currency
Definition: companyview.php:529
$wishlist
$wishlist
Definition: customerview.php:149
$query
if(isset( $Year) &&!is_numeric( $Year)||isset( $Month) &&!is_numeric( $Month)) $query
Definition: entryexitpages.php:65
$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
$vat
foreach( $categoryArray as $catItem) $vat
Definition: productedit.php:1334
$PriceGroup
$PriceGroup
Definition: productedit.php:1073
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.