VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: ficciones on January 24, 2015, 00:30:50 AM

Title: Show category description even if category has no products? [solved]
Post by: ficciones on January 24, 2015, 00:30:50 AM
I am new to VM. I am using VM3.0.2 on Joomla 3.3.6
I have a menu item which is a vm category. It has sub-categories but no products. I want the category description to show, but it is not showing on the page; if I add a product to the category then the category description shows. 
I have tried modifying some files, for example "com_virtuemart\views\category\tmpl\default.php" line 35 I changed
if (empty($this->keyword) and !empty($this->category)) {
<div class="category_description">
   <?php echo $this->category->category_description; ?>
</div>
to:
if (empty($this->keyword) ) {
<div class="category_description">
   <?php echo $this->category->category_description; ?>
</div>
But it doesn't work. I did the same thing with template/html/com_virtuemart/category/default.php, but nothing happened either.

I think I may be missing something obvious, since this is my first try with virtuemart. Can anyone help?
Title: Re: Show category description even if category has no products?
Post by: GJC Web Design on January 24, 2015, 01:11:35 AM
if you try

print 'Debug Line '.__LINE__.' $this->category <pre>'; print_r ($this->category); print "</pre><br />\n";

above the if (empty($this->keyword) ) { 

is the desc there?
Title: Re: Show category description even if category has no products?
Post by: ficciones on January 24, 2015, 18:31:28 PM
Thank you for your response, I have tried adding the code, but unfortunately the debug information seems to be treated the same way as the category description - it does not appear when there are no products! If I publish a product in the category, then both appear- the debug and the cat description. And then yes, the cat description shows up in ther debug listing.

This is what I have in my template/html/com_virtuemart/category/default.php file:
<?php 
 print 
'Debug Line '.__LINE__.' $this->category <pre>'print_r ($this->category); print "</pre><br />\n";
if (empty($this->keyword) && !empty($this->category->category_description)) : ?>

<p class="category_description">
<?php echo $this->category->category_description?>
</p>
<?php endif; ?>


In configuration I set default template and category template to be "my_template-Default"; and I set category layout "No Override". Changing category layout to "Default" makes no difference.
I also added your line of code to the core file components/com_virtuemart/views/category/tmpl/default.php

Title: Re: Show category description even if category has no products?
Post by: GJC Web Design on January 24, 2015, 19:44:52 PM
hmm - must be filtered out further up the chain

have a poke around in administrator\components\com_virtuemart\models\category.php
Title: Re: Show category description even if category has no products?
Post by: ficciones on January 24, 2015, 20:35:48 PM
Not sure what I am doing (I am new to VM!) but the only place I found something could be happening is in line 170:

static public function getChildCategoryListObject($vendorId, $virtuemart_category_id,$selectedOrdering = null, $orderDir = null,$lang=false) {

if(!$lang){
$lang = VmConfig::$vmlang;
}

if(VmConfig::$defaultLang!=$lang and VmConfig::$langCount>1){
$query = 'SELECT c.*, IFNULL(l.category_name,ld.category_name) as category_name,
IFNULL(l.category_description,ld.category_description) as category_description,
IFNULL(l.metadesc,ld.metadesc) as metadesc,
IFNULL(l.metakey,ld.metakey) as metakey,
IFNULL(l.customtitle,ld.customtitle) as customtitle,
IFNULL(l.slug,ld.slug) as slug
FROM `#__virtuemart_categories` as c
INNER JOIN `#__virtuemart_categories_'.VmConfig::$defaultLang.'` as ld using (`virtuemart_category_id`)
LEFT JOIN `#__virtuemart_categories_'.$lang.'` as l using (`virtuemart_category_id`)';
} else {
$query = 'SELECT L.*
FROM `#__virtuemart_categories_'.$lang.'` as L
INNER JOIN `#__virtuemart_categories` as c using (`virtuemart_category_id`)';
}

I do have 2 languages, english (default) and spanish.
The output is the same in both languages, the category name and the category description are not showing without a published product.
Title: Re: Show category description even if category has no products?
Post by: ficciones on January 25, 2015, 16:15:35 PM
I found the problem. The code
if (empty($this->keyword) && !empty($this->category->category_description)) : ?>
<p class="category_description">
<?php echo $this->category->category_description?>
</p>
<?php endif; ?>

was actually nested inside another if statement that was also testing the condition if (!empty($this->products)) so I moved the block of code outside of it.
Please disregard my last post about languages.
Title: Re: Show category description even if category has no products? [solved]
Post by: ryan.schaffner on March 10, 2015, 17:59:22 PM
Sorry, I'm a bit new to this--but I'm trying to figure out how to do what you did. Can you paste the new code and where it's located? I don't want to screw things up...

Thanks!