Jump to content



Photo
- - - - -

Choose a category fro new products in frontpage


This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1   AlainBensimon

AlainBensimon
  • Members
  • 23 posts

Posted 15 July 2011 - 17:16

Hello,
Currently, all the new products appear randomly on frontpage, and from all categories.

I'm looking for a way to have them appear only from the category I want, including the subcategories as well.

Here is my new_products.php code.

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2010 osCommerce

  Released under the GNU General Public License
*/
if ($first_page === true){
  if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
    $new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by     RAND() limit " . MAX_DISPLAY_PRODUCTS_FIRST_PAGE);
  } else {
    $new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . 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_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by     RAND() limit " . MAX_DISPLAY_PRODUCTS_FIRST_PAGE);
  }
}else{
  if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
    $new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by     RAND() limit " . MAX_DISPLAY_NEW_PRODUCTS);
  } else {
    $new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . 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_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by     RAND() limit " . MAX_DISPLAY_NEW_PRODUCTS);
  }
}
  $col = 0;
  $row = 0;
  
  if ($first_page == 0){  
  $col_items = (MAX_DISPLAY_NEW_PRODUCTS_PER_ROW - 1);
  $colspan = ((MAX_DISPLAY_NEW_PRODUCTS_PER_ROW * 2) - 1);
  }else{
  $col_items = (MAX_DISPLAY_NEW_PRODUCTS_PER_ROW_FIRST_PAGE - 1);
  $colspan = ((MAX_DISPLAY_NEW_PRODUCTS_PER_ROW_FIRST_PAGE * 2) - 1);
  }
  $col_width = (int)(100 / ($col_items + 1)).'%';

  $new_prods_content = '<div class="prods_content"><table border="0" cellspacing="0" cellpadding="0" class="prods_table">';
  while ($new_products = tep_db_fetch_array($new_products_query)) {
   
	if (($col === 0) && ($row != 0)) {
	  $new_prods_content .= '<tr><td class="prods_hseparator" colspan="'.$colspan.'">'.tep_draw_separator('spacer.gif', '1', '1').'</td></tr>';
	} 
	if ($col === 0) {
      $new_prods_content .= '<tr>';
   }else {
	   $new_prods_content .= '<td class="prods_vseparator">'.tep_draw_separator('spacer.gif', '1', '1').''; 
   }
// *************************************   
// *************************************
      $product_query = tep_db_query("select products_description, products_id from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$new_products['products_id'] . "' and language_id = '" . (int)$languages_id . "'");
      $product = tep_db_fetch_array($product_query);
	  $p_id = $new_products['products_id'];	
		  
	  $p_pic = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '" style="width:'.(SMALL_IMAGE_WIDTH + 2).'px;height:'.(SMALL_IMAGE_HEIGHT + 2).'px;">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], (SMALL_IMAGE_WIDTH + 2), (SMALL_IMAGE_HEIGHT + 2), ' style="width:'.(SMALL_IMAGE_WIDTH +2).'px;height:'.(SMALL_IMAGE_HEIGHT + 2).'px;"') . '';
	  
	  $p_name = '<span><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . $new_products['products_name'] . '</a></span>';
	  
	//  $p_desc = ''.substr(strip_tags($product['products_description']), 0, MAX_DESCR_1).' ...';

	  $p_desc =  mb_substr(strip_tags($product['products_description']), 0, MAX_DESCR_MODUL_NEW_PRODS, 'UTF-8').'...';
	  
	  $p_price = '<span class="productSpecialPrice">' . $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])) . '</span>';
// *************************************  
      $p_details = '<a class="bg_button2" onMouseOut="this.className=\'bg_button2\';" onMouseOver="this.className=\'bg_button2-act\';" href="' . tep_href_link('product_info.php?products_id='.$p_id) . '">'.tep_image_button('button_details.gif', '', ' class="btn1"').'</a>';
	  $p_details_text = '<div class="bg_button2" onMouseOut="this.className=\'bg_button2\';" onMouseOver="this.className=\'bg_button2-act\';">' .tep_draw_button_top() . '<a href="' . tep_href_link('product_info.php?products_id='.$p_id) . '" id="tdb1" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary ui-priority-secondary" role="button"><span class="ui-button-icon-primary ui-icon ui-icon-triangle-1-e"></span><span class="ui-button-text">'.  IMAGE_BUTTON_DETAILS .'</span></a>' . tep_draw_button_bottom().'</div>';

      $p_buy_now = '<a class="bg_button22" onMouseOut="this.className=\'bg_button22\';" onMouseOver="this.className=\'bg_button22-act\';" href="'.tep_href_link("products_new.php","action=buy_now&products_id=".$p_id).'">'.tep_image_button('button_in_cart.gif', '', ' class="btn1"').'</a>';
	  $p_buy_now_text = '<div class="bg_button22" onMouseOut="this.className=\'bg_button22\';" onMouseOver="this.className=\'bg_button22-act\';">' .tep_draw_button_top() . '<a href="'.tep_href_link("products_new.php","action=buy_now&products_id=".$p_id).'" id="tdb1" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary ui-priority-secondary" role="button"><span class="ui-button-icon-primary ui-icon ui-icon-cart"></span><span class="ui-button-text">'.  IMAGE_BUTTON_IN_CART .'</span></a>' . tep_draw_button_bottom().'</div>';
// *************************************
// *************************************
    $new_prods_content .= '<td style="width:'.$col_width.'" align="center" valign="top" class="wrapper_box">'.
	
				
				  '		<div class="pic_padd"><div class="wrapper_pic_div" style="width:'.(SMALL_IMAGE_WIDTH + 2).'px;height:'.(SMALL_IMAGE_HEIGHT + 2).'px;">'.$p_pic.''.tep_draw_prod_pic_top().''.tep_draw_prod_pic_bottom().'</a></div></div>'. "\n".
				
				  '		<div class="box-padd">'. "\n".
				      '		<div class="name name_padd">'.$p_name.'</div>'. "\n".
 '			<div class="desc desc_padd">'.$p_desc.'</div>'. "\n".
				  '			<div class="price price_padd"><b>'.$p_price.'</div>'. "\n".
				  '			<div class="button__padd">'.$p_buy_now_text.''.$p_details_text.'</div>'. "\n".
				  '		</div>'. "\n";

    $col ++;
    if ($col > $col_items) {
      	$new_prods_content .= '</td></tr>';
	  	$row ++;
      	$col = 0;
    }else{
		$new_prods_content .= '</td>';	
	}
  }

  $new_prods_content .= '</table></div>';
?>
  <?php
 if (!isset($_GET['cPath'])) 	{
?>
<?php
}else{
?>
<?php echo tep_draw_title_top();?>
<h1 class="cl_both "><?php echo sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')); ?></h1>
<?php echo tep_draw_title_bottom();?>
<?php	
}
?>

  <div class="contentPadd un">
    <?php echo $new_prods_content; ?>
  </div>

Thank a lot for any help.

#2   Loyd656

Loyd656
  • Members
  • 4 posts

Posted 09 June 2012 - 23:35

Bump! I'm very in need for this too, searched the forum, haven't found nothing.

Thanks!

#3   al3ks

al3ks
  • Members
  • 288 posts

Posted 10 June 2012 - 00:11

@Loyd656

try this
Find this post helpful? Click the 'Like this' button. :)

#4   DunWeb

DunWeb

    The Censored One

  • Members
  • 13,084 posts

Posted 10 June 2012 - 00:22

@Loyd656

You may also want to consider Featured Products



Chris
:|: Was this post helpful ? Click the LIKE THIS button :|:

See my Profile to learn more about add ons, templates, support plans and custom coding (click here)

#5   Loyd656

Loyd656
  • Members
  • 4 posts

Posted 10 June 2012 - 02:20

Thanks for sending me the addons, isn't there a quicker way to set this up by editing the code below. The code works fine for randomising the products on the homepage, just need the products to be specific products or a specific category. "if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {" - doesn't seem to be working when you enter a category ID, works without randomising but not with randomising products.

Found in: /includes/modules/new_products.php

if ($first_page === true){
  if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
	$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by	 RAND() limit " . MAX_DISPLAY_PRODUCTS_FIRST_PAGE);
  } else {
	$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . 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_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by	 RAND() limit " . MAX_DISPLAY_PRODUCTS_FIRST_PAGE);
  }
}else{
  if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
	$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by	 RAND() limit " . MAX_DISPLAY_NEW_PRODUCTS);
  } else {
	$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . 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_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by	 RAND() limit " . MAX_DISPLAY_NEW_PRODUCTS);
  }
}

Edited by Loyd656, 10 June 2012 - 02:20.


#6   DunWeb

DunWeb

    The Censored One

  • Members
  • 13,084 posts

Posted 10 June 2012 - 02:38

@Loyd656

You are trying to reinvent the wheel. The featured products contribution allows you to select the products you want to display on the front page. There is no reason to continue to try to recode the new_products module.



Chris
:|: Was this post helpful ? Click the LIKE THIS button :|:

See my Profile to learn more about add ons, templates, support plans and custom coding (click here)

#7   Loyd656

Loyd656
  • Members
  • 4 posts

Posted 10 June 2012 - 19:34

Thanks Chris. I've installed featured products and works fine. Displays the products on the homepage, but the styling is horrible. Although, now i have some custom styling problems. Any idea how to get them transformed back to the correct styling using the code below without interfering with featured products? The styling i need is the new_products.php found below.

Featured Products Styling (featured.php)
  if ($num_featured_products > 0) {
	$counter = 0;
	$col = 0;
	$featured_prods_content = '<table border="0" width="100%" cellspacing="0" cellpadding="2">';
	while ($featured_products = tep_db_fetch_array($featured_products_query)) {
	  $counter++;
	  if ($col === 0) {
		$featured_prods_content .= '<tr>';
	  }
	  $featured_prods_content .= '<td width="33%" align="center" valign="top"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $featured_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $featured_products['products_image'], $featured_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br /><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $featured_products['products_id']) . '">' . $featured_products['products_name'] . '</a><br />' . $currencies->display_price($featured_products['products_price'], tep_get_tax_rate($featured_products['products_tax_class_id'])) . '</td>';
	  $col ++;
	  if (($col > 2) || ($counter == $num_featured_products)) {
		$featured_prods_content .= '</tr>';
		$col = 0;
	  }
	}
	$featured_prods_content .= '</table>';
?>
  <h2><?php echo $title; ?></h2>
  <div class="contentText">
	<?php echo $featured_prods_content; ?>
  </div>

Before, Custom styling (new_products.php):
  $row = 0;
  $col = 0;
  $info_box_contents = array();
  while ($new_products = tep_db_fetch_array($new_products_query)) {
// ----------
  $product_query = tep_db_query("select products_description, products_id from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$new_products['products_id'] . "' and language_id = '" . (int)$languages_id . "'");
  $product = tep_db_fetch_array($product_query);
  $p_id = $product['products_id']; [/b]
[b]  $p_pic = '<p><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></p>';

  $p_name = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . $new_products['products_name'] . '</a>';

  $p_desc = ''.substr(strip_tags($product['products_description']), 0, MAX_DESCR_1).' ...';

  $p_price = '<span class="productSpecialPrice">'.$currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])).'</span>';

  $p_buy_now = '<a href="'.tep_href_link("products_new.php","action=buy_now&products_id=".$p_id).'">'.tep_image_button('button_add_to_cart1.gif', '', ' class="btn2"').'</a>';[/b]
[b]	$info_box_contents[$row][$col] = array('align' => 'left',
										   'params' => ' style="width:50%;"',
										   'text' => ''.tep_draw_prod2_top().'
<table cellpadding="0" cellspacing="0" border="0"><tr><td class="new">
<table cellpadding="0" cellspacing="0" border="0">
  <tr><td class="name name2_padd">'.$p_name.'</td></tr>
  <tr><td class="pic2_padd">'.tep_draw_prod_pic_top().''.$p_pic.''.tep_draw_prod_pic_bottom().'</td></tr>
  <tr><td>'.tep_draw_name_top().'
   <table cellpadding="0" cellspacing="0" border="0">
	<tr>
	 <td class="price2_padd"><b>'.PRICE.':</b>'.$p_price.'</td>
	 <td>'.tep_image(DIR_WS_IMAGES.'part.gif').'</td>
	 <td class="button2_padd button2_marg">
	  <table cellpadding="0" cellspacing="0" border="0">
	   <tr><td>'.$p_details.' '.$p_buy_now.'</td></tr>
	  </table>
	 </td>
	</tr>
   </table>
  '.tep_draw_name_bottom().'</td></tr>
</table>
</td></tr></table>		  
'.tep_draw_prod2_bottom().'');
	$col ++;
	if ($col > 1) {
	  $col = 0;
	  $row ++;
	}
  }
new contentBox($info_box_contents);

I need the featured products styling how the new_products.php is without interfering with featured products.

Thanks, Loyd.

Edited by Loyd656, 10 June 2012 - 19:36.


#8   multimixer

multimixer

    Lemons or Melons ?

  • Partner
  • 4,578 posts

Posted 11 June 2012 - 04:09

What you call "custom styling" is probaly some sort of template that use functions like "tep_draw_prod_pic_top()" for simple design/layout tasks + all that html styling like <b></b>

That's in my eyes worse than the original that is clean and can be easily styled with css

However, you can use the html structure of your new_products and replace the variables there with the data from your featured products box. You'll need to update the query to pull the products description

#9   Loyd656

Loyd656
  • Members
  • 4 posts

Posted 11 June 2012 - 13:23

Had a play around with the variables and got there in the end. @multimixer, possibly so, but the styling of the designs for the main page is much better than the original clean, plain and boring styling and is working fine for all common browsers and functions correctly, i can't see any issues with it.

# http://i50.tinypic.com/okn6sp.jpg

Featured products now working and all fixed, anyone else having problems use what Chris said above. ''Featured Products''.

Loyd /thumbsup.gif' class='bbc_emoticon' alt=':thumbsup:' />

Edited by Loyd656, 11 June 2012 - 13:24.


#10   multimixer

multimixer

    Lemons or Melons ?

  • Partner
  • 4,578 posts

Posted 11 June 2012 - 13:45

I didn't say that the default look better than you template

What I said is, that the code is much more clean and easy to style than the template monster mess you have. Only recommented thing to do, would be to change the table layout into an unordered list

Of course, this styling is something you need to do, you could say the default is "un-styled", but easy to style just using css. That is not the case with your template

Anyway, if you're happy with it /whistling.gif' class='bbc_emoticon' alt=':-' />

Glad that it worked

Edited by multimixer, 11 June 2012 - 13:46.


#11   burt

burt

    Vanquisher of Demons

  • Community Team
  • 9,828 posts

Posted 11 June 2012 - 14:21

Another way to do it, answering the orginal question and the bump;

/includes/modules/new_products.php

Find (approx line 14):
$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);

Change to:

    $new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . 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 = 'XYZ' and p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);

Change XYZ to the ID of the top level category you want to feature on the index page.
IF YOU MAKE A POST REQUESTING HELP...please state the exact version of osCommerce that you are using. THANKS
 
Big Bang Templates for 2.3 osCommerce - 2.3.1 > 2.3.4 - Buy One, Get One Free
 
--
Making your osCommerce better, one module at a time - get in touch.

#12   multimixer

multimixer

    Lemons or Melons ?

  • Partner
  • 4,578 posts

Posted 11 June 2012 - 16:22

@burt , you are right, this was the original question /smile.png' class='bbc_emoticon' alt=':)' />