Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Random New Products Shows Specials inc SubCats 1.0


Marc_J

Recommended Posts

Random New Products Shows Specials inc SubCats 1.0

September 14, 2005

Author: Marc J

Contributors : Nils Petersson, Allen Fox, Beer Monster, enigma1

 

This contribution can be downloaded from http://www.oscommerce.com/community/contributions,3546

 

Overview

This contribution combines the following 2 existing contributions: -

 

Include all Subcategories for 'New Products in ...' v1.0b

http://www.oscommerce.com/community/contributions,2053

 

and

 

Random New Products 1.1

http://www.oscommerce.com/community/contributions,1849

 

and also adds the displaying of Specials to the New Products module, instead of Specials being displayed as a regular price.

 

The contribution started life with the following topics: -

 

http://www.oscommerce.com/forums/index.php?showtopic=161445

 

and

 

http://www.oscommerce.com/forums/index.php?showtopic=169938

 

 

Easy installation, replacement of 1 file: -

 

catalog/includes/modules/new_products.php

 

This is the support thread, for what it's worth....I hardly did any of the coding (full credit to the contributors named above), so can't promise much help, but hopefully someone will!

 

This is my 1st contribution, so might be a little untidy - but it works!

Link to comment
Share on other sites

  • 6 months later...
Thank you for the contribution, but is there any way to modify new_products.php to work with Seperate Pricing Per Customer contribution?

 

Thanks.

 

I've never used that particular contribution, but it's probably just a case of using a file comparison tool (such as www.compareandmerge.com) on the two files, and some trial and error.

 

I could try but without having an installation of SPPC there's no way for me to test. If you hit a brick wall then I'll give it a try, it might be entertaining at least!

Link to comment
Share on other sites

  • 3 weeks later...

Hello,

Like this it looks my includes/modules/new_products.php when Separate Pricing Per Customer is installed.

<?php
/*
 $Id: new_products.php,v 1.34 2003/06/09 22:49:58 hpdl Exp $
 adapted for Separate Pricing Per Customer v4.0 2005/01/26

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

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/
?>
<!-- new_products //-->
<table id="products_new" width="100%"  border="0" cellspacing="0" cellpadding="0">
 <tr>
<td width=100%><div id="products_new_div">
 <?php $info_box_contents = array(); ?>
		<?php echo '<a href="products_new.php">' . tep_image(DIR_WS_IMAGES . 'orange-arrow.gif', ICON_ARROW_RIGHT) . '</a>'; ?>
		  <?php echo sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')); ?></div></td>
  <TD width=7 vAlign=top background=images/dropshadow_right.jpg ><IMG src="images/dropshadow_topright.jpg" width=7></TD>

 </tr>
</table>
<?php

 if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
// BOF Separate Pricing per Customer
$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, p.products_price as products_price from " . TABLE_PRODUCTS . " p 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, p.products_price as products_price from " . TABLE_PRODUCTS . " p, " . 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);
 }

// global variable (session) $sppc_customer_group_id -> local variable customer_group_id

 if(!tep_session_is_registered('sppc_customer_group_id')) {
 $customer_group_id = '0';
 } else {
  $customer_group_id = $sppc_customer_group_id;
 }

 if (($no_of_new_products = tep_db_num_rows($new_products_query)) > 0) {
  while ($_new_products = tep_db_fetch_array($new_products_query)) {
$new_products[] = $_new_products;
$list_of_prdct_ids[] = $_new_products['products_id'];
}

$select_list_of_prdct_ids = "products_id = '".$list_of_prdct_ids[0]."' ";
 if ($no_of_new_products > 1) {
  for ($n = 1; $n < count($list_of_prdct_ids); $n++) {
  $select_list_of_prdct_ids .= "or products_id = '".$list_of_prdct_ids[$n]."' ";
  }
}
// get all customers_group_prices for products with the particular customer_group_id
// however not necessary for customer_group_id = 0
if ($customer_group_id != '0') {
 $pg_query = tep_db_query("select pg.products_id, customers_group_price as price from " . TABLE_PRODUCTS_GROUPS . " pg where (".$select_list_of_prdct_ids.") and pg.customers_group_id = '".$customer_group_id."'");
while ($pg_array = tep_db_fetch_array($pg_query)) {
$new_prices[] = array ('products_id' => $pg_array['products_id'], 'products_price' => $pg_array['price'], 'specials_new_products_price' => '');
}

  for ($x = 0; $x < $no_of_new_products; $x++) {
// replace products prices with those from customers_group table
	if(!empty($new_prices)) {
	for ($i = 0; $i < count($new_prices); $i++) {
		if( $new_products[$x]['products_id'] == $new_prices[$i]['products_id'] ) {
		$new_products[$x]['products_price'] = $new_prices[$i]['products_price'];
		}
	}
} // end if(!empty($new_prices)
  } // end for ($x = 0; $x < $no_of_products_new; $x++)
} // end if ($customer_group_id != '0')

// an extra query is needed for all the specials
$specials_query = tep_db_query("select products_id, specials_new_products_price from specials where (".$select_list_of_prdct_ids.") and status = '1' and customers_group_id = '" .$customer_group_id. "' ");
while ($specials_array = tep_db_fetch_array($specials_query)) {
$new_s_prices[] = array ('products_id' => $specials_array['products_id'], 'specials_new_products_price' => $specials_array['specials_new_products_price']);
}

// replace products_price with the correct specials_new_products_price
if(!empty($new_s_prices)) {
for ($x = 0; $x < $no_of_new_products; $x++) {
	for ($i = 0; $i < count($new_s_prices); $i++) {
		if( $new_products[$x]['products_id'] == $new_s_prices[$i]['products_id'] ) {
		$new_products[$x]['products_price'] = $new_s_prices[$i]['specials_new_products_price'];
		}
	   }
   }
} // // end if(!empty($new_s_prices)

 $row = 0;
 $col = 0;

 $info_box_contents = array();

//  while ($new_products = tep_db_fetch_array($new_products_query)) {
for ($x = 0; $x < $no_of_new_products; $x++) {
$new_products[$x]['products_name'] = tep_get_products_name($new_products[$x]['products_id']);

$info_box_contents[$row][$col] = array('align' => 'center',
									   'params' => 'width="33%" height="100%" valign="top"',
									   'text' => '<table class="new_product" border="0" width="100%" height="100%" cellspacing="0" cellpadding="0"><tr><td valign="top"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products[$x]['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products[$x]['products_image'], $new_products[$x]['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products[$x]['products_id']) . '">' . $new_products[$x]['products_name'] . '</a><br>' . $currencies->display_price($new_products[$x]['products_price'], tep_get_tax_rate($new_products[$x]['products_tax_class_id'])). '</td></tr></table>');

$col ++;
if ($col > 2) {
  $col = 0;
  $row ++;
}
  } // end for ($x = 0; $x < $no_of_new_products; $x++)
} //  end if (($no_of_new_products = tep_db_num_rows($new_products_query)) > 0)
// EOF Separate Pricing per Customer
new contentBox($info_box_contents);
?>
<!-- new_products_eof //-->

Can you do something?

Thanks.

Edited by invasi0n
Link to comment
Share on other sites

  • 3 months later...

Hello, great contrib - thank you. Is there a way to make this contribution pull random new products from only the current category and the sub catagories that belong to it? (As opposed to selecting from all catagories and sub-categories of the store.)

 

thanks in advance!

 

scott

www.tacticaldivision.com

www.jungleblowgun.com

Link to comment
Share on other sites

Hi

 

Inexperienced newbie needs help! My catalog does not have large numbers of new products so I want to keep the front page looking fresh.

 

I was under the impression that this Contribution would allow the random selection from my entire catolog - maybe I got this wrong? But having uploaded the new file and changed the configuration I still have the 9 newest products on the front page.

 

Any suggestions please Thanks

Link to comment
Share on other sites

Hi guys, welcome to osC and the forums.

 

Hello, great contrib - thank you. Is there a way to make this contribution pull random new products from only the current category and the sub catagories that belong to it? (As opposed to selecting from all catagories and sub-categories of the store.)

Scott, this should already be the case. There's something wrong with your implementation if it's pulling products from all over.

 

I was under the impression that this Contribution would allow the random selection from my entire catolog - maybe I got this wrong? But having uploaded the new file and changed the configuration I still have the 9 newest products on the front page.

John, you have to change the admin setting: admin--->configuration--->maximum values--->selection of random new products.

 

Change this to something higher (higher than the number fo products you have, if you want to randomly select from them all).

Edited by Marc_J
Link to comment
Share on other sites

Hi guys, welcome to osC and the forums.

..............................................John, you have to change the admin setting: admin--->configuration--->maximum values--->selection of random new products.

 

Change this to something higher (higher than the number fo products you have, if you want to randomly select from them all).

Marc Hi - thanks for your help on this

 

What I want to do is randomly choose products no matter how old they are - if this is what your contribution is intended to do then I must have done something wrong as even when I change the

maximum value for selection of random new products to more than my catalog No. I still get the 9 latest items ?? .

 

Confused - any pointers greatly appreciated.

 

Cheers

Link to comment
Share on other sites

Marc Hi - thanks for your help on this

 

What I want to do is randomly choose products no matter how old they are - if this is what your contribution is intended to do then I must have done something wrong as even when I change the

maximum value for selection of random new products to more than my catalog No. I still get the 9 latest items ?? .

 

Confused - any pointers greatly appreciated.

 

Cheers

 

Marc ignore this - I have now uploaded it properly!! and it works fine - just what I wanted thanks for your help John

Link to comment
Share on other sites

Hi guys, welcome to osC and the forums.

Scott, this should already be the case. There's something wrong with your implementation if it's pulling products from all over.

 

Thanks Marc, there was indeed an error in my index.php coding at "$new_products_category_id = $current_category_id;"

 

Fixed now and working perfectly.

Thanks much!

Link to comment
Share on other sites

  • 3 weeks later...

i am tring to modify one line to hide the price if it is equal to ZERO

 

i show the cahnge i had to do for he orignal file and then the one i did one the file given in Random New Products Shows Specials inc SubCats 1.0

 

 

origianal new_products.php:

 

changed :

'text' => '<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><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . $new_products['products_name'] . '</a><br>' . $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])));

 

by

 

'text' => '<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><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . $new_products['products_name'] . '</a><br>' . (($new_products['products_price'] > 0) ? $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])) : ZERO_PRICE_TEXT);

 

 

on the Random New Products Shows Specials inc SubCats 1.0 new_products.php

 

changed

 

'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);

 

by

 

'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> 0) ? $whats_new_price : ZERO_PRICE_TEXT));

 

and it doesnt work i always got the ZERO_PRICE_TEXT that show even if price is sup to zero :huh:

MS2

Link to comment
Share on other sites

i noticed it was working in euro my deflaut currency but not in other so

i changed the code to this one , by compraing at the original ms2 code , and i see now it s working for all currencies :

 

  '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>' . (($random_product['products_price'] > 0) ? $currencies->display_price($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) : ZERO_PRICE_TEXT));

 

im released a new version guys tell me if you are all right with my code :rolleyes:

MS2

Link to comment
Share on other sites

forget my previous post read this

 

i noticed it was working in euro my deflaut currency but not in other so

i changed the code to this one , by comparing at the original ms2 code , and i see now it s working for all currencies :

 

 

for people u use hide if price = zero :

 

  '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>' . (($random_product['products_price'] > 0) ? $currencies->display_price($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) : ZERO_PRICE_TEXT));

 

that maybe means also , for people u dont use my hide if price = zero contrib , it still got to be using the currency function

im releasing a new version guys tell me if you are all right with my code :rolleyes:

 

then for all others u dont use this contrib it would be :

 

  '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>' 
. $currencies->display_price($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])));

MS2

Link to comment
Share on other sites

I just installed this mod and everything works fine, apart from it only displays the last 9 products, although it does display them randomly. I've tried setting New Products Module to 50, 100, 500 and it makes no difference. I have New Products Module set to 9.

 

I've tried using the complete new_products.php file and just editing the existing one.

 

Any ideas?

Link to comment
Share on other sites

I just installed this mod and everything works fine, apart from it only displays the last 9 products, although it does display them randomly. I've tried setting New Products Module to 50, 100, 500 and it makes no difference. I have New Products Module set to 9.

 

I've tried using the complete new_products.php file and just editing the existing one.

 

Any ideas?

 

There are two figures in admin that deal with new products, the one you're changing deals with the new prodcts page (marked "New Products Listing"), not the one this module uses which is (probably 3 above the one you're changing): -

 

admin--->configuration--->maximum values--->selection of random new products.

Edited by Marc_J
Link to comment
Share on other sites

There are two figures in admin that deal with new products, the one you're changing deals with the new prodcts page (marked "New Products Listing"), not the one this module uses which is (probably 3 above the one you're changing): -

 

admin--->configuration--->maximum values--->selection of random new products.

Yeah, I've tried that too. Made a mistake in my first post, should have said I have Selection of Random New Products set to 9.

 

I have tried different settings, but it just shows the same products, just randomly. ie: I set Selection of Random New Products to 9, I see the same 9 products randomly displayed, I set it to 15 I see the same 15 products randomly displayed.

Link to comment
Share on other sites

Yeah, I've tried that too. Made a mistake in my first post, should have said I have Selection of Random New Products set to 9.

 

I have tried different settings, but it just shows the same products, just randomly. ie: I set Selection of Random New Products to 9, I see the same 9 products randomly displayed, I set it to 15 I see the same 15 products randomly displayed.

 

Thats EXACTLY what it's supposed to do. The number in the "Selection of Random New Products" field tells the module how far back to pick new products from - 15 picks from the last 15 products added.

 

It wil display (by default) 9, which can be changed by changing the "New Products Module" number.

 

I'm not quite sure what you're not managing to do - if you have 500 products and you want it to select from your complete catalogue, just set "Selection of Random New Products" to 500, then it'll display the same 500 products randomly, 9 at a time!

Link to comment
Share on other sites

  • 2 weeks later...

Hi everyone...

 

I don't know whether or not this is helpful, but I've spent hours trying to do it and it is so simple... (I could be repeating something that is already covered here, excuse my stupidity)

 

I wanted to make the specials in the body on my mainpage random, similar to what a lot of people are doing with their new products boxes...

 

The trouble was, while the display of the products selected from the database was random, the actual selection of them was not. So for example the code would select 10 products, and then display those 10 products randomly. I wanted it to select 10 random products and then display them.

 

// start random new products
$new_products_query = tep_db_query("select p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s where p.products_status = '1' and s.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and s.status = '1' order by rand() limit " . MAX_DISPLAY_SPECIAL_PRODUCTS);

// end random new products

 

You will notice on the last line I have chaned what is normally "order by s.products_id desc" or "order by p.products_date_added desc" to "order by rand()"

 

That is all you need to do to get random queries from the database! I hope this helps someone I had been trying to work it out for ages!

Link to comment
Share on other sites

When I use this contribution, I lose the border around "New Products". How can I get it back? I've tried looking at the old one but cannot figure it out. Thanks!

 

This shouldn't be the case with a default MS2.2 installation. Perhaps you've installed other contributions which deal with the look of your store?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...