News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Display category description inside products on category view

Started by Alexikakos, February 09, 2021, 11:01:32 AM

Previous topic - Next topic

Alexikakos

Hi all,

I want to display category description inside product item, on category view.

I tried edit products.php (\public_html\templates\mytemplate\html\com_virtuemart\sublayouts\products.php).
I added inside "foreach ( $products as $product ){...}"
the follow line:
<?php echo $product->category_description?>
<?php echo $product->category->category_description ?></div>
<?php echo $this->category_description ?></div>

But not Working. Any idea?

PS: The wired that this code its working inside product foreach: <?php echo $product->virtuemart_category_id;  ?>, <?php echo $product->category_name?>, but not category description.

Joomla Version: 3.9.24
VirtueMart Version: 3.8.4
PHP 7.3


Jörgen

The category description should be the same for all products in the sam category. Is there not cote to display the category description earlier in the file ? Code that is not linked to the product but to the current category ?

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

Alexikakos

Hi,
Yes it does.

In catagory view file (\public_html\templates\mytemplate\html\com_virtuemart\category\default.php) it use this echo:
<?php echo $this->category->category_description?>
But this code it work in \public_html\templates\mytemplate\html\com_virtuemart\category\default.php not in \public_html\templates\mytemplate\html\com_virtuemart\sublayouts\products.php

The products layout (in category view) is in product.php file in this path: \public_html\templates\mytemplate\html\com_virtuemart\sublayouts\products.php
the <?php echo $this->category->category_description?> not working in product.php only in default.php.

That is my problem

Jörgen

You can transfer the data to the products.php when the sublayout is rendered. If You can not figure it out, I will show an example later tonight.

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

Alexikakos


Jörgen

Hello this shows the fundamentals:
echo shopFunctionsF::renderVmSubLayout($this->productsLayout,array('products'=>$this->products,
'currency'=>$this->currency,
'products_per_row'=>$this->perRow,
'showRating'=>$this->showRating,
'categoryDescription'=>$this->category->category_description));

That code transfers the data categoryDescription into the array viewData[]

In the layoutfile products.php You will have to use this code to get data from viewData:
$categoryDescription = $viewData['categoryDescription'];

You can add as many items to the viewData as You like.

I hope you get the idea.

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

Alexikakos

I think i understand you,

but i think i need and an "echo" to display it.

i tried <?php echo shopFunctionsF::renderVmSubLayout('categories',array('product'=>$product,'categoryDescription'=>$categoryDescription)); ?> but not results,

How to echo "shopFunctionsF::renderVmSubLayout" for "categoryDescription"

Jörgen

I tried to show You the basics, not a cut and paste code.

In the present rendersublayout call you have to add Your new item with correct data for $categoryDescription. This will carry the data through to the sublayout.
In the sublayout (products.php) , You have to collect the $categoryDescription from the $viewData array. Then You can echo the $categoryDescription.

I use this technique in all my overrides, so I know it works, You just have to figure out where to adjust the code.

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

Dimi

Hello,
I'am trying to make the same thing, but I have a small problem.

My category tree is:
Products -> Women -> Shirts, Jackets, Dresses, etc.

I have a menu item Women where I display all the products of the subcategories.
I used Jörgen's code to display inside every product box the description of the category.

For example
In every dress I want to display the Dresses (subcategory) description, but the code I used fetches the Women (parent category) description.

Any ideas on what I should change?

Thank you.