Author Topic: Number of products does not count properly  (Read 12219 times)

vbarkouski

  • Beginner
  • *
  • Posts: 22
Number of products does not count properly
« on: December 16, 2009, 00:13:27 am »
Hello

http://www.baytires.com/

I have the following tree:

Used tires (0)
   > 16 Inch (9)
          >> 205/55/16 (5)
                >>> "5 products products listed"
          >> 215/50/16 (4)
                >>> "4 products products listed"


how can I fix that first category counts final amount of product in child list?
please help


rb

  • Advanced
  • Full Member
  • *****
  • Posts: 1503
Re: Number of products does not count properly
« Reply #1 on: December 19, 2009, 00:28:05 am »
The existing code only counts products in subcategories 1 level below each category.  Since you have 3 levels of categories, the code doesn't find and count your products properly.  The following fix should handle counting products regardless of how "deep" you have subcategories set up.

The function that needs to be fixed is in a core VM class.  Instead of changing the core class, this fix uses VM's "Extended User Class" functionality which became available with VM 1.1.4.

Step 1 - copy the following code and save it into a file named "ps_product_category.php" (but don't overwrite your existing ps_product_cateogry.php file).
Code: [Select]
<?php
if( !defined'_VALID_MOS' ) && !defined'_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

class 
ps_product_category extends vm_ps_product_category {

/**
* Alternative counting method which includes counts of child categories to any depth
*/

function products_in_category$category_id ) {
if( PSHOP_SHOW_PRODUCTS_IN_CATEGORY == '1' || vmIsAdminMode() ) {
$num ps_product_category::product_count_in_cat($category_id);
return " ($num) ";
}
else
return ( "" );
}

/**
* Recursive function to count products in child categories, to any depth
*
*/
function product_count_in_cat$category_id ) {
$num ps_product_category::product_count($category_id);
//if( empty($num) && ps_product_category::has_childs( $category_id )) {
if( ps_product_category::has_childs$category_id )) {
$db = new ps_DB;
$q "SELECT category_child_id FROM #__{vm}_category_xref ";
$q .= "WHERE category_parent_id='$category_id' ";
$db->query($q);
while( $db->next_record() ) {
$num += ps_product_category::product_count_in_cat$db->f("category_child_id") );
}
}
return $num;
}
}
?>

Step 2 - Create a directory in
          components/com_virtuemart/themes/your_theme_name/
and call it user_class (unless you already have one)

Step 3 - Move the file from Step 1 into this new directory so the file path looks like this:
          components/com_virtuemart/themes/your_theme_name/user_class/ps_product_category.php
       
Step 4 - Admin->Configuration->Security tab->Security Settings box
          enable "Allow the inclusion of extended classes from the theme-directory"
       
Test it.  If you have any problems, just delete the file user_class/ps_product_category.php

vbarkouski

  • Beginner
  • *
  • Posts: 22
Re: Number of products does not count properly
« Reply #2 on: December 21, 2009, 23:50:02 pm »
You are the life saver. thank you!

megahz

  • Beginner
  • *
  • Posts: 2
Re: Number of products does not count properly
« Reply #3 on: February 05, 2010, 09:11:10 am »
thanks for your solution , is great, but there is one more thing.

the mod_tpindexvm does not count all items inside categories and subcategories.

can you help us on what to change in the mod?

the code in default.php is this:
Code: [Select]
<?php
/**
* TemplatePlazza
* TemplatePlazza.com 
**/
defined('_JEXEC') or die('Restricted access');

$menu = &JSite::getMenu();
$items $menu->getItems('link''index.php?option=com_virtuemart');
$itemid = isset($items[0]) ? '&Itemid='.$items[0]->id '';

$modtype $params->get('modtype');
$showtitle $params->get('showtitle');
$showdesc $params->get('showdesc');
$showsubcat $params->get('showsubcat');
$showthumb $params->get('showthumb');
$col $params->get ('num_cols'2);
$colwidth floor(100/$col);
$x 0;
$y 1;
$row ceil(count($list)/$col);
$total $col*$row;
$rest = ($total-count($list))+1;

if($modtype == 0){
$headtag "<link rel=\"stylesheet\" href=\"" JURI::root() . "/modules/mod_tpindexvm/tmpl/tpindexvm.css\" type=\"text/css\" />";
}else{
$headtag "<link rel=\"stylesheet\" href=\"" JURI::root() . "/modules/mod_tpindexvm/tmpl/tpindexvm_menu.css\" type=\"text/css\" />";
}
$mainframe->addCustomHeadTag($headtag);

if($list){
if($modtype == 0){
$data  "<div class=\"productthumb\">";
$data .= '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
for($a=0$a<$total$a++){
if($y == 1){
$data .= '<tr valign="top"><td width="' $colwidth '%">';
}else{
$data .= '<td width="' $colwidth '%">';
}


if(isset($list[$a]->id)){
$linkp JRoute::_('index.php?option=com_virtuemart&page=shop.browse&category_id='.$list[$a]->id.$itemidfalse);
$data .= "<div class=\"pthumb\">";

if($showthumb == 1){
$class " bbb";
}else{
$class "";
}

if($showtitle == 1){
$data .= "<a href=\"$linkp\" title=\"" $list[$a]->name "\" id=\"productthumbbig$x\" class=\"productthumbbigtitle\">";
$data .= "<span>" $list[$a]->name "</span>";
$data .= "</a>";
}

if($showthumb == 1){
$data .= "<a href=\"$linkp\" title=\"" $list[$a]->name "\" id=\"productthumbbig$x\" class=\"productthumbbig\">";
$data .= "<div class=\"pthumbimg\"><img src='" JURI::base(true) . "/components/com_virtuemart/shop_image/category/" $list[$a]->filename "' /></div>";
$data .= "</a>";
}

if($showdesc == || $showsubcat == 1){
$data .= "<div class='detail" $class "'>";

if($showdesc == 1){ $data .= "<div class='desc'>" $list[$a]->desc "</div>";}

if($showsubcat == 1){
$child modTPIndexHelper::getListChild($params$list[$a]->id);
if(count($child) > 0){
$data .= "<ul>";
for($i=0$i<count($child); $i++){
$linkc JRoute::_('index.php?option=com_virtuemart&page=shop.browse&category_id='.$child[$i]->id.$itemidfalse);
$data .= "<li><a href=\"$linkc\" title=\"" $child[$i]->name "\">" $child[$i]->name " (" number_format($child[$i]->total0""".") . ")</a></li>";
}
$data .= "</ul>";
}
}
$data .= "</div>";
$data .= "<div class='clear'></div>";
}
$data .= "</div>";
}else{
$data .= "&nbsp;";
}

$x++;
if($y == $col){
$data .= '</td></tr>';
$y 1;
}else{
$data .= '</td>';
$y++;
}
}
$data .= "</table>";
}else{
$data  "<div class=\"productthumb_menu\">";
$data .= '<ul class="parent">';
for($a=0$a<$total$a++){
if(isset($list[$a]->id)){
$data .= '<li>';
$linkp JRoute::_('index.php?option=com_virtuemart&page=shop.browse&category_id='.$list[$a]->id.$itemidfalse);
$data .= "<div class=\"pthumb\">";

if($showthumb == 1){
$class " bbb";
}else{
$class "";
}

$data .= "<a href=\"$linkp\" title=\"" $list[$a]->name "\" id=\"productthumbbig$x\" class=\"productthumbbigtitle\">";
$data .= "<span>" $list[$a]->name "</span>";
$data .= "</a>";

if($showthumb == 1){
$data .= "<a href=\"$linkp\" title=\"" $list[$a]->name "\" id=\"productthumbbig$x\" class=\"productthumbbig\">";
$data .= "<img src='" JURI::base(true) . "/components/com_virtuemart/shop_image/category/" $list[$a]->filename "' />";
$data .= "</a>";
}

if($showdesc == || $showsubcat == 1){
$data .= "<div class='detail" $class "'>";

if($showdesc == 1){ $data .= "<div class='desc'>" $list[$a]->desc "</div>";}

if($showsubcat == 1){
$child modTPIndexHelper::getListChild($params$list[$a]->id);
if(count($child) > 0){
$data .= "<ul>";
for($i=0$i<count($child); $i++){
$linkc JRoute::_('index.php?option=com_virtuemart&page=shop.browse&category_id='.$child[$i]->id.$itemidfalse);
$data .= "<li><a href=\"$linkc\" title=\"" $child[$i]->name "\">" $child[$i]->name " (" number_format($child[$i]->total0""".") . ")</a></li>";
}
$data .= "</ul>";
}
}
$data .= "</div>";
$data .= "<div class='clear'></div>";
}
$data .= "</div>";
$data .= '</li>';
}

$x++;
}
$data .= "</ul>";
}
$data .= "</div>";
}else{
$data "";
}
echo $data;
?>



corex

  • Beginner
  • *
  • Posts: 16
Re: Number of products does not count properly
« Reply #4 on: February 08, 2010, 18:46:21 pm »
Have can I remove the total amount of products from the module?

rb

  • Advanced
  • Full Member
  • *****
  • Posts: 1503
Re: Number of products does not count properly
« Reply #5 on: February 09, 2010, 16:42:35 pm »
corex, if you're asking how to remove the display that shows the count of products within a category using a standard VirtueMart module, the answer is you change the configuration:

Admin->Configuration->Site tab->Display box
     Un-check "Show the Number of Products" and then save.

corex

  • Beginner
  • *
  • Posts: 16
Re: Number of products does not count properly
« Reply #6 on: February 09, 2010, 16:52:04 pm »
Thx for answer but it dont work for this module, but only the standard vm category module.

dombra

  • Beginner
  • *
  • Posts: 26
Re: Number of products does not count properly
« Reply #7 on: April 29, 2010, 21:17:19 pm »
Hi, am having the same problem. did what you wrote with ps_product_category.php and placed it into user_class directory and turned on "Allow the inclusion of extended classes from the theme-directory?" but nothing seems to change?? any clues what am doing wrong?

my site is www.santehnika24.lv under fifth categorie called flizes


appreciate the help

cheers

rb

  • Advanced
  • Full Member
  • *****
  • Posts: 1503
Re: Number of products does not count properly
« Reply #8 on: April 29, 2010, 23:14:26 pm »
dombra, viewing your category called "Tiles", it sure looks like this hack isn't running.  If you have more than one Theme directory (for example, Default and another you obtained or built), be sure the directory "user_class" is in your concurrently configured Theme directory (and of course, be sure it has READ permissions).

dombra

  • Beginner
  • *
  • Posts: 26
Re: Number of products does not count properly
« Reply #9 on: April 29, 2010, 23:40:34 pm »
yes, to make sure i made in every theme directory user_class and copied file and the permissions are ok. what could it be ???

rb

  • Advanced
  • Full Member
  • *****
  • Posts: 1503
Re: Number of products does not count properly
« Reply #10 on: April 30, 2010, 00:05:36 am »
dombra, I don't know what the cause of your problem is.

If I were debugging it, I would first check to see if the user_class is even executing by replacing this statement on line 13:
      return " ($num) ";     
with
      return " (X) ";

If your Categories then do not show product counts =  (X), you'd know  the user_class isn't running.

dombra

  • Beginner
  • *
  • Posts: 26
Re: Number of products does not count properly
« Reply #11 on: April 30, 2010, 00:37:43 am »
nothing changes, so it seems yes its not running. check all the spelling everything is correct

panfred

  • Beginner
  • *
  • Posts: 2
Re: Number of products does not count properly
« Reply #12 on: January 06, 2011, 13:31:43 pm »
Have You find way how to disable count display?

Hi, am having the same problem. did what you wrote with ps_product_category.php and placed it into user_class directory and turned on "Allow the inclusion of extended classes from the theme-directory?" but nothing seems to change?? any clues what am doing wrong?

my site is www.santehnika24.lv under fifth categorie called flizes


appreciate the help

cheers

aashu

  • Beginner
  • *
  • Posts: 2
Re: Number of products does not count properly
« Reply #13 on: March 04, 2011, 06:18:03 am »
@rb: i am a bit late but thanks a lot for the fix

vbarkouski

  • Beginner
  • *
  • Posts: 22
Re: Number of products does not count properly
« Reply #14 on: March 17, 2011, 10:40:12 am »
How to make this hack to count products by total in-stock availability of all listings, but not amount of listings?