Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Change Featured Products Layout

Change Featured Products Layout

Views: 795

Results 1 to 2 of 2
16 May 2011, 8:45 PM
#1
scottlpool2003 avatar

scottlpool2003

New Zenner

Join Date:
May 2011
Posts:
2
Plugin Contributions:
0

Change Featured Products Layout

madabouttoys.co.uk

Featured products is near the bottom.

They are displaying on-top of each other, I need them to display inline.

I'm not too sure what the problem is, but I had to edit the code because it was displaying the wrong product.

Here is the code from includes/modules/featured_products.php

<?php
/**
 * featured_products module - prepares content for display
 *
 * @package modules
 * @copyright Copyright 2003-2007 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: featured_products.php 6424 2007-05-31 05:59:21Z ajeh $
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}
if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
  $featured_products_query = "select distinct p.products_id, p.products_image, pd.products_name
                           from (" . TABLE_PRODUCTS . " p
                           left join " . TABLE_FEATURED . " f on p.products_id = f.products_id
                           left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id )
                           where p.products_id = f.products_id and p.products_id = pd.products_id and p.products_status = 1 and f.status = 1 and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'";
} else {
  $featured_products_query = "select distinct p.products_id, p.products_image, pd.products_name
                           from (" . TABLE_PRODUCTS . " p
                           left join " . TABLE_FEATURED . " f on p.products_id = f.products_id
                           left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.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 = '" . (int)$new_products_category_id . "'
                           and p.products_id = f.products_id and p.products_id = pd.products_id and p.products_status = 1 and f.status = 1 and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'";

}
$featured_products = $db->ExecuteRandomMulti($featured_products_query, MAX_DISPLAY_SEARCH_RESULTS_FEATURED);

$row = 0;
$col = 0;
$list_box_contents = array();
$title = '';

$num_products_count = $featured_products->RecordCount();

// show only when 1 or more
if ($num_products_count > 0) {
  if ($num_products_count < SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS || SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS == 0) {
    $col_width = floor(100/$num_products_count);
  } else {
    $col_width = floor(100/SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS);
  }
  while (!$featured_products->EOF) {$product_query = "select products_name, products_description from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$featured_products->fields['products_id'] . "' and language_id = '" . (int)$_SESSION['languages_id'] . "'";
		$product_info = $db->Execute($product_query);$product_query = "select products_name, products_description from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$featured_products->fields['products_id'] . "' and language_id = '" . (int)$_SESSION['languages_id'] . "'";
		$product_info = $db->Execute($product_query);

      $products_price = zen_get_products_display_price($featured_products->fields['products_id']);
			$products_price = str_replace('$', '<small>$</small>', $products_price);
      $featured_products->fields['products_name'] = zen_get_products_name($featured_products->fields['products_id']);

			#PR Build product information box
			$product_info_str  = '<table class="productBoxHeading_tb" width="241" cellspacing="0" cellpadding="0"><tr>';
			$product_info_str .= '<td class="productBoxHeadingLcorner"></td>';
			$product_info_str .= '<td class="productBoxHeading">' . '<span class="productBoxPrice floatRight"></span><B>' . $featured_products->fields['products_name'] . '</B></td>';
			$product_info_str .= '<td class="productBoxHeadingRcorner"></td>';
			$product_info_str .= '</tr></table>';
	
			$product_info_str .= '<table class="productBoxOuter" width="241" cellspacing="0" cellpadding="0"><tr>';
			$product_info_str .= '<td class="productBoxLSide"> </td>';
			$product_info_str .= '<td class="productBoxMSide" valign="top">';
	
			$product_info_str .= '<table class="productBox" width="100%" cellspacing="0" cellpadding="0"><tr>';
			$product_info_str .= '<td class="productBoxImage" width="118">';
			$product_info_str .= '<a href="' . zen_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $featured_products->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $featured_products->fields['products_image'], $featured_products->fields['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
			$product_info_str .= '</td><td class="productBoxContent" valign="top">';
	
			$product_info_str .= '<table width="100%" cellspacing="0" cellpadding="0"><tr>';
			$product_info_str .= '<td class="productBoxDescription" valign="top">';
			$product_info_str .= (strlen($product_info->fields['products_description']) > 50) ? substr(strip_tags($product_info->fields['products_description']), 0, 50) . '…' : strip_tags($product_info->fields['products_description']);
			$product_info_str .= '</td></tr><tr><td>';
			$product_info_str .= '<B>' . $products_price = zen_get_products_display_price($featured_products->fields['products_id']) . '</B>';
			$product_info_str .= '</td></tr><tr><td height="4"></td></tr><tr><td>';
			$product_info_str .= '<a href="' . zen_href_link(basename($PHP_SELF), zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $featured_products->fields['products_id']) . '">' . '<img src="http://www.vintagebicyclerebuilds.net.au/includes/templates/layout17f/images/az_buy_now.gif" class="noborder" alt="" />' . '</a>';
			$product_info_str .= '</td></tr></table>';
	
			$product_info_str .= '</td';
			$product_info_str .= '</tr></table>'; // productBoxContent
	
			$product_info_str .= '</td>';
			$product_info_str .= '<td class="productBoxRSide"> </td>';
			$product_info_str .= '</tr></table>';
	
			$product_info_str .= '<table class="productBoxBottom_tb" width="241" cellspacing="0" cellpadding="0"><tr>';
			$product_info_str .= '<td class="productBoxLBottom"></td>';
			$product_info_str .= '<td class="productBoxMBottom"></td>';
			$product_info_str .= '<td class="productBoxRBottom"></td>';
			$product_info_str .= '</tr></table>';
	
			$list_box_contents[$row][$col] = array('align' => 'center',
																						 'params' => 'class="smallText" width="49%" valign="top"',
																						 'text' => $product_info_str);
	
			$col ++;
			if ($col > 1) {
				$col = 0;
				$row ++;
			}
      $featured_products->MoveNextRandom();
    }


  if ($featured_products->RecordCount() > 0) {
    if (isset($new_products_category_id) && $new_products_category_id !=0) {
      $category_title = zen_get_categories_name((int)$new_products_category_id);
      $title = '<h2 class="centerBoxHeading">' . TABLE_HEADING_FEATURED_PRODUCTS . ($category_title != '' ? ' - ' . $category_title : '') . '</h2>';
    } else {
      $title = '<h2 class="centerBoxHeading">' . TABLE_HEADING_FEATURED_PRODUCTS . '</h2>';
    }
    $zc_show_featured = true;
  }
}
?>

I would ideally like three in a row, but I don't think it will fit so two will do.

Thanks in advance, all help is appreciated.

Scott

16 May 2011, 9:02 PM
#2
scottlpool2003 avatar

scottlpool2003

New Zenner

Join Date:
May 2011
Posts:
2
Plugin Contributions:
0

Re: Change Featured Products Layout

Sorry about the above, I've changed it back, but having a problem.

The featured products are not displaying the correct products.

I have two featured products added in the admin area:

ID: 12 Baghera Blue Streamline foot to floor
ID: 63 Ez Fort playhouse

But the featured products seems to be pulling random images/titles

Please help! :)

Code:

<?php /** * featured_products module - prepares content for display * * @package modules * @copyright Copyright 2003-2007 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license <http://www.zen-cart.com/license/2_0.txt> GNU Public License V2.0 * @version $Id: featured_products.php 6424 2007-05-31 05:59:21Z ajeh $ */ if (!defined('IS_ADMIN_FLAG')) { die('Illegal Access'); } // initialize vars $categories_products_id_list = ''; $list_of_products = ''; $featured_products_query = ''; $display_limit = ''; if ( (($manufacturers_id > 0 && $_GET['filter_id'] == 0) || $_GET['music_genre_id'] > 0 || $_GET['record_company_id'] > 0) || (!isset($new_products_category_id) || $new_products_category_id == '0') ) { $featured_products_query = "select distinct p.products_id, p.products_image, pd.products_name, p.master_categories_id from (" . TABLE_PRODUCTS . " p left join " . TABLE_FEATURED . " f on p.products_id = f.products_id left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id ) where p.products_id = f.products_id and p.products_id = pd.products_id and p.products_status = 1 and f.status = 1 and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'"; } else { // get all products and cPaths in this subcat tree $productsInCategory = zen_get_categories_products_list( (($manufacturers_id > 0 && $_GET['filter_id'] > 0) ? zen_get_generated_category_path_rev($_GET['filter_id']) : $cPath), false, true, 0, $display_limit); if (is_array($productsInCategory) && sizeof($productsInCategory) > 0) { // build products-list string to insert into SQL query foreach($productsInCategory as $key => $value) { $list_of_products .= $key . ', '; } $list_of_products = substr($list_of_products, 0, -2); // remove trailing comma $featured_products_query = "select distinct p.products_id, p.products_image, pd.products_name, p.master_categories_id from (" . TABLE_PRODUCTS . " p left join " . TABLE_FEATURED . " f on p.products_id = f.products_id left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id) where p.products_id = f.products_id and p.products_id = pd.products_id and p.products_status = 1 and f.status = 1 and pd.language_id = '" . (int)$_SESSION['languages_id'] . "' and p.products_id in (" . $list_of_products . ")"; } } if ($featured_products_query != '') $featured_products = $db->ExecuteRandomMulti($featured_products_query, MAX_DISPLAY_SEARCH_RESULTS_FEATURED); $row = 0; $col = 0; $list_box_contents = array(); $title = ''; $num_products_count = ($featured_products_query == '') ? 0 : $featured_products->RecordCount(); // show only when 1 or more if ($num_products_count > 0) { if ($num_products_count < SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS || SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS == 0) { $col_width = floor(100/$num_products_count); } else { $col_width = floor(100/SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS); } while (!$featured_products->EOF) { $products_price = zen_get_products_display_price($featured_products->fields['products_id']); if (!isset($productsInCategory[$featured_products->fields['products_id']])) $productsInCategory[$featured_products->fields['products_id']] = zen_get_generated_category_path_rev($featured_products->fields['master_categories_id']); $list_box_contents[$row][$col] = array('params' => 'class="boxshadow1"' . ' ' . '', 'text' => (($new_products->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' : '<div class="box1"><div class="imagebox"><a href="' . zen_href_link(zen_get_info_page($new_products->fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $new_products->fields['products_image'], $new_products->fields['products_name'], IMAGE_PRODUCT_NEW_WIDTH, IMAGE_PRODUCT_NEW_HEIGHT) . '</a></div>') . '<p><a href="' . zen_href_link(zen_get_info_page($new_products->fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']) . '"><b>' . $new_products->fields['products_name'] . '</b></a></p><p class="colred"><a href="' . zen_href_link(zen_get_info_page($new_products->fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']) . '"><font color="#8e1b13">View Now</font></a></p></div>'); $col ++; if ($col > (SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS - 1)) { $col = 0; $row ++; } $featured_products->MoveNextRandom(); } if ($featured_products->RecordCount() > 0) { if (isset($new_products_category_id) && $new_products_category_id !=0) { $category_title = zen_get_categories_name((int)$new_products_category_id); $title = '<h2 class="centerBoxHeading">' . TABLE_HEADING_FEATURED_PRODUCTS . ($category_title != '' ? ' - ' . $category_title : '') . '</h2>'; } else { $title = '<h2 class="centerBoxHeading">' . TABLE_HEADING_FEATURED_PRODUCTS . '</h2>'; } $zc_show_featured = true; } } ?>