One of the wonderful things about open source software like Joomla is the high degree of customizability. This is important when a project has specific requirements that might not be exactly common, and are therefore not natively supported. The shopping cart extension Virtuemart is no exception. Here is a quick pointer to add product type infomation and custom fields to Virtuemart category pages.
Adding Custom Fields to Virtuemart Layouts
Recently a client requested a feature for the popular Joomla ecommerce platform, Virtuemart: the ability to display different product attributes in the category view.
Virtuemart has something called Product Types, which you can use to configure different parameters for each product that will display in the product details view. These are what Virtuemart calls "custom fields." Knowing this, it can be assumed that if you were to include the code from the product details template that outputs the product type parameters into the category template, they would automatically appear in the category view. Unfortunately, it's not that easy.
So how is it done?
Fortunately, there is a solution, which I found after some research (and scouring the Virtuemart forums).
- Make sure you back up your files!
- Navigate to administrator/components/html and open shop.browse.php
-
Look for (around line 59):
require_once(CLASSPATH . 'ps_product_attribute.php' ); $ps_product_attribute = new ps_product_attribute;
-
After it add this:
require_once(CLASSPATH . 'ps_product_type.php' ); $ps_product_type = new ps_product_type;
-
Next look for:
$product_s_desc = $db_browse->f("product_s_desc"); if( empty($product_s_desc) && $product_parent_id!=0 ) { $product_s_desc = $dbp->f("product_s_desc"); // Use product_s_desc from Parent Product } -
And add this after:
$flerd_product_id = $db_browse->f("product_id"); $product_type = $ps_product_type->list_product_type($flerd_product_id); -
Then after:
$products[$i]['product_s_desc'] = $product_s_desc;
-
Add:
$products[$i]['product_type'] = $product_type;
- Save and upload your file.
- Next navigate to components/com_virtuemart/themes/(name of theme)/templates/browse and open browse_1.php (or whichever template you're using for your category view)
- Add this code: wherever in your template you want the product type parameters to appear.
That's it, now just style it using css!
Doctor's Orders
Virtuemart can be a powerful tool for quickly deploying an ecommerce store. The best thing? It is totally free! If you haven't used it before go check it out. If you have used it and need advanced functionality, keep coming back for Virtuemart tutorials right here on JomDoc or Ask the Doctor for help.





