Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

productlist.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: productlist.php 9741 2002-11-21 08:42:39Z vl $
5 //
6 // Created on: <23-Sep-2000 14:46:20 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 // include_once( "classes/eztexttool.php" );
32 // include_once( "classes/ezcachefile.php" );
33 // include_once( "classes/ezlist.php" );
34
35 // include_once( "eztrade/classes/ezproduct.php" );
36 // include_once( "eztrade/classes/ezproductcategory.php" );
37 // include_once( "eztrade/classes/ezpricegroup.php" );
38
39 // sections
40 // include_once( "ezsitemanager/classes/ezsection.php" );
41
42
43 if ( $CategoryID != 0 )
44 {
45 $GlobalSectionID = eZProductCategory::sectionIDStatic( $CategoryID );
46 $CategoryArray = $CategoryID;
47 }
48
49 // init the section
50 $sectionObject =& eZSection::globalSectionObject( $GlobalSectionID );
51 $sectionObject->setOverrideVariables();
52
53
54 $ini =& eZINI::instance( 'site.ini' );
55
56 $Language = $ini->variable( "eZTradeMain", "Language" );
57 $Limit = $ini->variable( "eZTradeMain", "ProductLimit" );
58 $ShowPriceGroups = $ini->variable( "eZTradeMain", "PriceGroupsEnabled" ) == "true";
59 $RequireUserLogin = $ini->variable( "eZTradeMain", "RequireUserLogin" ) == "true";
60 $PricesIncludeVAT = $ini->variable( "eZTradeMain", "PricesIncludeVAT" ) == "enabled" ? true : false;
61
62 $CapitalizeHeadlines = $ini->variable( "eZArticleMain", "CapitalizeHeadlines" );
63
64 $ThumbnailImageWidth = $ini->variable( "eZTradeMain", "ThumbnailImageWidth" );
65 $ThumbnailImageHeight = $ini->variable( "eZTradeMain", "ThumbnailImageHeight" );
66
67 $ShowPrice = $ini->variable( "eZTradeMain", "PriceGroupsEnabled" ) == "true";
68
69 $SimpleOptionHeaders = $ini->variable( "eZTradeMain", "SimpleOptionHeaders" ) == "true";
70 $ShowOptionQuantity = $ini->variable( "eZTradeMain", "ShowOptionQuantity" ) == "true";
71 $RequireQuantity = $ini->variable( "eZTradeMain", "RequireQuantity" ) == "true" ;
72
73
74 $t = new eZTemplate( "kernel/eztrade/user/" . $ini->variable( "eZTradeMain", "TemplateDir" ),
75 "kernel/eztrade/user/intl/", $Language, "productlist.php" );
76
77 $t->set_file( "product_list_page_tpl", "productlist.tpl" );
78
79 $t->set_block( "product_list_page_tpl", "price_tpl", "price" );
80 $t->set_block( "product_list_page_tpl", "path_tpl", "path" );
81 $t->set_block( "product_list_page_tpl", "product_list_tpl", "product_list" );
82
83 $t->set_block( "product_list_tpl", "product_tpl", "product" );
84 $t->set_block( "product_tpl", "product_image_tpl", "product_image" );
85
86 $t->set_block( "product_tpl", "option_tpl", "option" );
87 $t->set_block( "option_tpl", "value_price_header_tpl", "value_price_header" );
88 $t->set_block( "option_tpl", "value_tpl", "value" );
89
90 $t->set_block( "value_price_header_tpl", "value_description_header_tpl", "value_description_header" );
91 // $t->set_block( "value_price_header_tpl", "value_price_header_item_tpl", "value_price_header_item" );
92 $t->set_block( "value_price_header_tpl", "value_currency_header_item_tpl", "value_currency_header_item" );
93
94 $t->set_block( "value_tpl", "value_description_tpl", "value_description" );
95 $t->set_block( "value_tpl", "value_price_item_tpl", "value_price_item" );
96 $t->set_block( "value_tpl", "value_availability_item_tpl", "value_availability_item" );
97 $t->set_block( "value_tpl", "value_price_currency_list_tpl", "value_price_currency_list" );
98
99 $t->set_block( "value_price_currency_list_tpl", "value_price_currency_item_tpl", "value_price_currency_item" );
100
101 $t->set_block( "product_tpl", "add_to_cart_tpl", "add_to_cart" );
102
103 $t->set_block( "product_list_page_tpl", "category_list_tpl", "category_list" );
104 $t->set_block( "category_list_tpl", "category_tpl", "category" );
105
106 $t->set_var( "product", "" );
107 $t->set_var( "module", "" );
108
109 if ( !isSet( $ModuleName ) )
110 $ModuleName = "trade";
111 if ( !isset( $ModuleList ) )
112 $ModuleList = "productlist";
113 if ( !isset( $ModuleView ) )
114 $ModuleView = "productview";
115
116 // makes the section ID available in articleview template
117 $t->set_var( "section_id", $GlobalSectionID );
118
119 $t->set_var( "module", $ModuleName );
120 $t->set_var( "module_list", $ModuleList );
121 $t->set_var( "module_view", $ModuleView );
122
123 $t->setAllStrings();
124
125 $category = new eZProductCategory();
126 $category->get( $CategoryID );
127
128 // path
129 $pathArray = $category->path();
130
131 $t->set_var( "path", "" );
132 foreach ( $pathArray as $path )
133 {
134 $t->set_var( "category_id", $path[0] );
135 $t->set_var( "category_name", $path[1] );
136 $t->parse( "path", "path_tpl", true );
137
138 if( isset( $SiteTitleAppend ) )
139 $SiteTitleAppend .= $path[1] . " - ";
140 }
141
142 $categoryList =& $category->getByParent( $category );
143
144 $user =& eZUser::currentUser();
145
146 // categories
147 $i = 0;
148 foreach ( $categoryList as $categoryItem )
149 {
150 if ( eZObjectPermission::hasPermission( $categoryItem->id(), "trade_category", "r", $user ) )
151 {
152 $t->set_var( "category_id", $categoryItem->id() );
153 $t->set_var( "category_name", $categoryItem->name() );
154 $t->set_var( "category_description", $categoryItem->description() );
155
156 $parent = $categoryItem->parent();
157
158 if ( $categoryItem->parent() != 0 )
159 {
160 $parent = $categoryItem->parent();
161 $t->set_var( "category_parent", $parent->name() );
162 }
163 else
164 {
165 $t->set_var( "category_parent", "&nbsp;" );
166 }
167
168 if ( ( $i % 2 ) == 0 )
169 {
170 $t->set_var( "td_class", "bglight" );
171 }
172 else
173 {
174 $t->set_var( "td_class", "bgdark" );
175 }
176
177 $t->parse( "category", "category_tpl", true );
178 $i++;
179 }
180 }
181
182 if ( count( $categoryList ) == 0 )
183 {
184 $t->set_var( "category_list", "" );
185 }
186 else
187 {
188 $t->parse( "category_list", "category_list_tpl" );
189 }
190
191 if ( !isset( $Limit ) or !is_numeric( $Limit ) )
192 $Limit = 10;
193 if ( !isset( $Offset ) or !is_numeric( $Offset ) )
194 $Offset = 0;
195
196 // products
197 $TotalTypes =& $category->productCount( $category->sortMode(), false );
198 $productList =& $category->activeProducts( $category->sortMode(), $Offset, $Limit, $category->id() );
199
200 $locale = new eZLocale( $Language );
201 $i = 0;
202
203 foreach ( $productList as $product )
204 {
205 if ( eZObjectPermission::hasPermission( $category->id(), "trade_category", "r", $user ) )
206 {
207 $t->set_var( "product_id", $product->id() );
208
209 // preview image
210 $thumbnailImage = $product->thumbnailImage();
211
212 if ( $thumbnailImage )
213 {
214 $variation =& $thumbnailImage->requestImageVariation( $ThumbnailImageWidth, $ThumbnailImageHeight );
215
216 $t->set_var( "thumbnail_image_uri", "/" . $variation->imagePath() );
217 $t->set_var( "thumbnail_image_width", $variation->width() );
218 $t->set_var( "thumbnail_image_height", $variation->height() );
219 $t->set_var( "thumbnail_image_caption", $thumbnailImage->caption() );
220
221 $t->parse( "product_image", "product_image_tpl" );
222 }
223 else
224 {
225 $t->set_var( "product_image", "" );
226 }
227
228 $options = $product->options();
229 $t->set_var( "option", "" );
230
231 $t->set_var( "value_price_header", "" );
232 if ( $ShowPrice and $product->showPrice() == true )
233 $t->parse( "value_price_header", "value_price_header_tpl" );
234
235 // show alternative currencies
236 $currency = new eZProductCurrency( );
237 $currencies =& $currency->getAll();
238 $t->set_var( "currency_count", count( $currencies ) );
239 $t->set_var( "value_price_header_item", "" );
240 $t->set_var( "value_currency_header_item", "" );
241 if ( !$RequireUserLogin or is_a( $user, "eZUser" ) )
242 {
243 $t->parse( "value_price_header_item", "value_price_header_item_tpl" );
244 if ( count( $currencies ) > 0 )
245 $t->parse( "value_currency_header_item", "value_currency_header_item_tpl" );
246 }
247
248 $can_checkout = true;
249
250 $currency_locale = new eZLocale( $Language );
251 foreach ( $options as $option )
252 {
253 $values = $option->values();
254
255 $t->set_var( "value", "" );
256 $i = 0;
257 $headers = $option->descriptionHeaders();
258 $t->set_var( "value_description_header", "" );
259 if ( $SimpleOptionHeaders )
260 {
261 $t->set_var( "description_header", $headers[0] );
262 $t->parse( "value_description_header", "value_description_header_tpl" );
263 }
264 else
265 {
266 foreach ( $headers as $header )
267 {
268 $t->set_var( "description_header", $header );
269 $t->parse( "value_description_header", "value_description_header_tpl", true );
270 }
271 }
272
273 foreach ( $values as $value )
274 {
275 $value_quantity = $value->totalQuantity();
276 if ( $ShowOptionQuantity or ( is_bool( $value_quantity ) and !$value_quantity ) or
277 !$RequireQuantity or ( $RequireQuantity and $value_quantity > 0 ) )
278 {
279 if ( !$value->hasQuantity( $RequireQuantity ) )
280 $can_checkout = false;
281 $t->set_var( "value_td_class", ( $i % 2 ) == 0 ? "bglight" : "bgdark" );
282 $id = $value->id();
283
284 $descriptions = $value->descriptions();
285 $t->set_var( "value_description", "" );
286 if ( $SimpleOptionHeaders )
287 {
288 $t->set_var( "value_id", $value->id() );
289
290 $t->set_var( "value_name", $descriptions[0] );
291 $t->parse( "value_description", "value_description_tpl" );
292 }
293 else
294 {
295 foreach ( $descriptions as $description )
296 {
297 $t->set_var( "value_name", $description );
298 $t->parse( "value_description", "value_description_tpl", true );
299 }
300 }
301
302 $t->set_var( "value_price", "" );
303 $t->set_var( "value_price_item", "" );
304 $t->set_var( "value_price_currency_list", "" );
305 if ( $ShowPrice and $product->showPrice() == true )
306 {
307 $price = new eZCurrency( $value->correctPrice( $PricesIncludeVAT, $product ) );
308 if ( $value->price() != 0 )
309 $t->set_var( "value_price", "+".$value->localePrice( $PricesIncludeVAT, $product ) );
310 else
311 $t->set_var( "value_price", "" );
312
313 $t->parse( "value_price_item", "value_price_item_tpl" );
314
315 $t->set_var( "value_price_currency_item", "" );
316 foreach ( $currencies as $currency )
317 {
318 $altPrice = $price;
319 $altPrice->setValue( $price->value() * $currency->value() );
320
321 $currency_locale->setSymbol( $currency->sign() );
322 $currency_locale->setPrefixSymbol( $currency->prefixSign() );
323
324 $t->set_var( "alt_value_price", $currency_locale->format( $altPrice ) );
325 $t->parse( "value_price_currency_item", "value_price_currency_item_tpl", true );
326 }
327
328 $t->set_var( "value_price_currency_list", "" );
329 if ( count( $currencies ) > 0 )
330 $t->parse( "value_price_currency_list", "value_price_currency_list_tpl" );
331 }
332
333 $t->set_var( "value_availability_item", "" );
334 if ( !( is_bool( $value_quantity ) and !$value_quantity ) )
335 {
336 $named_quantity = $value_quantity;
337 if ( $ShowNamedQuantity )
338 $named_quantity = eZProduct::namedQuantity( $value_quantity );
339 $t->set_var( "value_availability", $named_quantity );
340 $t->parse( "value_availability_item", "value_availability_item_tpl" );
341 }
342
343 $t->parse( "value", "value_tpl", true );
344 $i++;
345 }
346 }
347
348 if ( $i > 0 )
349 {
350 $t->set_var( "option_name", $option->name() );
351 $t->set_var( "option_description", $option->description() );
352 $t->set_var( "option_id", $option->id() );
353 // $t->set_var( "product_id", isset( $ProductID ) ? $ProductID : false );
354
355 $t->parse( "option", "option_tpl", true );
356 }
357 }
358
359 if( isset( $SiteDescriptionOverride ) )
360 $SiteDescriptionOverride .= $product->name() . " ";
361 // $SiteDescriptionOverride = addslashes( $SiteDescriptionOverride );
362 $t->set_var( "product_name", $product->name() );
363
364 $t->set_var( "product_intro_text", eZTextTool::nl2br( $product->brief() ) );
365
366 if ( $ShowPrice and $product->showPrice() == true and $product->hasPrice() )
367 {
368 $t->set_var( "product_price", $product->localePrice( $PricesIncludeVAT ) );
369 $priceRange = $product->correctPriceRange( $PricesIncludeVAT );
370
371 if ( ( empty( $priceRange["min"] ) and empty( $priceRange["max"] ) ) and !($product->correctPrice( $PricesIncludeVAT ) > 0) )
372 {
373 $t->set_var( "product_price", "" );
374 }
375 $t->parse( "price", "price_tpl" );
376 }
377 elseif( $product->showPrice() == false )
378 {
379 $t->set_var( "product_price", "" );
380 $t->parse( "price", "price_tpl" );
381 }
382 else
383 {
384 $priceArray = "";
385 $options =& $product->options();
386 if ( count( $options ) == 1 )
387 {
388 $option = $options[0];
389 if ( get_class( $option ) == "ezoption" )
390 {
391 $optionValues =& $option->values();
392 if ( count( $optionValues ) > 1 )
393 {
394 $i=0;
395 foreach ( $optionValues as $optionValue )
396 {
397 $priceArray[$i] = $optionValue->localePrice( $PricesIncludeVAT, $product );
398 $i++;
399 }
400 $high = max( $priceArray );
401 $low = min( $priceArray );
402
403 $t->set_var( "product_price", $low . " - " . $high );
404
405 $t->parse( "price", "price_tpl" );
406 }
407 }
408 }
409 else
410 $t->set_var( "price", "" );
411 }
412
413 $t->set_var( "category_id", $category->id() );
414
415 if ( ( $i % 2 ) == 0 )
416 {
417 $t->set_var( "td_class", "bglight" );
418 }
419 else
420 {
421 $t->set_var( "td_class", "bgdark" );
422 }
423
424 $t->set_var( "action_url", "cart/add" );
425 $t->parse( "add_to_cart", "add_to_cart_tpl" );
426 $t->parse( "product", "product_tpl", true );
427 $i++;
428 }
429 }
430
431 if ( count( $productList ) > 0 )
432 {
433 $t->parse( "product_list", "product_list_tpl" );
434 }
435 else
436 {
437 $t->set_var( "product_list", "" );
438 }
439
440
441
442 eZList::drawNavigator( $t, $TotalTypes, $Limit, $Offset, "product_list_page_tpl" );
443
444 if ( isset( $GenerateStaticPage ) && $GenerateStaticPage == "true" )
445 {
446 // if ( $user ) {
447 // $CategoryArray =& $user->groups( false );
448 // }
449 // else
450 // {
451 // $CategoryArray = '';
452 // }
453
454 if ( !$PriceGroup )
455 $PriceGroup = 0;
456
457 $cache = new eZCacheFile( "kernel/eztrade/cache/", array( "productlist", $CategoryID, $Offset, $PriceGroup ),
458 "cache", "," );
459 $cacheFileName = $cache->filename( true );
460 // add PHP code in the cache file to store variables
461 /*
462 $output = "<?php\n";
463 $output .= "\$GlobalSectionID=\"$GlobalSectionID\";\n";
464 $output .= "\$SiteTitleAppend=\"$SiteTitleAppend\";\n";
465 $output .= "\$SiteDescriptionOverride=\"$SiteDescriptionOverride\";\n";
466 $output .= "?>\n";
467 */
468
469 $output = $t->parse( "output", "product_list_page_tpl" );
470 print( $output ."<br /><br />" );
471 $cache->store( $output );
472 }
473 else
474 {
475 $t->pparse( "output", "product_list_page_tpl" );
476 }
477
478 ?>
$CategoryID
$CategoryID
Definition: admin/articleedit.php:53
eZCurrency
Definition: ezcurrency.php:46
eZList\drawNavigator
static drawNavigator(&$t, $total_types, $max_types, $index, $parent=false, $variables=false)
Definition: ezlist.php:401
eZLocale
Definition: ezlocale.php:119
eZObjectPermission\hasPermission
static hasPermission( $objectID, $moduleTable, $permission, $user=false)
Definition: ezobjectpermission.php:76
eZProductCategory
Definition: ezproductcategory.php:90
eZProductCategory\sectionIDStatic
static sectionIDStatic( $categoryID)
Definition: ezproductcategory.php:394
eZProductCurrency
Definition: ezproductcurrency.php:40
eZProduct\namedQuantity
static namedQuantity( $quantity)
Definition: ezproduct.php:1037
eZSection\globalSectionObject
static & globalSectionObject( $sectionID)
Definition: ezsection.php:366
eZTemplate
Definition: eztemplate.php:107
eZTextTool\nl2br
static nl2br( $string, $xhtml=true)
Definition: eztexttool.php:65
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
$id
$id
Definition: companytypelist.php:193
$currency
$currency
Definition: companyview.php:529
$currencies
$currencies
Definition: currency.php:99
$GlobalSectionID
$GlobalSectionID
Definition: ezad/user/datasupplier.php:28
$Offset
$Offset
Definition: ezarticle/user/search.php:110
$ModuleName
$ModuleName
Definition: ezarticle/user/searchsupplier.php:30
$variation
$variation
Definition: ezimagecatalogue/user/menubox.php:55
$priceRange
$priceRange
Definition: eztrade/user/extendedsearch.php:85
$values
$values
Definition: fixedvalues.php:103
$output
$output
Definition: formpreview.php:81
$product
$product
Definition: homepage.php:202
$ModuleList
$ModuleList
Definition: hotdealslist.php:87
$options
$options
Definition: optionlist.php:56
$header
$header
Definition: paypalnotify.php:141
$price
$price
Definition: pricegroupedit.php:39
$PriceGroup
$PriceGroup
Definition: productedit.php:1073
$ThumbnailImageHeight
$ThumbnailImageHeight
Definition: productlist.php:65
$Limit
$Limit
Definition: productlist.php:57
$category
$category
Definition: productlist.php:125
$ShowOptionQuantity
$ShowOptionQuantity
Definition: productlist.php:70
$locale
$locale
Definition: productlist.php:200
$t
$t
Definition: productlist.php:74
$sectionObject
if( $CategoryID !=0) $sectionObject
Definition: productlist.php:50
$TotalTypes
$TotalTypes
Definition: productlist.php:197
$user
$user
Definition: productlist.php:144
$PricesIncludeVAT
$PricesIncludeVAT
Definition: productlist.php:60
$pathArray
$pathArray
Definition: productlist.php:129
$i
$i
Definition: productlist.php:147
$Language
$Language
Definition: productlist.php:56
$ini
$ini
Definition: productlist.php:54
$ShowPriceGroups
$ShowPriceGroups
Definition: productlist.php:58
$categoryList
foreach( $pathArray as $path) $categoryList
Definition: productlist.php:142
$ShowPrice
$ShowPrice
Definition: productlist.php:67
$CapitalizeHeadlines
$CapitalizeHeadlines
Definition: productlist.php:62
$SimpleOptionHeaders
$SimpleOptionHeaders
Definition: productlist.php:69
$ThumbnailImageWidth
$ThumbnailImageWidth
Definition: productlist.php:64
$RequireQuantity
$RequireQuantity
Definition: productlist.php:71
$productList
$productList
Definition: productlist.php:198
$RequireUserLogin
$RequireUserLogin
Definition: productlist.php:59
$currency_locale
$currency_locale
Definition: productpreview.php:265
$can_checkout
$can_checkout
Definition: productpreview.php:263
$ShowNamedQuantity
$ShowNamedQuantity
Definition: productpreview.php:54
$GenerateStaticPage
$GenerateStaticPage
Definition: quizscores.php:95
$headers
$headers
Definition: requestpagelist.php:61
$SiteTitleAppend
$SiteTitleAppend
Definition: user/articlelist.php:212
$SiteDescriptionOverride
$SiteDescriptionOverride
Definition: user/articlelist.php:383
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.