Jump to content



Photo
- - - - -

Add-on to hide categories with zero products in stock?


  • Please log in to reply
6 replies to this topic

#1   csaba

csaba
  • Members
  • 19 posts
  • Real Name:csaba

Posted 05 January 2017 - 20:38

There was a simple add-on for the osc 2.2 to hide (do not display) categories which don't have any active products. Is there a similar add-on for osc 2.3.4? I've been looking but couldn't find one.



#2   ecommunlimited

ecommunlimited
  • Members
  • 268 posts
  • Real Name:William G. Sibert
  • Gender:Male
  • Location:Newark, Ohio USA

Posted 06 January 2017 - 01:33

@csaba

 

This is the 2.3 version of the Activate or Inactivate Categories contribution. Hide Categories with category cache

 

Take care

Bill



#3   csaba

csaba
  • Members
  • 19 posts
  • Real Name:csaba

Posted 09 January 2017 - 18:49

Thanks Bill, but that's not exactly what i am looking for. There was a simple modification for the 2.2 version, in which, if you had no products in a category, that category was automatically not displayed in the online shop. And as soon as you had at least 1 product in stock in that category, the category was displayed automatically.



#4   ecommunlimited

ecommunlimited
  • Members
  • 268 posts
  • Real Name:William G. Sibert
  • Gender:Male
  • Location:Newark, Ohio USA

Posted 09 January 2017 - 19:40

@csaba

 

I miss that feature myself.

 

For v2.2 you can check this out:

http://addons.oscommerce.com/info/6911

Not sure how old your systems is but you can check these out as well:

http://forums.oscomm...ctive-products/

http://forums.oscomm...th-no-products/

http://forums.oscomm...in-default-php/

http://forums.oscomm...es/#entry239214

 

Take care

Bill



#5   csaba

csaba
  • Members
  • 19 posts
  • Real Name:csaba

Posted 09 January 2017 - 21:47

Thanks Bill. So far i had no luck with those... will continue tomorrow. If anybody has an idea how to do it, i would really appreciate it. Here is my categories.php below

<?php
/*
  $Id: categories.php 1739 2007-12-20 00:52:16Z hpdl $

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

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

  function tep_show_category($counter, $count) {
    global $tree, $categories_string, $cPath_array;
    
    $products_in_category = tep_count_products_in_category($counter);
      if ($products_in_category > 0) {
   /*   
      for ($i=0; $i<$tree[$counter]['level']; $i++) {
    */  

if ($count == 0 ) $kk=' class="bg_list_un"'; else $kk=' class="bg_list"'; 
  $count++;

    $categories_string .= '<li'.$kk.'>';

    for ($i=0; $i<$tree[$counter]['level']; $i++) {
      $categories_string .= '<div>';
    }

    $categories_string .= '<a href="';

    if ($tree[$counter]['parent'] == 0) {
      $cPath_new = 'cPath=' . $counter;
    } else {
      $cPath_new = 'cPath=' . $tree[$counter]['path']; 
    }

    $categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '"><i>';

    if (isset($cPath_array) && in_array($counter, $cPath_array)) {
      $categories_string .= '<b>';
    }

// display category name
    $categories_string .= $tree[$counter]['name'];

    if (isset($cPath_array) && in_array($counter, $cPath_array)) {
      $categories_string .= '</b>';
    }
    if (SHOW_COUNTS == 'true') {
      
        $categories_string .= '&nbsp;<strong>(' . $products_in_category . ')</strong>';
      
    }

}
    if (tep_has_category_subcategories($counter)) {
      $categories_string .= '</i><font>'.tep_image(DIR_WS_IMAGES.'bg_list_.gif','','','','').'</font>';
    }



	
	if (tep_has_category_subcategories($counter)) {
    $categories_string .= '</a>';
	}else{
	$categories_string .= '</i></a>';
	}	
    for ($i=0; $i<$tree[$counter]['level']; $i++) {
      $categories_string .= '</div>';
    }

    $categories_string .= '</li>';

    if ($tree[$counter]['next_id'] != false) {
      tep_show_category($tree[$counter]['next_id'], $count);
    }
  }
?>
<!-- categories //-->
          <tr>
            <td>
<?php
  $info_box_contents = array();
  $info_box_contents[] = array('text' => BOX_HEADING_CATEGORIES);

  new infoBoxHeading($info_box_contents, true, false);
  
	$count = 0;

  $categories_string = '';
  $tree = array();

  $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
  while ($categories = tep_db_fetch_array($categories_query))  {
    $tree[$categories['categories_id']] = array('name' => $categories['categories_name'],
                                                'parent' => $categories['parent_id'],
                                                'level' => 0,
                                                'path' => $categories['categories_id'],
                                                'next_id' => false);
                                                

    if (isset($parent_id)) {
      $tree[$parent_id]['next_id'] = $categories['categories_id'];
    }

    $parent_id = $categories['categories_id'];

    if (!isset($first_element)) {
      $first_element = $categories['categories_id'];
    }
  }

  //------------------------
  if (tep_not_null($cPath)) {
    $new_path = '';
    reset($cPath_array);
    while (list($key, $value) = each($cPath_array)) {
      unset($parent_id);
      unset($first_id);
      $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
      if (tep_db_num_rows($categories_query)) {
        $new_path .= $value;
        while ($row = tep_db_fetch_array($categories_query)) {
          $tree[$row['categories_id']] = array('name' => $row['categories_name'],
                                               'parent' => $row['parent_id'],
                                               'level' => $key+1,
                                               'path' => $new_path . '_' . $row['categories_id'],
                                               'next_id' => false);

          if (isset($parent_id)) {
            $tree[$parent_id]['next_id'] = $row['categories_id'];
          }

          $parent_id = $row['categories_id'];

          if (!isset($first_id)) {
            $first_id = $row['categories_id'];
          }

          $last_id = $row['categories_id'];
        }
        $tree[$last_id]['next_id'] = $tree[$value]['next_id'];
        $tree[$value]['next_id'] = $first_id;
        $new_path .= '_';
      } else {
        break;
      }
    }
  }
  tep_show_category($first_element, $count); 

  $info_box_contents = array();
  $info_box_contents[] = array('text' => '<ul class="categories">' . $categories_string . '</ul>');

  new infoBox($info_box_contents);
?>
            </td>
          </tr>
<!-- categories_eof //-->


#6   csaba

csaba
  • Members
  • 19 posts
  • Real Name:csaba

Posted 10 January 2017 - 21:25

@csaba

 

I miss that feature myself.

 

For v2.2 you can check this out:

http://addons.oscommerce.com/info/6911

Not sure how old your systems is but you can check these out as well:

http://forums.oscomm...ctive-products/

http://forums.oscomm...th-no-products/

http://forums.oscomm...in-default-php/

http://forums.oscomm...es/#entry239214

 

Take care

Bill

 

I've tried again all these but they don't work on my osc 2.3.4.

And they work on the old osc2.2. Why?



#7   mdtaylorlrim

mdtaylorlrim
  • Community Sponsor
  • 2,560 posts
  • Real Name:Mark
  • Gender:Male

Posted 20 April 2017 - 19:08

@csaba

 

I have a process that runs every so often that updates my products quantity on hand and prices changes, as supplied by my vendor. The last couple of lines of the job is here:

if ($qty == 0){
  $product_status = 0;
  } else {
    $product_status = 1;
    }

$sql = "update products set products_quantity = '" . $qty . "', products_price = '" . $cost . "', products_status = '" . $product_status . "' where vendor_model = '" . $itemno . "' and vendor_id = '1'";

$result = $mysqli->query($sql);  
  
}

I have an extra couple of fields in my db since I have multiple vendors so you will have to edit this to match your db and run it as your application warrants.

 

 

Mark


Edited by mdtaylorlrim, 20 April 2017 - 19:09.

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?