Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Bestsellers / New Products per sub category


truetoform

Recommended Posts

Posted

Ok this is for all the people out there that have more then one sub category between products.

 

From the index.php New products by month are listed and once you get to the category products are listed it defines that list from its current category.

 

Well I picked up this mod that is supposed to display the products from the sub categories listed below the current category. From what I can tell its not working, I still only get new products for index and the last category the products no in between. The code is listed below I have been going insane trying to figure out what?s wrong but I am not the most skilled php coder there is. My main focus here is getting the new products to display right in sub category?s then converting this mod to do the same for bestsellers per category and sub category. Any help would be much appreciated.

 

Here is the support form for the Contribution I am using

http://forums.oscommerce.de/viewtopic.php?t=13925

 

BTW: I am using osc snapshot 06/08/04

 

<?php

/*

$Id: new_products.php,v 1.35 2003/09/08 13:25:44 project3000 Exp $

 

***************************************************************************

Contribution: Include all Subcategories for 'New Products', version 1.0

Mod by Nils Petersson, 2004/05/02

***************************************************************************

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

?>

?>

 

<!-- new_products //-->

<?php

 

if ( (isset($new_products_category_id)) || ($new_products_category_id == '0') ) { // in index.php

$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 { // 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 " . $num);

}

 

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;

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

$new_products['products_name'] = tep_get_products_name($new_products['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=' . $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'])));

 

$col ++;

if ($col > 2) {

$col = 0;

$row ++;

}

}

new contentBox($info_box_contents);

}

 

?>

<!-- new_products_eof //-->

 

Thank You

Jason

Posted
Well I picked up this mod that is supposed to display the products from the sub categories listed below the current category. From what I can tell its not working

It does what it's supposed to do and it's working fine.

 

BTW: I am using osc snapshot 06/08/04

Here's your problem. The readme file (always worth reading, btw) says:

A contribution for osCommerce 2.2 Milestone 2

 

I'd recommend you use a Milesone release, and not a snapshot and spare yourself from a lot of frustration. Especially since you say you're not very skilled at PHP. When using a snapshot, you should really have a good reason to do so, absolutly know what you're doing, and be able to invest a lot of time in rewriting most contributions. If not - go Milestone.

Posted

Hey Nils,

 

Thanks for the quick reply. Yea I did see that in the readme I do have the MS2 installed as well as the snapshot I use the MS2 to make sure stuff works then I try to do conversions for the snapshots. I just forgot to say I had it working on the MS2.

 

I have for the most part recoded it to work with the snapshot but I am kind of stuck on the $cats part. I am not sure if I need something calling the cPath arrays or if I am just missing something from the database calling change.

 

Here is what I got:

 

<?php
/*
 $Id: new_products.php,v 1.35 2003/09/08 13:25:44 project3000 Exp $
 
***************************************************************************
Contribution: Include all Subcategories for 'New Products', version 1.0
Mod by Nils Petersson, 2004/05/02 
***************************************************************************

 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($current_category_id)) || ($current_category_id == '0') ) {  // in index.php
  $new_products = $osC_Database->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 {   // in a category

$cats[] = $current_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 = $osC_Database->query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$cats[$i] . "'"); 
 while ($new_products->next()) {
	 $cats[] = $new_products->valueInt('cataegorie_id');
 }
 $cats=array_unique($cats); // sort out doubles
}

$num = (int) MAX_DISPLAY_NEW_PRODUCTS;
$new_products = $osC_Database->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 " . $num);

}
   $new_products->setCache('new_products-' . '-' . $current_catagory_id, '720');
   $new_products->execute();

   if ($new_products->numberOfRows() > 0)  {

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

$row = 0;
$col = 0;

$info_box_contents = array();

while ($new_products ->next()) {
  $new_products = tep_get_products_name($new_products->valueInt('products_id'));
  $specials_price = tep_get_products_special_price($new_products->valueDecimal('products_price'), $new_products->valueInt('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=' . $new_products->valueInt('products_id')) . '">' . tep_image(DIR_WS_IMAGES . $new_products->value('products_image'), $new_products->value('products_name'), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products->valueInt('products_id')) . '">' . $new_products->value('products_name') . '</a><br>' . $products_price);

  $col ++;
  if ($col > 2) {
   $col = 0;
   $row ++;
  }
}
new contentBox($info_box_contents);
}

?>
<!-- new_products_eof //-->

 

When I run the page I get:

 

Fatal error: Call to a member function on a non-object in ...catalog/includes/modules/new_products.php on line 32

 

Any help would be appreciated.

 

Jason

Posted

Found the error:

 

Line: 32 and 33

 

 while ($new_products->next()) {
 $cats[] = $new_products->valueInt('cataegorie_id');

 

Changed it to

 

 
while ($categorie->next()) {
 $cats[] = $categorie->valueInt('cataegorie_id');

 

Now I do not get any errors but I am not getting anything when the page loads. I know there is new products in there, and suggestions?

 

Thank

Jason

  • 4 months later...
Posted

Thank you, Thank you, Thank you for this contrib. I have been tearing what's left of my hair out...trying to fix this problem. BTW for those who live by the motto "if it ain't broke don't fix it" this will work with MS1 if you are replacing the new_products.php v1.34 with this one

Archived

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

×
×
  • Create New...