Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Specials on Default - Make Random


jond

Recommended Posts

Ive seen several requests for making Specials on Default mod display random products, instead of showing newest.

 

I too would like to do this. How could the specials on default code be modified to show random products?

 

thanks in advance!

Link to comment
Share on other sites

Ive seen several requests for making Specials on Default mod display random products, instead of showing newest.

 

I too would like to do this. How could the specials on default code be modified to show random products?

 

thanks in advance!

 

I played with this option myself just a few days ago kind of duplicating the New products Random Mod.

However it overall it failed.

I was able to get it working on the Index page but then it failed when going to a catagory option of 2 or more further catagories.

I was able to then get it working on the catagories page but then it failed on the Index page.

Ultimately I gave up a bit frustrated and was just now looking to see if anyone else had acheived this option. It would be really great, I too am not really a php person but can tinker with some knowledge and thats about it.

 

Hope someone is out there that either can or has done this and can help.

Link to comment
Share on other sites

I appreciate the reply.

 

I actually just use the specials on default mod on my index.php page, so the modification you did would work great for me. Could you let me know how you got the random to work on your index?

Link to comment
Share on other sites

I appreciate the reply.

 

I actually just use the specials on default mod on my index.php page, so the modification you did would work great for me. Could you let me know how you got the random to work on your index?

 

 

I will have to recreate the file, (which should be fairly easy) because I dumped the whole file in frustration. will post it when it's done.

Link to comment
Share on other sites

Jon

 

Here you go, I had another look at things and got it to work completely without any errors.

Best to just copy and paste the below into:

catalog/includes/modules/default_specials.php

Back up first!!

<?php
/*
 $Id: default_specials.php,v 2.0 2003/06/13

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

 Copyright (c) 2003 osCommerce

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

 
<?php
$info_box_contents = array();
 $info_box_contents[] = array('text' => sprintf(TABLE_HEADING_DEFAULT_SPECIALS, strftime('%B')));
 new contentBoxHeading($info_box_contents);

  if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
    $specials = 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 s.specials_date_added DESC limit " . MAX_RANDOM_SELECT_NEW);
  } else {
    $specials = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, p.products_price, s.specials_new_products_price) as products_price, s.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 = '" . (int)$new_products_category_id . "' and p.products_status = '1' and s.status = '1' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_SPECIALS);
  }


 $row = 0;
 $col = 0;
 $pCount = 0;
 $info_box_contents = array();
 $found_products = array();
 $num_rows = tep_db_num_rows($specials);
 if (MAX_DISPLAY_NEW_PRODUCTS > MAX_RANDOM_SELECT_NEW) {
   // don't allow more new products than will be queried
   $max_specials = MAX_RANDOM_SELECT_NEW;
 } else {
   $max_specials = MAX_DISPLAY_NEW_PRODUCTS;
 }
 if ($num_rows > 0) {        
   while ($pCount < $max_specials) {    
     // choose a random row 
     $random_specials = '';
     $random_row = tep_rand(0, ($num_rows - 1));
     tep_db_data_seek($specials, $random_row);
     $random_specials = tep_db_fetch_array($specials);
//  while ($default_specials = tep_db_fetch_array($specials)) {
     // see if found already, if not use else skip
     $found = 0;
     for ($ii=0; $ii < $pCount; $ii++) {
       if ($found_products[$ii] == $random_specials['products_id']) {
         $found = 1;
         break;
       }
     }
     if ($found == 0) {
       // keep track of found id's
       $found_products[$pCount] += $random_specials['products_id'];
       $pCount ++; 
       // add to display array

       $random_specials['products_name'] = tep_get_products_name($random_specials['products_id']);
   $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_specials["products_id"]) . '">' . tep_image(DIR_WS_IMAGES . $random_specials['products_image'], $random_specials['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_specials['products_id']) . '">' . $random_specials['products_name'] . '</a><br><s>' . $currencies->display_price($random_specials['products_price'], tep_get_tax_rate($random_specials['products_tax_class_id'])) . '</s><br><span class="productSpecialPrice">' . $currencies->display_price($random_specials['specials_new_products_price'], tep_get_tax_rate($random_specials['products_tax_class_id'])) . '</span>' . '<br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $random_specials['products_id'], 'NONSSL') . '">' . tep_image_button('button_buy_now.gif', TEXT_BUY . $random_specials['products_name'] . TEXT_NOW) . '</a>');
   $col ++;
   if ($col > 2) {
     $col = 0;
     $row ++;
   }
 }
   } // while pCount
 } // num_rows  
 new contentBox($info_box_contents);
?>

<!-- default_specials_eof //-->

 

P.S. This puts a "buy now" button at the bottom of the product description also.

If you don't want that button, delete this section

' . '<br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $random_specials['products_id'], 'NONSSL') . '">' . tep_image_button('button_buy_now.gif', TEXT_BUY . $random_specials['products_name'] . TEXT_NOW) . '</a>

 

Cheers

John

Link to comment
Share on other sites

The point being that your answer works (I guess, I have not tested it), but your code is awful.  A more elegant solution is to simply "order by RAND()".

 

Burt

I can't and am not taking credit for this code. I just modified an existing contribution "Specials on Default".

 

As far as whether this code works "order by RAND()", I don't know I have not tested it.

 

Cheers

Link to comment
Share on other sites

hey, i really appreciate this - youre the man!

 

Jond and anyone else.

I have found a problem with the code I posted above.

It works fine provided there is at least 3 items or No items on special, in a catagory that has additional catagories under it.

 

The code is supposed to display specific items of any items that are on special in those catagories.

Unfortunately unless there is Zero items or enough to fill a row, it errors the whole page.

 

A temporary work around is change this:

   if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {

To this:

  if ($cPath) {
//   if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {

This will allow the page to display properly, but does not show specific specials item/s relevent to the specific catagories.

 

I will keep working at this but I am not a real PHP person. Hopefully someone with more experience could chime in here and fix this problem easily for us.

Link to comment
Share on other sites

sounds great, this will work fine for me, because i just use the module on my main page.

I do typically always have more than 3 specials at one time, but will certainly implement the fix to avoid any problems.

thanks for the heads up!

Link to comment
Share on other sites

i just use your code on my main page.

 

i switched it to the new code, and the page would not load. i switched back, works fine for me. let me know if you have a better fix.

 

appreciate all the help!

Link to comment
Share on other sites

  • 3 weeks later...

Hi

 

I ised this contributon and replace the code FILENAME_NEW_PRODUCTS with FILENAME_DEFAULT_SPECIALS

 

When no exist specials products i want disapear this table and show the New products table ... it's posible?

if( <--- I DON'T KNOW WHAT CODE PUT HERE --->)
 { .... bla bla bla

} else // If it's empty, then include the original New Products box
{
  include (DIR_WS_MODULES . FILENAME_NEW_PRODUCTS);
}

 

 

appreciate all the help!

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...