Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Show products on "top sub-category"


Guest

Recommended Posts

Posted

Hi,

I search on this excelent forum about this issue, and I didt find the answer

Mi problem is if a sub-category does not have products, only more subcategories, not showing products. Exist a contibution or example code to show the products of the subcategories? any idea?

 

Thanks!

 

Edwin

Posted

Do you think is this posible? make some changes show new products of the top of the subcategoy and , example the subcategory are cPath=28, and the all subcategories cPath=28_33, cPath=28_87, use a wildcard like display new products of cPath=28*.

 

Any idea?

Posted

It's doable, but not that way. A product does not know to what categories it belongs except for the immediate category. In other words, it does not know the parent of its category. You would have to do it the other way: for all subcategories of the current category, recursively get their subcategories until you get the product list.

 

Perhaps the All Products contribution will do what you want.

 

Good luck,

Matt

Posted
You would have to do it the other way:  for all subcategories of the current category, recursively get their subcategories until you get the product list.

 

Matt,

Thanks by your answer, did you know how to make the recursively? this mod I have to do in new_products.php? or on what file do I have to make this?

 

Thanks again...

 

Edwin

Posted

I find this code on http://www.oscommerce.com/forums/viewtopic.php...cursively#51624

 

$inf=array();  

$inf[]=array('align'=>'left','text'=>BOX_HEADING_CATEGORIES);  

new infoBoxHeading($inf,false,true);  

$inf2="";  

function findCats($id,$lev,$C){  

global $inf2,$cPathParts;  

$query=mysql_query("select * from categories where parent_id='$id'");  

while($row=mysql_fetch_array($query)){  

$newC=$C."$row[categories_id]_";  

$row2=mysql_fetch_array(mysql_query("select * from categories_description where categories_id='$row[categories_id]'"));  

for($i=0;$i<$lev;$i++)$inf2.='  ';  

$inf2.=(($cPathParts[$lev])==$row[categories_id])?''.$row2[categories_name].'':''.$row2[categories_name].'';  

$inf2.='

';  

findCats($row[categories_id],$lev+1,$newC);  

}  

}  

$cPathParts=split('_',$cPath);  

findCats(0,0,'');  

$inf=array();  

$inf[]=array('align'=>'left','text'=>$inf2);  

new infoBox($inf);  

?>  

 

How can I use for this code for find random products below of the "top subcategory"?

 

Edwin

Posted

Any idea? I was wordering If the best way are not show "new products" box if no products to show, is this posible...

 

Please help...

 

 

Thanks

 

Edwin

Posted

Any idea? I was wordering If the best way are not show "new products" box if no products to show, is this posible...

 

Please help...

 

 

Thanks

 

Edwin

Posted

Do think is this posible? I try to do this... but I cant... Please help... :cry:

 

Edwin

  • 4 weeks later...
  • 4 weeks later...
Posted

Here is a code that it will help you

 

Remplace the include/modules/new_products.php by this:

 

<!-- new_products //-->
<?php
 $info_box_contents = array();
$mes=strftime('%B');
$mes=ucfirst($mes);
 $info_box_contents[] = array('text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, $mes));

 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);
   $categorie_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$new_products_category_id . "'");
 }

 $row = 0;
 $col = 0;
 $productos = 0;
 $info_box_contents = array();
 while ($categorie = tep_db_fetch_array($categorie_query)) {
$cats[] = $categorie['categories_id'];
 }
 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'])));
  
   $productos++;
   $col ++;
   if ($col > 2) {
     $col = 0;
     $row ++;
   }
 }

 $cats=array_unique($cats);
  
$bolean=1;
while((count($cats)!=0)&&($bolean))
{
 for($i=0;$i<count($cats);$i++)
 {
   $catsnew = "";
   $num = (int) MAX_DISPLAY_NEW_PRODUCTS;
   $cant = $num - $productos;
   $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)$cats[$i]. "' and p.products_status = '1' order by p.products_date_added desc limit " . $cant);
   $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)) {
$catsnew[] = $categorie['categories_id'];
   }
   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'])));

     $productos++;
     $col ++;
     if ($col > 2) {
       $col = 0;
       $row ++;
     }
   }
 
   if($catsnew=="")
$bolean=0;
   else
$catsnew=array_unique($catsnew);
 }
 $cats = "";
 $cats = $catsnew;
}

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

 

enjoy it.

Archived

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

×
×
  • Create New...