Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Displaying New Products on the home page


Guest

Recommended Posts

Is it possible to display new products for the month on the home page by specific category.

 

Simply, there are certain products that I do not want being shown on the front page.

 

Thanks

Link to comment
Share on other sites

if the products you want to show are only in specific categories then you can change the query in the existing new product box to only look in those cats.

 

Is that what you want ?

 

post the page here if it is and i'll have a look - also need the cat numbers.

Your online success is Paramount.

Link to comment
Share on other sites

if the products you want to show are only in specific categories then you can change the query in the existing new product box to only look in those cats.

 

Is that what you want ?

 

post the page here if it is and i'll have a look - also need the cat numbers.

thats exactly what I mean.. thank you

 

the categories numbers are: cPath=32 and cPath=34_101 and cPath=34_113

 

the whatsnew.php file is here:

 

-----------------------------------------------------------------------------------------------

 

 

<?php

/*

$Id: whats_new.php,v 1.31 2003/02/10 22:31:09 hpdl Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

if ($random_product = tep_random_select("select products_id, products_image, products_tax_class_id, products_price from " . TABLE_PRODUCTS . " where products_status = '1' order by products_date_added desc limit " . MAX_RANDOM_SELECT_NEW)) {

?>

<!-- whats_new //-->

<tr>

<td>

<?php

$random_product['products_name'] = tep_get_products_name($random_product['products_id']);

$random_product['specials_new_products_price'] = tep_get_products_special_price($random_product['products_id']);

 

$info_box_contents = array();

$info_box_contents[] = array('text' => BOX_HEADING_WHATS_NEW);

 

new infoBoxHeading($info_box_contents, false, false, tep_href_link(FILENAME_PRODUCTS_NEW), $column_location);

 

if (tep_not_null($random_product['specials_new_products_price'])) {

$whats_new_price = '<s>' . $currencies->display_price($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '</s><br>';

$whats_new_price .= '<span class="productSpecialPrice">' . $currencies->display_price($random_product['specials_new_products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '</span>';

} else {

$whats_new_price = $currencies->display_price($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id']));

}

 

$info_box_contents = array();

$info_box_contents[] = array('align' => 'center',

'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $random_product['products_image'], $random_product['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id']) . '">' . $random_product['products_name'] . '</a><br>' . $whats_new_price);

 

new infoBox($info_box_contents, $column_location);

?>

</td>

</tr>

<!-- whats_new_eof //-->

<?php

}

?>

 

-----------------------------------------------------------------------------------------------

Link to comment
Share on other sites

replace:

 

if ($random_product = tep_random_select("select products_id, products_image, products_tax_class_id, products_price from " . TABLE_PRODUCTS . " where products_status = '1' order by products_date_added desc limit " . MAX_RANDOM_SELECT_NEW))

 

with:

 

 if ($random_product = tep_random_select("select p2c.categories_id, p.products_id, p.products_image, p.products_tax_class_id, p.products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and ((p2c.categories_id = 32) or (p2c.categories_id = 101) or (p2c.categories_id = 113)) and products_status = '1' order by products_date_added desc limit " . MAX_RANDOM_SELECT_NEW))

Your online success is Paramount.

Link to comment
Share on other sites

thanks for giving it a go....

 

i get this error message:

 

Parse error: parse error, unexpected '}' in /home/domian/public_html/catalog/includes/boxes/whats_new.php on line 44

Link to comment
Share on other sites

sorry for the delay..

 

OK I see this has change the What's New? box on left rather than the main New Products For May box on the Home Page.

 

Sorry maybe I wasnt clear.. I need the main New Products For May box on the home page to display products from certain Categories.

 

Hope you can help

Link to comment
Share on other sites

  • 2 weeks later...

The issue is that you posted the code for the whats_new.php for Yesudo to work on when you should have posted the file for the box that you wanted the change which is the new products box this file is in catalog/includes/modules/new_products.php

 

If you post that file Emmett will probably pop back and do an edit for you. ;)

No longer giving free advice. Please place deposit in meter slot provided.  Individual: [=] SME: [==] Corporation: [===]
If deposit does not fit one of the slots provided then you are asking too much! :P

Is your Osc dated try Phoenix  raising oscommerce from the ashes.

Link to comment
Share on other sites

I'm not Gomez so I haven't posted or not posted anything :)

 

If the code is needed it is:

 

  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, 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 where products_status = '1' order by p.products_date_added desc 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, 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_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' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);

  }

Link to comment
Share on other sites

ok if you look at the code changes that Emmett made and transfer that code change to the code that THX has just posted then you should have what you want. :D

No longer giving free advice. Please place deposit in meter slot provided.  Individual: [=] SME: [==] Corporation: [===]
If deposit does not fit one of the slots provided then you are asking too much! :P

Is your Osc dated try Phoenix  raising oscommerce from the ashes.

Link to comment
Share on other sites

Hello apologise for the delay again.. I have been away on business..

 

This code that THX kindly written:

 

 

? 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, 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 where products_status = '1' order by p.products_date_added desc 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, 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_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' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);

? }

 

 

 

needs to replace which piece of code within catalog/includes/modules/new_products.php

 

<?php

/*

  $Id: new_products.php,v 1.34 2003/06/09 22:49:58 hpdl Exp $

 

  osCommerce, Open Source E-Commerce Solutions

  http://www.oscommerce.com

 

  Copyright © 2003 osCommerce

 

  Released under the GNU General Public License

*/

?>

<!-- new_products //-->

<?php

  $info_box_contents = array();

  $info_box_contents[] = array('text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));

 

  new contentBoxHeading($info_box_contents);

 

  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, 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 where products_status = '1' order by p.products_date_added desc 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, 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_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' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);

  }

 

  $row = 0;

  $col = 0;

  $info_box_contents = array();

  while ($new_products = tep_db_fetch_array($new_products_query)) {

    $new_products['products_name'] = tep_get_products_name($new_products['products_id']);

    #PR Build product information box

    $product_info_str = '<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr>';

    $product_info_str .= '<td height="14" class="productBoxHeadingLcorner"></td>';

    $product_info_str .= '<td height="14" class="productBoxHeading"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . $new_products['products_name'] . '</a> </td>';

    $product_info_str .= '<td height="14" class="productBoxHeadingRcorner"></td>';

    $product_info_str .= '</tr></table>';

    $product_info_str .= '<table border="0" width="100%" cellspacing="0" cellpadding="0" class="productBox" valign="top"><tr><td>';

    $product_info_str .= '<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>';

    $product_info_str .= '</td><td>';

    $product_info_str .= '' . $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id']));

    $product_info_str .= '<br><br><a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $new_products['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a>';

    $product_info_str .= '</td></tr></table>';

    $info_box_contents[$row][$col] = array('align' => 'center',

                                          'params' => 'class="smallText" width="33%" valign="top"',

                                          'text' => $product_info_str);

 

    $col ++;

    if ($col > 2) {

      $col = 0;

      $row ++;

    }

  }

 

  new newProductsBox($info_box_contents);

?>

<!-- new_products_eof //-->

Link to comment
Share on other sites

Seems to have been some confusion, the code I posted is the original code. I was posting this so someone could review it and post the necessary code change to allow what gomez wants to happen.

Link to comment
Share on other sites

Your contribution works gorn but it does not recurse the sub categories so if I select category 1 which has 5 categories beneath it all filled with products, I only get products in the root category 1 nothing from the 5 below it.

Link to comment
Share on other sites

  • 4 weeks later...

Hi All,

I found this thread looking for the same thing.

I wanted to display only selected items from a particular category. I have two boxes on the homepage - e.g. 1 box for "flowers", the other for "flowerpots".

 

I only wanted one of each category in each box...

 

The MySQL replacement statement in this thread seemed to have a few issues, but I used it with success after fixing up the ",p" and a few other bits.

 

On line 15 of the whats_new.php , I corrected it to read as below (my Category product number happens to be 26, so change this to whatever your category is).

 

if ($random_product = tep_random_select("select products_to_categories.categories_id, products.products_id, products.products_image, products.products_tax_class_id, products.products_price from " . TABLE_PRODUCTS ." , " . TABLE_PRODUCTS_TO_CATEGORIES . " where products.products_id = products_to_categories.products_id and products_to_categories.categories_id = 26 and products_status = '1' order by products_date_added desc limit " . MAX_RANDOM_SELECT_NEW)) {

 

I love Open-Source... who needs big corps. to empty your bank when we can all help each other...

 

Paul :

:ph34r: ;)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...