VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: gpullen on August 29, 2012, 14:18:29 PM

Title: Product Count on Category List??
Post by: gpullen on August 29, 2012, 14:18:29 PM
Hi,

Please see the site I am developing here:  http://bfplantsales.com/stock

Is it possible to display a Product Count next to each category... eg  Excavators (4)   like It does in the module I am using on the left hand side??  (IceVMCategories)

Thanks
Gareth
Title: Re: Product Count on Category List??
Post by: ivus on August 29, 2012, 17:05:03 PM
nice link. deosn't work.
Title: Re: Product Count on Category List??
Post by: gpullen on August 30, 2012, 13:41:26 PM
Sorry, temp domain was removed..  Try the link now!!
Title: Re: Product Count on Category List??
Post by: gpullen on September 04, 2012, 17:48:08 PM
Any ideas?

http://bfplantsales.com/stock/
Title: Re: Product Count on Category List??
Post by: ivus on September 05, 2012, 02:40:22 AM
Hi gpullen,

looks like you've already figured this one out.

;D
Title: Re: Product Count on Category List??
Post by: Cornel on September 05, 2012, 07:42:37 AM
Can you share the steps you took to change the code so the number of products in the category is displayed ?
Title: Re: Product Count on Category List??
Post by: gpullen on September 06, 2012, 11:36:29 AM
What?!!!  noooo!!  Read the first post again!!


The category module on left hand side is IceVMCategories..  it Does that by default.   I want the main bit in the middle of the page to ALSO show product count!!!

Thanks
Title: Re: Product Count on Category List??
Post by: ivus on September 06, 2012, 14:26:31 PM
Hi gpullen,

wasn't clear enough.

OK 2 step process.

STEP 1 : Modify the MODEL
/administrator/components/com_virtuemart/models/category.php @ line 138.

Look for -


if(!empty($childList)){
if(!class_exists('TableCategory_medias'))require(JPATH_VM_ADMINISTRATOR.DS.'tables'.DS.'category_medias.php');
foreach($childList as $child){
$xrefTable = new TableCategory_medias($db);
// $xrefTable = $this->getTable('category_medias');
$child->virtuemart_media_id = $xrefTable->load($child->virtuemart_category_id);
}
}



Change to -


if(!empty($childList)){
if(!class_exists('TableCategory_medias'))require(JPATH_VM_ADMINISTRATOR.DS.'tables'.DS.'category_medias.php');
foreach($childList as $child){
$xrefTable = new TableCategory_medias($db);
// $xrefTable = $this->getTable('category_medias');
$child->virtuemart_media_id = $xrefTable->load($child->virtuemart_category_id);

$categoryModel = VmModel::getModel ('category');
$child->number_of_products =  $categoryModel->countProducts ($child->virtuemart_category_id);

}
}



               $categoryModel = VmModel::getModel ('category');
               $child->number_of_products =  $categoryModel->countProducts ($child->virtuemart_category_id);



STEP 2 : Modify the OUTPUT TEMPLATE
/components/com_virtuemart/views/categories/tmpl/default.php @ line 68.

Look for -


    // Show Category ?>
    <div class="category floatleft<?php echo $category_cellwidth $show_vertical_separator ?>">
    <div class="spacer">
    <h2>
    <a href="<?php echo $caturl ?>" title="<?php echo $category->category_name ?>">
    <?php echo $category->category_name ?>
    <br />
    <?php // if ($category->ids) {
    echo $category->images[0]->displayMediaThumb("",false);
    //} ?>

    </a>
    </h2>
    </div>
    </div>



Change to -


    // Show Category ?>
    <div class="category floatleft<?php echo $category_cellwidth $show_vertical_separator ?>">
    <div class="spacer">
    <h2>
    <a href="<?php echo $caturl ?>" title="<?php echo $category->category_name ?>">
    <?php echo $category->category_name ?> (<?php echo $category->number_of_products ?>)
    <br />
    <?php // if ($category->ids) {
    echo $category->images[0]->displayMediaThumb("",false);
    //} ?>

    </a>
    </h2>
    </div>
    </div>



               <?php echo $category->category_name ?> (<?php echo $category->number_of_products ?>)


AND THAT"S IT...

Title: Re: Product Count on Category List??
Post by: ivus on September 13, 2012, 16:31:19 PM
did you sort this out? Mark it solved if you have.
Title: Re: Product Count on Category List??
Post by: kanbosk on November 02, 2012, 13:36:11 PM
Hi Ivus,

Thanks for helping with the code. I had the same problem and implemented your suggestions but they did nothing. Am using virtuemart 2.0.12f and Joomla 2.5.7. Can you help more? Thanks
Title: Re: Product Count on Category List??
Post by: bytelord on November 02, 2012, 13:44:48 PM
Hello,

No need to hack the core... please take a look over here: http://forum.virtuemart.net/index.php?topic=102174.0

Regards
Title: Re: Product Count on Category List??
Post by: kanbosk on November 02, 2012, 14:06:19 PM
Hi bytelord
Thanks for your quick response. I have placed the code exactly where you suggested (components/com_virtuemart/views/category/tmpl) and in the exact location but nothing at all happens.
Any ideas? Am using Joomla 2.5.7 and VM 2.0.12f. Thanks
Title: Re: Product Count on Category List??
Post by: bytelord on November 02, 2012, 14:08:32 PM
lets discuss it on the other thread...