First of all, let’s open these three files first:
- shop.browse.php in /administrator/components/com_virtuemart/html/shop.browse.php
- ps_product.php (Open this for explanation purpose)
- browse_1.php (The browse page in which your browse page is using)
Shop.browse.php
Search for this line:
// NOW START THE PRODUCT LIST
$tpl = vmTemplate::getInstance();
All code will be inserted after the line above. That created the object of class vmTemplate.
Before the add to cart button:
// Add-to-Cart Button
I insert the codes to set the manufacturer description (or name). In the manufacturer description I only have one image, which is the logo of the manufacturer.
$mf_desc = $ps_product->get_mf_desc( $db_browse->f(‘product_id’) );
$tpl->set(‘mf_desc’,$mf_desc);$mf_id = $ps_product->get_manufacturer_id( $db_browse->f(‘product_id’) );
$tpl->set(‘mf_id’,$mf_id);Put this code:
$products[$i][‘mf_desc’] = $mf_desc;
$products[$i][‘mf_id’] = $mf_id;right before : } // END OF while loop
Note: Do not put the code above inside any if condition statement after the $tpl = vmTemplate::getInstance(); Otherwise, the codes might not work probably.
So, you might ask what does this line say about:
$ps_product->get_mf_desc( $db_browse->f(‘product_id’) );
PS_product is the PHP class file “ps_product.php”.
ps_product.php
Inside this class, we found a method/function called “get_mf_name”.
And the method get_mf_name require a passin reference “product_id”.
We create a method called get_mf_desc after the get_mf_name method we put:
/**
* Functon to get the description of the manufacturer this product is assigned to
*
* @param int $product_id
* @return string the manufacturer description
*/
function get_mf_desc($product_id) {
$db = new ps_DB;$q = “SELECT mf_desc,#__{vm}_manufacturer.manufacturer_id FROM #__{vm}_product_mf_xref,#__{vm}_manufacturer “;
$q .= “WHERE product_id=’$product_id’ “;
$q .= “AND #__{vm}_manufacturer.manufacturer_id=#__{vm}_product_mf_xref.manufacturer_id”;$db->query($q);
$db->next_record();
if ($db->f(“mf_desc”)) {
return $db->f(“mf_desc”);
}
else {
return “”;
}
}
To get each product id in browse page, we have this build in function: $db_browse->f(‘product_id’)
Lastly, we put this “TAG” $mf_desc in our browse template file:browse_1.php
browse_1.php
<a href=”<?php echo $sess->url( URL.”index.php?option=com_virtuemart&page=shop.browse&manufacturer_id=”. $mf_id ) ?>” target=”_parent”>
<?php echo $mf_desc; ?>
</a>
Straight forward? Just echo the variables we defined before.
Hi,
I have tried everything outlined above but it didn’t work. I am trying to display the manufacturer’s name in the browse page but it does not display anything!
I am using Virtuemart 1.1.5
Joomla 1.5.22
Any ideas please?