Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Special Price in Latest Products Module (index)


Marc_J

Recommended Posts

I just noticed that everywhere except the "New Products for [this month]" module at the bottom of the index page displays Special prices correctly - i.e. usual price scored out, and the Special price in red below it.

 

However, the "New Products for...." on the index displays only the special price, but with no indication that this is a special price.

 

Is there any easy way to fix this?

Link to comment
Share on other sites

well just put that together havent tested it for syntax but should be close to what you need. So in includes\modules\new_products.php replace the if/else statements:

 

 ?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, NULL) as products_retail_price, 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, NULL) as products_retail_price, 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);
?}

 

 

 

then when it loads the array put this:

 

 ? ?$info_box_contents[$row][$col] = array('align' => 'center',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'params' => 'class="smallText" width="33%" valign="top"',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? '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_retail_price'], tep_get_tax_rate($new_products['products_tax_class_id'])) . '<br>' . $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])));

 

finally you could setup the css for strike/bold combinations

 

forgot to mention to backup first

Link to comment
Share on other sites

Many thanks, Mark!

 

I'm sure that would have worked, but I forgot to mention that I installed a Random New Products contrib!

 

And just to complicate it further, I (well, Beer Monster actually) merged that with Include all Subcategories for 'New Products in ...'

 

See this topic for details of the merge, or for simplicity here's my new_products.php :-

 

<?php
/*
$Id: new_products.php,v 1.35 2004/02/05 15:50:00 adf Exp $
Randomize New Products
$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 (c) 2003 osCommerce

Released under the GNU General Public License
*/
?>
<!-- new_products //-->
<?php

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
// start random new products
?$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_RANDOM_SELECT_NEW);
} else { ? // in a category

$cats[] = $new_products_category_id; // current catID as starting value
// put cat-IDs of all cats nested in current branch into $cats array, go through all subbranches
for($i=0;$i<count($cats);$i++) {
$categorie_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$cats[$i] . "'"); 
while ($categorie = tep_db_fetch_array($categorie_query)) {
$cats[] = $categorie['categories_id'];
}
$cats=array_unique($cats); // sort out doubles
}

$num = (int) MAX_DISPLAY_NEW_PRODUCTS;
$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 in (".implode(', ', $cats).") and p.products_status = '1' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);
// end random new products ? ?
}

if (tep_db_num_rows($new_products_query) > 0) {
$info_box_contents = array();
$info_box_contents[] = array('text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));
new contentBoxHeading($info_box_contents);
$row = 0;
$col = 0;
$pCount = 0;
$info_box_contents = array();
$found_products = array();
$num_rows = tep_db_num_rows($new_products_query);
if (MAX_DISPLAY_NEW_PRODUCTS > MAX_RANDOM_SELECT_NEW) {
?// don't allow more new products than will be queried
?$max_new_products = MAX_RANDOM_SELECT_NEW;
} else {
?$max_new_products = MAX_DISPLAY_NEW_PRODUCTS;
}
if ($num_rows < $max_new_products) {
$max_new_products = $num_rows;
}
// ?echo "num_rows: " . $num_rows . " max_new_products " . $max_new_products . "<br>";
if ($num_rows > 0) { ? ? ? ?
?while ($pCount < $max_new_products) { ? ?
? ?// choose a random row 
? ?$random_product = '';
? ?$random_row = tep_rand(0, ($num_rows - 1));
? ?tep_db_data_seek($new_products_query, $random_row);
? ?$random_product = tep_db_fetch_array($new_products_query);
? ?// see if found already, if not use else skip
? ?$found = 0;
? ?for ($ii=0; $ii < $pCount; $ii++) {
? ? ?if ($found_products[$ii] == $random_product['products_id']) {
? ? ? ?$found = 1;
? ? ? ?break;
? ? ?}
? ?}
? ?if ($found == 0) {
? ? ?// keep track of found id's
? ? ?$found_products[$pCount] += $random_product['products_id'];
? ? ?$pCount ++; 
? ? ?// add to display array
? ? ?$random_product['products_name'] = tep_get_products_name($random_product['products_id']);
? ? ?$info_box_contents[$row][$col] = array('align' => 'center',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'params' => 'class="smallText" width="33%" valign="top"',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? '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'])));
? ? ?$col ++;
? ? ?if ($col > 2) {
? ? ? ?$col = 0;
? ? ? ?$row ++;
? ? ?}
? ?} // found
?} // while pCount
} // num_rows ?
// end random new products

new contentBox($info_box_contents);
}
?>
<!-- new_products_eof //-->

 

Any pointers?

Link to comment
Share on other sites

ok then extend the queries you have a bit like I did. You need the original price field so previously I added with the queries this:

 

if(s.status, s.specials_new_products_price, NULL) as products_retail_price,

you could add it before the 'if' you have with your queries; and to display add after the '</a><br>' this:

 . $currencies->display_price($new_products['products_retail_price'], tep_get_tax_rate($new_products['products_tax_class_id'])) . '<br>' .

Link to comment
Share on other sites

ok then extend the queries you have a bit like I did. You need the original price field so previously I added with the queries this:

 

if(s.status, s.specials_new_products_price, NULL) as products_retail_price,

you could add it before the 'if' you have with your queries; and to display add after the '</a><br>' this:

 . $currencies->display_price($new_products['products_retail_price'], tep_get_tax_rate($new_products['products_tax_class_id'])) . '<br>' .

 

I'm sorry, this seems to be a little beyond me :( The closest I came was geting a "regular" price of ?0.00 displayed, with no score-through, and below that the correct special price (in black, not red). Half way there it seems, but my tweaking only makes things worse!

 

So, I'm still stuck, my if / else looks like this: -

 

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
// start random new products
?$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_RANDOM_SELECT_NEW);
} else { ? // in a category

$cats[] = $new_products_category_id; // current catID as starting value
// put cat-IDs of all cats nested in current branch into $cats array, go through all subbranches
for($i=0;$i<count($cats);$i++) {
$categorie_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$cats[$i] . "'"); 
while ($categorie = tep_db_fetch_array($categorie_query)) {
$cats[] = $categorie['categories_id'];
}
$cats=array_unique($cats); // sort out doubles
}

$num = (int) MAX_DISPLAY_NEW_PRODUCTS;
$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 in (".implode(', ', $cats).") and p.products_status = '1' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);
// end random new products ? ?
}

 

and my contents is like this: -

 

 ? ? ?$info_box_contents[$row][$col] = array('align' => 'center',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'params' => 'class="smallText" width="33%" valign="top"',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? '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'])));

 

Despite your help, all I really know for sure is that it's only these two areas that need edited - I think!

Link to comment
Share on other sites

Here are the 3 parts you need to change with the file you posted

 

1st query

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
// start random new products
$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, NULL) as products_retail_price, 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_RANDOM_SELECT_NEW);
} else {   // in a category

 

2nd query

$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, NULL) as products_retail_price, 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 in (".implode(', ', $cats).") and p.products_status = '1' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);
// end random new products    
}

 

 

Finally the display

     $info_box_contents[$row][$col] = array('align' => 'center',
                                       'params' => 'class="smallText" width="33%" valign="top"',
                                       '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($new_products['products_retail_price'], tep_get_tax_rate($new_products['products_tax_class_id'])) . '<br>' . $currencies->display_price($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])));

Link to comment
Share on other sites

This has exactly the same results as I had: -

 

The "regular" price is displayed as ?0.00, with no score-through, and below that the correct special price (in black, not red).

 

ALthough I did initially get an error, and had to remove a duplicate ' . ' from here in your display code: -

 

$random_product['products_name'] . '</a><br>' . . $currencies->display_price($new_products['products_retail_price']

 

???

Link to comment
Share on other sites

hmm.. should had payed better attention when I redid the queries Ok,

 

First query

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
// start random new products
$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_price, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as specials_new_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_RANDOM_SELECT_NEW);
} else {   // in a category

Second query

$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_price, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as specials_new_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 in (".implode(', ', $cats).") and p.products_status = '1' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);
// end random new products    
}

 

and for the display:

$info_box_contents[$row][$col] = array('align' => 'center',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'params' => 'class="smallText" width="33%" valign="top"',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? '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><s>' . $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])) . '</s><br><span class="productSpecialPrice">' . $currencies->display_price($random_product['specials_new_products_price '], tep_get_tax_rate($random_product['products_tax_class_id'])) . '</span'>);

 

But you also need to add an if else statement and keep the old code so if there is a special price for the new product you display the new code otherwise the old code. For the color info I used the productsSpecialPrice css entry cant remember if it exists in the default core.

Link to comment
Share on other sites

I applied these changes (class productsSpecialPrice is OK), without worrying about the additional if else you suggest (one step at a time!) and got the following error: -

 

Parse error: parse error, unexpected ')' in /home/username/public_html/includes/modules/new_products.php on line 81

 

new_products.php currently looks like: -

 

<?php
/*
$Id: new_products.php,v 1.35 2004/02/05 15:50:00 adf Exp $
Randomize New Products
$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 (c) 2003 osCommerce

Released under the GNU General Public License
*/
?>
<!-- new_products //-->
<?php

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
// start random new products
$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_price, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as specials_new_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_RANDOM_SELECT_NEW);
} else { ? // in a category

$cats[] = $new_products_category_id; // current catID as starting value
// put cat-IDs of all cats nested in current branch into $cats array, go through all subbranches
for($i=0;$i<count($cats);$i++) {
$categorie_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$cats[$i] . "'"); 
while ($categorie = tep_db_fetch_array($categorie_query)) {
$cats[] = $categorie['categories_id'];
}
$cats=array_unique($cats); // sort out doubles
}

$num = (int) MAX_DISPLAY_NEW_PRODUCTS;
$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_price, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as specials_new_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 in (".implode(', ', $cats).") and p.products_status = '1' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);
// end random new products ? ?
}

if (tep_db_num_rows($new_products_query) > 0) {
$info_box_contents = array();
$info_box_contents[] = array('text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));
new contentBoxHeading($info_box_contents);
$row = 0;
$col = 0;
$pCount = 0;
$info_box_contents = array();
$found_products = array();
$num_rows = tep_db_num_rows($new_products_query);
if (MAX_DISPLAY_NEW_PRODUCTS > MAX_RANDOM_SELECT_NEW) {
?// don't allow more new products than will be queried
?$max_new_products = MAX_RANDOM_SELECT_NEW;
} else {
?$max_new_products = MAX_DISPLAY_NEW_PRODUCTS;
}
if ($num_rows < $max_new_products) {
$max_new_products = $num_rows;
}
// ?echo "num_rows: " . $num_rows . " max_new_products " . $max_new_products . "<br>";
if ($num_rows > 0) { ? ? ? ?
?while ($pCount < $max_new_products) { ? ?
? ?// choose a random row 
? ?$random_product = '';
? ?$random_row = tep_rand(0, ($num_rows - 1));
? ?tep_db_data_seek($new_products_query, $random_row);
? ?$random_product = tep_db_fetch_array($new_products_query);
? ?// see if found already, if not use else skip
? ?$found = 0;
? ?for ($ii=0; $ii < $pCount; $ii++) {
? ? ?if ($found_products[$ii] == $random_product['products_id']) {
? ? ? ?$found = 1;
? ? ? ?break;
? ? ?}
? ?}
? ?if ($found == 0) {
? ? ?// keep track of found id's
? ? ?$found_products[$pCount] += $random_product['products_id'];
? ? ?$pCount ++; 
? ? ?// add to display array
? ? ?$random_product['products_name'] = tep_get_products_name($random_product['products_id']);
? ? ?$info_box_contents[$row][$col] = array('align' => 'center',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'params' => 'class="smallText" width="33%" valign="top"',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'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><s>' . $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])) . '</s><br><span class="productSpecialPrice">' . $currencies->display_price($random_product['specials_new_products_price '], tep_get_tax_rate($random_product['products_tax_class_id'])) . '</span'>);
? ? ?$col ++;
? ? ?if ($col > 2) {
? ? ? ?$col = 0;
? ? ? ?$row ++;
? ? ?}
? ?} // found
?} // while pCount
} // num_rows ?
// end random new products

new contentBox($info_box_contents);
}
?>
<!-- new_products_eof //-->

 

FYI, line 81 is the line that starts 'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO......... in the display code.

Link to comment
Share on other sites

this part of the line

 

'</span'>);

 

correct it like this

 

'</span>');

 

let me know if you still get the error.

 

The error's gone, now everything's in the correct format, but values are all ?0.00 (i.e. regular price is ?0.00 in black, scored through, and special price is ?0.00 in red below it)...

Link to comment
Share on other sites

this part

['specials_new_products_price ']

 

there is an extra space at the end should be:

 

['specials_new_products_price']

 

and the in the display line change this part:

$currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id']))

 

to

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

because we do not have a $new_products variable, everything goes through the random thingy.

Link to comment
Share on other sites

Success! :) :)

 

Thank-you!

 

I'll try to add the additional if else to check for non-special products myself, but don't be surprised if I'm back for more help!

 

Thanks again. Once this is all done, and if I have time, I'll up it as a contrib as I think it's quite a useful new_products module because it

  • randomizes new products
  • includes sub-categories
  • indicates specials

All of which are, in my opinion, an improvement on the default - or at least useful to have as an option!

 

I will, of course, give full credit to everyone involved, as I did none of the work myself :blush:

Link to comment
Share on other sites

glad it works now, man this syntax its so hard when you code without testing :D we need more intelligent syntax parsers to correct these mistakes. :rolleyes:

Link to comment
Share on other sites

OK, I looked at includes/boxes/whats_new.php and took a little code (the if else for specials prices) from there which I think (I may be wrong) tidies things up a little.

 

What it does is defines a whats_new_price variable (is it OK to use this, as it's already in use on the same page in the "what's new" infobox?), which is then used in the display code.

 

So, my includes/modules/new_products.php now looks like this: -

 

<?php
/*
$Id: new_products.php,v 1.35 2004/02/05 15:50:00 adf Exp $
Randomize New Products
$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 (c) 2003 osCommerce

Released under the GNU General Public License
*/
?>
<!-- new_products //-->
<?php

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
// start random new products
$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_price, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as specials_new_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_RANDOM_SELECT_NEW);
} else {   // in a category

$cats[] = $new_products_category_id; // current catID as starting value
// put cat-IDs of all cats nested in current branch into $cats array, go through all subbranches
for($i=0;$i<count($cats);$i++) {
$categorie_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$cats[$i] . "'"); 
while ($categorie = tep_db_fetch_array($categorie_query)) {
$cats[] = $categorie['categories_id'];
}
$cats=array_unique($cats); // sort out doubles
}

$num = (int) MAX_DISPLAY_NEW_PRODUCTS;
$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_price, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as specials_new_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 in (".implode(', ', $cats).") and p.products_status = '1' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);
// end random new products    
}

if (tep_db_num_rows($new_products_query) > 0) {
$info_box_contents = array();
$info_box_contents[] = array('text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));
new contentBoxHeading($info_box_contents);
$row = 0;
$col = 0;
$pCount = 0;
$info_box_contents = array();
$found_products = array();
$num_rows = tep_db_num_rows($new_products_query);
if (MAX_DISPLAY_NEW_PRODUCTS > MAX_RANDOM_SELECT_NEW) {
 // don't allow more new products than will be queried
 $max_new_products = MAX_RANDOM_SELECT_NEW;
} else {
 $max_new_products = MAX_DISPLAY_NEW_PRODUCTS;
}
if ($num_rows < $max_new_products) {
$max_new_products = $num_rows;
}
//  echo "num_rows: " . $num_rows . " max_new_products " . $max_new_products . "<br>";
if ($num_rows > 0) {        
 while ($pCount < $max_new_products) {    
   // choose a random row 
   $random_product = '';
   $random_row = tep_rand(0, ($num_rows - 1));
   tep_db_data_seek($new_products_query, $random_row);
   $random_product = tep_db_fetch_array($new_products_query);
   // see if found already, if not use else skip
   $found = 0;
   for ($ii=0; $ii < $pCount; $ii++) {
     if ($found_products[$ii] == $random_product['products_id']) {
       $found = 1;
       break;
     }
   }
   if ($found == 0) {
     // keep track of found id's
     $found_products[$pCount] += $random_product['products_id'];
     $pCount ++; 
     // add to display array
     $random_product['products_name'] = tep_get_products_name($random_product['products_id']);

   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[$row][$col] = array('align' => 'center',
                                     'params' => 'class="smallText" width="33%" valign="top"',
                                     '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);
     $col ++;
     if ($col > 2) {
       $col = 0;
       $row ++;
     }
   } // found
 } // while pCount
} // num_rows  
// end random new products

new contentBox($info_box_contents);
}
?>
<!-- new_products_eof //-->

 

Specials show up correctly. However, non-specials still show up the same as before I applied this, i.e. looks like a special price, but with the same price twice (scored out in black, and below it in red).

 

????

Link to comment
Share on other sites

I fixed it (I think)...

 

I added

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

 

just before the if else defining whats_new_price .... and it worked!

 

However, I'm not sure if this is strictly correct or a messy way of doing things. As I said before I'd like to up this as a contrib, so would like it "correct".

 

Can it be tidied up any further, or is it good as it is?

Link to comment
Share on other sites

  • 1 month later...
does anyone know how to make this display in 2 columns instead of 3 columns?

 

Replace: -

 

	  $info_box_contents[$row][$col] = array('align' => 'center',
								  'params' => 'class="smallText" width="33%" valign="bottom"',
								  '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);
  $col ++;
  if ($col > 2) {
	$col = 0;
	$row ++;

 

With: -

 

	  $info_box_contents[$row][$col] = array('align' => 'center',
								  'params' => 'class="smallText" width="50%" valign="bottom"',
								  '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);
  $col ++;
  if ($col > 1) {
	$col = 0;
	$row ++;

 

Should work. The only parts actually changed are width="33%" to width="50%" and if ($col > 2) to if ($col > 1)

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...