Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

wishlist.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: wishlist.php 8850 2002-01-02 21:42:12Z kaid $
5 //
6 // Created on: <21-Oct-2000 18:09:45 bf>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
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 the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27 // include_once( "classes/INIFile.php" );
28 // include_once( "classes/eztemplate.php" );
29 // include_once( "classes/ezlocale.php" );
30 // include_once( "classes/ezcurrency.php" );
31
32 // include_once( "ezuser/classes/ezuser.php" );
33
34 $ini =& eZINI::instance( 'site.ini' );
35
36 $Language = $ini->variable( "eZTradeMain", "Language" );
37 $ShowQuantity = $ini->variable( "eZTradeMain", "ShowQuantity" ) == "true";
38 $ShowNamedQuantity = $ini->variable( "eZTradeMain", "ShowNamedQuantity" ) == "true";
39 $RequireQuantity = $ini->variable( "eZTradeMain", "RequireQuantity" ) == "true";
40 $ShowOptionQuantity = $ini->variable( "eZTradeMain", "ShowOptionQuantity" ) == "true";
41 $TinyImageWidth = $ini->variable( "eZImageCatalogueMain", "TinyImageWidth" );
42 $TinyImageHeight = $ini->variable( "eZImageCatalogueMain", "TinyImageHeight" );
43
44 // include_once( "eztrade/classes/ezproduct.php" );
45 // include_once( "eztrade/classes/ezoption.php" );
46 // include_once( "eztrade/classes/ezoptionvalue.php" );
47 // include_once( "eztrade/classes/ezproductcategory.php" );
48 // include_once( "eztrade/classes/ezwishlist.php" );
49 // include_once( "eztrade/classes/ezwishlistitem.php" );
50 // include_once( "eztrade/classes/ezwishlistoptionvalue.php" );
51 // include_once( "ezsession/classes/ezsession.php" );
52 // include_once( "ezimagecatalogue/classes/ezimage.php" );
53
54
55 $wishlist = new eZWishList();
56 $session = new eZSession();
57
58 // if no session exist create one.
59 if ( !$session->fetch() )
60 {
61 $session->store();
62 }
63
64
65 // your own wishlist
66 $user =& eZUser::currentUser();
67
68 if ( !$user )
69 {
70 eZHTTPTool::header( "Location: /trade/customerlogin/?RedirectURL=/trade/wishlist/" );
71 exit();
72 }
73
74 $wishlist = $wishlist->getByUser( $user );
75
76
77 if ( !$wishlist )
78 {
79 $wishlist = new eZWishList();
80 $wishlist->setUser( $user );
81
82 $wishlist->store();
83 }
84
85 if ( isset( $Action ) && $Action == "AddToBasket" )
86 {
87 $product = new eZProduct( $ProductID );
88
89 // check if a product like this is already in the basket.
90 // if so-> add the count value.
91 $productAddedToWishlist = false;
92 {
93 // fetch the cart items
94 $items =& $wishlist->items( );
95
96 foreach ( $items as $item )
97 {
98 $productItem =& $item->product();
99 // the same product
100 if ( ( $ProductID == $productItem->id() ) && ( $productAddedToWishlist == false ) )
101 {
102 $optionValues =& $item->optionValues();
103
104 if ( count( $optionValues ) > 0 )
105 { // product with options
106 $hasTheSameOptions = true;
107
108 foreach ( $optionValues as $optionValue )
109 {
110 $option =& $optionValue->option();
111 $value =& $optionValue->optionValue();
112
113 $optionValueFound = false;
114
115 if ( count( $OptionValueArray ) > 0 )
116 {
117 $i=0;
118 foreach ( $OptionValueArray as $valueItem )
119 {
120 if ( ( $OptionIDArray[$i] == $option->id() )
121 && ( $valueItem == $value->id() ) )
122 {
123 $optionValueFound = true;
124 }
125 $i++;
126 }
127 }
128
129 if ( $optionValueFound == false )
130 {
131 $hasTheSameOptions = false;
132 }
133 }
134
135 if ( $hasTheSameOptions == true )
136 {
137 $item->setCount( $item->count() + 1 );
138 $item->store();
139 $productAddedToWishlist = true;
140 }
141 }
142 else
143 { // product without options
144 if ( count( $OptionValueArray ) == 0 )
145 {
146 $item->setCount( $item->count() + 1 );
147 $item->store();
148 $productAddedToWishlist = true;
149 }
150 }
151 }
152 }
153 }
154
155 if ( $productAddedToWishlist == false )
156 {
157 $wishlistItem = new eZWishListItem();
158
159 $wishlistItem->setProduct( $product );
160 $wishlistItem->setWishlist( $wishlist );
161
162 $wishlistItem->store();
163
164 if ( count( $OptionValueArray ) > 0 )
165 {
166 $i = 0;
167 foreach ( $OptionValueArray as $value )
168 {
169
170 $option = new eZOption( $OptionIDArray[$i] );
171 $optionValue = new eZOptionValue( $value );
172
173 $wishlistOption = new eZWishListOptionValue();
174 $wishlistOption->setWishListItem( $wishlistItem );
175 $wishlistOption->setOption( $option );
176 $wishlistOption->setOptionValue( $optionValue );
177
178 $wishlistOption->store();
179
180 $i++;
181 }
182 }
183 }
184
185 eZHTTPTool::header( "Location: /trade/wishlist/" );
186
187 exit();
188 }
189
190
191 if ( isset( $Action ) && $Action == "RemoveFromWishlist" )
192 {
193 $wishListItem = new eZWishListItem( );
194 if ( $wishListItem->get( $WishListItemID ) )
195 {
196 $wishListItem->delete();
197 }
198
199 eZHTTPTool::header( "Location: /trade/wishlist/" );
200
201 exit();
202 }
203
204
205 if ( isset( $Action ) && $Action == "Refresh" )
206 {
207 $i=0;
208 if ( count( $WishlistIDArray ) > 0 )
209 foreach ( $WishlistIDArray as $wishlistID )
210 {
211 $wishlistItem = new eZWishListItem( $wishlistID );
212 $wishlistItem->setCount( $WishlistCountArray[$i] );
213 $wishlistItem->store();
214 $i++;
215 }
216
217 if ( isset( $IsPublicButton ) )
218 {
219 $wishlist->setIsPublic( !$wishlist->isPublic() );
220 $wishlist->store();
221 }
222 else
223 {
224 // set public/private
225 if ( $IsPublic != "" )
226 {
227 $wishlist->setIsPublic( true );
228 $wishlist->store();
229 }
230 else
231 {
232 $wishlist->setIsPublic( false );
233 $wishlist->store();
234 }
235 }
236 }
237
238
239 if ( isset( $Action ) && $Action == "MoveToCart" )
240 {
241 $wishListItem = new eZWishListItem( );
242 if ( $wishListItem->get( $WishListItemID ) )
243 {
244 $product = $wishListItem->product();
245 $Quantity = $product->totalQuantity();
246 if ( !$product->hasPrice() )
247 {
248 $optionValues =& $wishListItem->optionValues();
249 $Quantity = 0;
250 foreach ( $optionValues as $optionValue )
251 {
252 $option =& $optionValue->option();
253 $value =& $optionValue->optionValue();
254 $value_quantity = $value->totalQuantity();
255 if ( $value_quantity > 0 )
256 $Quantity = $value_quantity;
257 }
258 }
259
260 if ( $product->hasQuantity( $RequireQuantity ) )
261 {
262 $wishListItem->moveToCart();
263 $wishListItem->delete();
264 }
265 }
266
267 eZHTTPTool::header( "Location: /trade/cart/" );
268 exit();
269 }
270
271 $t = new eZTemplate( "kernel/eztrade/user/" . $ini->variable( "eZTradeMain", "TemplateDir" ),
272 "kernel/eztrade/user/intl/", $Language, "wishlist.php" );
273
274 $t->setAllStrings();
275
276 $t->set_file( array(
277 "wishlist_page_tpl" => "wishlist.tpl"
278 ) );
279
280
281 $t->set_block( "wishlist_page_tpl", "public_wishlist_tpl", "public_wishlist" );
282 $t->set_block( "wishlist_page_tpl", "non_public_wishlist_tpl", "non_public_wishlist" );
283
284 $t->set_block( "wishlist_page_tpl", "empty_wishlist_tpl", "empty_wishlist" );
285
286 $t->set_block( "wishlist_page_tpl", "wishlist_image_tpl", "wishlist_image" );
287
288
289 $t->set_block( "wishlist_page_tpl", "wishlist_item_list_tpl", "wishlist_item_list" );
290 $t->set_block( "wishlist_item_list_tpl", "product_available_header_tpl", "product_available_header" );
291 $t->set_block( "wishlist_item_list_tpl", "wishlist_item_tpl", "wishlist_item" );
292 $t->set_block( "wishlist_item_tpl", "product_available_item_tpl", "product_available_item" );
293 $t->set_block( "wishlist_item_tpl", "move_to_cart_item_tpl", "move_to_cart_item" );
294 $t->set_block( "wishlist_item_tpl", "no_move_to_cart_item_tpl", "no_move_to_cart_item" );
295 $t->set_block( "wishlist_item_tpl", "wishlist_item_option_tpl", "wishlist_item_option" );
296 $t->set_block( "wishlist_item_option_tpl", "wishlist_item_option_availability_tpl", "wishlist_item_option_availability" );
297
298 $t->set_block( "wishlist_item_tpl", "is_bought_tpl", "is_bought" );
299 $t->set_block( "wishlist_item_tpl", "is_not_bought_tpl", "is_not_bought" );
300
301 $t->set_block( "wishlist_page_tpl", "wishlist_checkout_tpl", "wishlist_checkout" ); //SF
302
303 $t->set_var( "public_wishlist", "" );
304 $t->set_var( "non_public_wishlist", "" );
305 if ( $wishlist->isPublic() == true )
306 {
307 $t->parse( "public_wishlist", "public_wishlist_tpl" );
308 }
309 else
310 {
311 $t->parse( "non_public_wishlist", "non_public_wishlist_tpl" );
312 }
313
314 // fetch the wishlist items
315 $items = $wishlist->items( );
316
317
318
319 $locale = new eZLocale( $Language );
320 $currency = new eZCurrency();
321
322 $t->set_var( "product_available_header", "" );
323 if ( $ShowQuantity )
324 $t->parse( "product_available_header", "product_available_header_tpl" );
325
326 $i = 0;
327 $sum = 0.0;
328 foreach ( $items as $item )
329 {
330 $t->set_var( "td_class", ( $i % 2 ) == 0 ? "bglight" : "bgdark" );
331
332 $product =& $item->product();
333
334 $t->set_var( "wishlist_item_id", $item->id() );
335
336 $image =& $product->thumbnailImage();
337
338 if ( $image )
339 {
340 $thumbnail =& $image->requestImageVariation( $TinyImageWidth, $TinyImageHeight );
341
342 $t->set_var( "product_image_path", "/" . $thumbnail->imagePath() );
343 $t->set_var( "product_image_width", $thumbnail->width() );
344 $t->set_var( "product_image_height", $thumbnail->height() );
345 $t->set_var( "product_image_caption", $image->caption() );
346 $t->parse( "wishlist_image", "wishlist_image_tpl" );
347 }
348 else
349 {
350 $t->set_var( "wishlist_image", "&nbsp;" );
351 }
352
353 if ( $item->isBought() == true )
354 {
355 $t->set_var( "is_not_bought", "" );
356 $t->parse( "is_bought", "is_bought_tpl" );
357 }
358 else
359 {
360 $t->set_var( "is_bought", "" );
361 $t->parse( "is_not_bought", "is_not_bought_tpl" );
362 }
363
364 // product price
365 $price = $item->price();
366 $currency->setValue( $price );
367 $sum += $price;
368
369
370 $t->set_var( "product_id", $product->id() );
371 $t->set_var( "product_name", $product->name() );
372
373 $optionValues =& $item->optionValues();
374
375 $Quantity = $product->totalQuantity();
376 if ( !$product->hasPrice() )
377 {
378 $Quantity = 0;
379 foreach ( $optionValues as $optionValue )
380 {
381 $option =& $optionValue->option();
382 $value =& $optionValue->optionValue();
383 $value_quantity = $value->totalQuantity();
384 if ( $value_quantity > 0 )
385 $Quantity = $value_quantity;
386 }
387 }
388 $t->set_var( "product_available_item", "" );
389 if ( $ShowQuantity )
390 {
391 $NamedQuantity = $Quantity;
392 if ( $ShowNamedQuantity )
393 $NamedQuantity = eZProduct::namedQuantity( $Quantity );
394 $t->set_var( "product_availability", $NamedQuantity );
395 $t->parse( "product_available_item", "product_available_item_tpl" );
396 }
397 $t->set_var( "wishlist_item_count", $item->count() );
398
399 $t->set_var( "product_price", $locale->format( $currency ) );
400
401 $t->set_var( "wishlist_item_option", "" );
402 $min_quantity = $Quantity;
403 foreach ( $optionValues as $optionValue )
404 {
405 $option =& $optionValue->option();
406 $value =& $optionValue->optionValue();
407 $value_quantity = $value->totalQuantity();
408
409 $t->set_var( "option_name", $option->name() );
410
411 $descriptions =& $value->descriptions();
412 if ( count( $descriptions ) > 0 )
413 $t->set_var( "option_value", $descriptions[0] );
414 else
415 $t->set_var( "option_value", $value->option()->name() );
416
417 $t->set_var( "wishlist_item_option_availability", "" );
418 if ( !(is_bool( $value_quantity ) and !$value_quantity) )
419 {
420 if ( is_bool( $min_quantity ) )
421 $min_quantity = $value_quantity;
422 else
423 $min_quantity = min( $min_quantity , $value_quantity );
424 $named_quantity = $value_quantity;
425 if ( $ShowNamedQuantity )
426 $named_quantity = eZProduct::namedQuantity( $value_quantity );
427 if ( $ShowOptionQuantity )
428 {
429 $t->set_var( "option_availability", $named_quantity );
430 $t->parse( "wishlist_item_option_availability", "wishlist_item_option_availability_tpl" );
431 }
432 }
433
434 $t->parse( "wishlist_item_option", "wishlist_item_option_tpl", true );
435 }
436
437 $t->set_var( "move_to_cart_item", "" );
438 $t->set_var( "no_move_to_cart_item", "" );
439 if ( (is_bool( $min_quantity ) and !$min_quantity) or
440 !$RequireQuantity or ( $RequireQuantity and $min_quantity > 0 ) )
441 {
442 $t->parse( "move_to_cart_item", "move_to_cart_item_tpl" );
443 }
444 else
445 {
446 $t->parse( "no_move_to_cart_item", "no_move_to_cart_item_tpl" );
447 }
448
449 $t->parse( "wishlist_item", "wishlist_item_tpl", true );
450
451 $i++;
452 }
453
454
455 $currency->setValue( $sum );
456 $t->set_var( "wishlist_sum", $locale->format( $currency ) );
457
458
459 if ( count( $items ) > 0 )
460 {
461 $t->parse( "wishlist_item_list", "wishlist_item_list_tpl" );
462 $t->set_var( "empty_wishlist", "" );
463 }
464 else
465 {
466 $t->parse( "empty_wishlist", "empty_wishlist_tpl" );
467 $t->set_var( "wishlist_item_list", "" );
468 }
469
470 if ( count( $items ) > 0 )
471 {
472 $t->parse( "wishlist_checkout", "wishlist_checkout_tpl" );
473 }
474 else
475 {
476 $t->set_var( "wishlist_checkout", "" );
477 }
478
479
480 $t->pparse( "output", "wishlist_page_tpl" );
481
482 ?>
483
eZCurrency
Definition: ezcurrency.php:46
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZLocale
Definition: ezlocale.php:119
eZOptionValue
Definition: ezoptionvalue.php:54
eZOption
Definition: ezoption.php:82
eZProduct
Definition: ezproduct.php:71
eZProduct\namedQuantity
static namedQuantity( $quantity)
Definition: ezproduct.php:1037
eZSession
Definition: lib/ezsession/classes/ezsession.php:65
eZTemplate
Definition: eztemplate.php:107
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
eZWishListItem
Definition: ezwishlistitem.php:55
eZWishListOptionValue
Definition: ezwishlistoptionvalue.php:42
eZWishList
Definition: ezwishlist.php:63
$item
$item
Definition: classes/admin/linklist.php:228
$Action
$Action
Definition: companysearch.php:80
$thumbnail
$thumbnail
Definition: ezarticle/admin/imagelist.php:59
exit
exit
Definition: folder.php:81
$product
$product
Definition: homepage.php:202
$price
$price
Definition: pricegroupedit.php:39
$Quantity
if( $product->catalogNumber() !="") $Quantity
Definition: productpreview.php:491
$image
$image
Definition: user/articlelist.php:242
$TinyImageWidth
$TinyImageWidth
Definition: wishlist.php:41
$ShowOptionQuantity
$ShowOptionQuantity
Definition: wishlist.php:40
$currency
$currency
Definition: wishlist.php:320
$locale
$locale
Definition: wishlist.php:319
$t
if(! $wishlist) if(isset( $Action) && $Action=="AddToBasket") if(isset( $Action) && $Action=="RemoveFromWishlist") if(isset( $Action) && $Action=="Refresh") if(isset( $Action) && $Action=="MoveToCart") $t
Definition: wishlist.php:271
$items
$items
Definition: wishlist.php:315
$i
$i
Definition: wishlist.php:326
$Language
$Language
Definition: wishlist.php:36
$ini
$ini
Definition: wishlist.php:34
$sum
$sum
Definition: wishlist.php:327
$user
if(! $session->fetch()) $user
Definition: wishlist.php:66
$TinyImageHeight
$TinyImageHeight
Definition: wishlist.php:42
$ShowNamedQuantity
$ShowNamedQuantity
Definition: wishlist.php:38
$session
$session
Definition: wishlist.php:56
$wishlist
$wishlist
Definition: wishlist.php:55
$ShowQuantity
$ShowQuantity
Definition: wishlist.php:37
$RequireQuantity
$RequireQuantity
Definition: wishlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.