PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/catalog/includes/modules/featured.php

https://github.com/eosc/EosC-2.3
PHP | 153 lines | 106 code | 17 blank | 30 comment | 36 complexity | 64538fc7a3f4aaf8ac66130b584f8d09 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /*
  3. osCommerce, Open Source E-Commerce Solutions
  4. http://www.oscommerce.com
  5. Copyright (c) 2002 osCommerce
  6. Released under the GNU General Public License
  7. Featured Products V1.5.2
  8. adapted for Separate Pricing Per Customer v4.1 2006/02/26
  9. and made flexible for number of columns (default 3), added dividing lines ($color_v and $color_h)
  10. see line 28 and further to define these variables (set to background color if you don't want them)
  11. Displays a list of featured products, selected from admin
  12. For use as an Infobox instead of the "New Products" Infobox
  13. */
  14. ?>
  15. <!-- featured_products //-->
  16. <?php
  17. if(FEATURED_PRODUCTS_DISPLAY == 'true')
  18. {
  19. $featured_products_category_id = $new_products_category_id;
  20. $cat_name_query = tep_db_query("select categories_name from categories_description where categories_id = '" . $featured_products_category_id . "' limit 1");
  21. $cat_name_fetch = tep_db_fetch_array($cat_name_query);
  22. $cat_name = $cat_name_fetch['categories_name'];
  23. $info_box_contents = array();
  24. $color_h = '#bbc3d3'; // color of horizontal lines
  25. $color_v = '#bbc3d3'; // color of vertical lines
  26. $border_style_h = "solid"; // style of horizontal lines: solid, dashed, dotted
  27. $border_style_v = ""; // style of vertical lines
  28. $no_of_columns = 3;
  29. // BOF Separate Pricing Per Customer
  30. if(!tep_session_is_registered('sppc_customer_group_id')) {
  31. $customer_group_id = '0';
  32. } else {
  33. $customer_group_id = $sppc_customer_group_id;
  34. }
  35. // EOF Separate Pricing Per Customer
  36. if ( (!isset($featured_products_category_id)) || ($featured_products_category_id == '0') ) {
  37. $info_box_contents[] = array('align' => 'left', 'text' => '<a class="infoBoxHeading" href="' . tep_href_link(FILENAME_FEATURED_PRODUCTS) . '">' . TABLE_HEADING_FEATURED_PRODUCTS . '</a>');
  38. list($usec, $sec) = explode(' ', microtime());
  39. srand( (float) $sec + ((float) $usec * 100000) );
  40. $mtm= rand();
  41. $featured_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, NULL as specstat, NULL as specials_new_products_price, p.products_price, pd.products_name from " . TABLE_PRODUCTS . " p left join " . TABLE_FEATURED . " f using(products_id) left join " . TABLE_PRODUCTS_DESCRIPTION . " pd using(products_id) where p.products_status = '1' and f.status = '1' and pd.language_id = '" . (int)$languages_id . "' order by rand($mtm) DESC limit " . MAX_DISPLAY_FEATURED_PRODUCTS);
  42. } else {
  43. $info_box_contents[] = array('align' => 'left', 'text' => sprintf(TABLE_HEADING_FEATURED_PRODUCTS_CATEGORY, $cat_name));
  44. $featured_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, NULL as specstat, NULL as specials_new_products_price, p.products_price, pd.products_name from " . TABLE_PRODUCTS . " p left join " . TABLE_FEATURED . " f using(products_id) left join " . TABLE_PRODUCTS_DESCRIPTION . " pd using(products_id), " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . $featured_products_category_id . "' and p.products_status = '1' and f.status = '1' and pd.language_id = '" . (int)$languages_id . "' order by rand() DESC limit " . MAX_DISPLAY_FEATURED_PRODUCTS);
  45. }
  46. if (($no_of_featured_prdcts = tep_db_num_rows($featured_products_query)) > 0) {
  47. while ($_featured_products = tep_db_fetch_array($featured_products_query)) {
  48. $featured_products[] = $_featured_products;
  49. $list_of_prdct_ids[] = $_featured_products['products_id'];
  50. }
  51. $_select_list_of_prdct_ids = implode("','", $list_of_prdct_ids);
  52. $select_list_of_prdct_ids = "'". $_select_list_of_prdct_ids . "'";
  53. // get all customers_group_prices for products with the particular customer_group_id
  54. // however not necessary for customer_group_id = 0
  55. if ($customer_group_id != '0') {
  56. $pg_query = tep_db_query("select pg.products_id, customers_group_price as price from " . TABLE_PRODUCTS_GROUPS . " pg where products_id in (".$select_list_of_prdct_ids.") and pg.customers_group_id = '".$customer_group_id."'");
  57. while ($pg_array = tep_db_fetch_array($pg_query)) {
  58. $new_prices[] = array ('products_id' => $pg_array['products_id'], 'products_price' => $pg_array['price'], 'specials_new_products_price' => '');
  59. }
  60. for ($x = 0; $x < $no_of_featured_prdcts; $x++) {
  61. // replace products prices with those from customers_group table
  62. if(!empty($new_prices)) {
  63. for ($i = 0; $i < count($new_prices); $i++) {
  64. if( $featured_products[$x]['products_id'] == $new_prices[$i]['products_id'] ) {
  65. $featured_products[$x]['products_price'] = $new_prices[$i]['products_price'];
  66. }
  67. }
  68. } // end if(!empty($new_prices)
  69. } // end for ($x = 0; $x < $no_of_featured_prdcts; $x++)
  70. } // end if ($customer_group_id != '0')
  71. // an extra query is needed for all the specials
  72. $specials_query = tep_db_query("select products_id, specials_new_products_price, status as specstat from specials where products_id in (".$select_list_of_prdct_ids.") and status = '1' and customers_group_id = '" .$customer_group_id. "' ");
  73. while ($specials_array = tep_db_fetch_array($specials_query)) {
  74. $new_s_prices[] = array ('products_id' => $specials_array['products_id'], 'specials_new_products_price' => $specials_array['specials_new_products_price'], 'specstat' => $specials_array['specstat']);
  75. }
  76. // add correct specials_new_products_price
  77. if(!empty($new_s_prices)) {
  78. for ($x = 0; $x < $no_of_featured_prdcts; $x++) {
  79. for ($i = 0; $i < count($new_s_prices); $i++) {
  80. if( $featured_products[$x]['products_id'] == $new_s_prices[$i]['products_id'] ) {
  81. $featured_products[$x]['specials_new_products_price'] = $new_s_prices[$i]['specials_new_products_price'];
  82. $featured_products[$x]['specstat'] = $new_s_prices[$i]['specstat'];
  83. }
  84. }
  85. }
  86. } // // end if(!empty($new_s_prices)
  87. } // end if ($no_of_featured_prdcts = tep_db_num_rows($featured_products_query)) > 0)
  88. // EOF Separate Pricing Per Customer
  89. $row = 0;
  90. $col = 0;
  91. $num = 1;
  92. // we need to know what the last row is, because the td on that row should not have a bottom border
  93. $last_row = ( $no_of_featured_prdcts % $no_of_columns == 0 ? ($no_of_featured_prdcts / $no_of_columns) -1 : floor($no_of_featured_prdcts / $no_of_columns ));
  94. // BOF Separate Pricing Per Customer
  95. // while ($featured_products = tep_db_fetch_array($featured_products_query)) {
  96. for ($x = 0; $x < $no_of_featured_prdcts; $x++) {
  97. if ($num == 1) { new contentBoxHeading($info_box_contents); }
  98. // $featured_products[$x]['products_name'] = tep_get_products_name($featured_products[$x]['products_id']);
  99. if($featured_products[$x]['specstat']) {
  100. $info_box_contents[$row][$col] = array('align' => 'center',
  101. 'params' => 'class="smallText" width="' . (floor(100 / $no_of_columns)) . '%" valign="top" style="padding-top: 4px; '. ( $row < $last_row ? 'border-bottom: 1px ' . $border_style_h . ' ' . $color_h . '; ': '') . ( $col < ($no_of_columns - 1) ? 'border-right: 1px ' . $border_style_v . ' ' . $color_v . ';"': '"'),
  102. 'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $featured_products[$x]['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $featured_products[$x]['products_image'], $featured_products[$x]['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $featured_products[$x]['products_id']) . '">' . $featured_products[$x]['products_name'] . '</a><br><s>' . $currencies->display_price($featured_products[$x]['products_price'], tep_get_tax_rate($featured_products[$x]['products_tax_class_id'])) . '</s><br><span class="productSpecialPrice">' .
  103. $currencies->display_price($featured_products[$x]['specials_new_products_price'], tep_get_tax_rate($featured_products[$x]['products_tax_class_id'])) . '</span>');
  104. } else {
  105. $info_box_contents[$row][$col] = array('align' => 'center',
  106. 'params' => 'class="smallText" width="' . (floor(100 / $no_of_columns)) . '%" valign="top" style="padding-top: 4px; '. ( $row < $last_row ? 'border-bottom: 1px ' . $border_style_h . ' ' . $color_h . '; ': '') . ( $col < ($no_of_columns - 1) ? 'border-right: 1px ' . $border_style_v . ' ' . $color_v . ';"': '"'),
  107. 'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $featured_products[$x]['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $featured_products[$x]['products_image'], $featured_products[$x]['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $featured_products[$x]['products_id']) . '">' . $featured_products[$x]['products_name'] . '</a><br>' . $currencies->display_price($featured_products[$x]['products_price'], tep_get_tax_rate($featured_products[$x]['products_tax_class_id'])));
  108. }
  109. // EOF Separate Pricing Per Customer
  110. // if we reached the last of the products, make sure the row of table cells is filled with empty cells if needed
  111. // just adding spaces for text does not produce an empty cell: use a instead
  112. if ($num == $no_of_featured_prdcts ) {
  113. for ($i = $col + 1; $i < $no_of_columns; $i++) {
  114. $info_box_contents[$row][$i] = array('align' => 'center', 'params' => 'class="smallText" width="' . (floor(100 / $no_of_columns)) . '%" valign="top" style="padding-top: 4px; '. ( $row < $last_row ? 'border-bottom: 1px ' . $border_style_h . ' ' . $color_h . '; ': '') . ( $i < ($no_of_columns - 1) ? 'border-right: 1px ' . $border_style_v . ' ' . $color_v . ';"': '"'),
  115. 'text' => '');
  116. }
  117. } // end if ($num == $no_of_featured_prdcts )
  118. $col ++;
  119. $num++;
  120. if ($col > ($no_of_columns -1)) {
  121. $col = 0;
  122. $row ++;
  123. }
  124. } // end for ($x=0; $x < $no_of_featured_prdcts; $x++)
  125. if($num > 1) {
  126. new contentBox($info_box_contents);
  127. }
  128. } else // If it's disabled, then include the original New Products box
  129. {
  130. include (DIR_WS_MODULES . FILENAME_NEW_PRODUCTS);
  131. }
  132. ?>
  133. <!-- featured_products_eof //-->