Author Topic: Show category description even if category has no products? [solved]  (Read 5522 times)

ficciones

  • Beginner
  • *
  • Posts: 4
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?

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10445
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Show category description even if category has no products?
« Reply #1 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?
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

ficciones

  • Beginner
  • *
  • Posts: 4
Re: Show category description even if category has no products?
« Reply #2 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:
Code: [Select]
<?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


GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10445
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Show category description even if category has no products?
« Reply #3 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
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

ficciones

  • Beginner
  • *
  • Posts: 4
Re: Show category description even if category has no products?
« Reply #4 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:

Code: [Select]
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.

ficciones

  • Beginner
  • *
  • Posts: 4
Re: Show category description even if category has no products?
« Reply #5 on: January 25, 2015, 16:15:35 pm »
I found the problem. The code
Code: [Select]
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.

ryan.schaffner

  • Beginner
  • *
  • Posts: 9
Re: Show category description even if category has no products? [solved]
« Reply #6 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!