
So last time we discussed how to add image all tags to good ol' Virtuemart 1.1x's products. Now I know we are up to Virtuemart 2 (which I am really excited about but haven't had anytime to delve into) but I know there are alot of shop owners out there that have modified Virtuemart 1.1x so much that they are very nervous about migrating to Virtuemart 2 at this time. I'm right there with you guys.
So for the rest of us stubborn people that haven't made the upgrade here's how to add image alt tags to the category pages.
1. First, as before we will need to add a field to the database for the new image all field. This time we add it to the table "jos_vm_category". I am calling this one "cat_image_alt".
2. Open /administrator/components/com_virtuemart/html/product.product_category_form.php and add about line 179 after
<tr>
<td width="21%" ><?php echo $VM_LANG->_('URL')." (".$VM_LANG->_('CMN_OPTIONAL')."!) "; ?></td>
<td width="79%" >
<?php
if( stristr($db->f("category_full_image"), "http") )
$category_full_image_url = $db->f("category_full_image");
else if(!empty($_REQUEST['category_full_image_url']))
$category_full_image_url = vmGet($_REQUEST, 'category_full_image_url');
else
$category_full_image_url = "";
?>
<input type="text" class="inputbox" size="50" name="category_full_image_url" value="" onchange="if( this.value.length>0) document.adminForm.auto_resize.checked=false; else document.adminForm.auto_resize.checked=true; toggleDisable( document.adminForm.auto_resize, document.adminForm.category_thumb_image_url, true );toggleDisable( document.adminForm.auto_resize, document.adminForm.category_thumb_image, true );" />
</td>
</tr>
add:
<tr class="row1">
<td width="21%" ><div style="text-align:right;font-weight:bold;">Image Alt Tag:</div>
</td>
<td width="79%" height="2">
<input type="text" class="inputbox" name="cat_image_alt" value="<?php $db->sp("cat_image_alt"); ?>" size="32" maxlength="64" />
</td>
</tr>
Step 3: Open administrator/components/com_virtuemart/classes/ps_product_category.php and add to lines 261 and 325 (within "$fields = array (")
'cat_image_alt' => vmGet($d,'cat_image_alt'),
Step 4. Within the same file around line 916 find:
/**
* creates a bulleted of the childen of this category if they exist
* @author pablo
* @param int $category_id
* @return string The HTML code
*/
function get_child_list($category_id) {
global $sess, $ps_product, $VM_LANG;
$ps_vendor_id = $_SESSION["ps_vendor_id"];
$db = new ps_DB;
$childs = array();
$q = "SELECT category_id, category_thumb_image, category_child_id,category_name FROM #__{vm}_category,#__{vm}_category_xref ";
$q .= "WHERE #__{vm}_category_xref.category_parent_id='$category_id' ";
$q .= "AND #__{vm}_category.category_id=#__{vm}_category_xref.category_child_id ";
$q .= "AND #__{vm}_category.vendor_id='$ps_vendor_id' ";
$q .= "AND #__{vm}_category.category_publish='Y' ";
$q .= "ORDER BY #__{vm}_category.list_order, #__{vm}_category.category_name ASC";
$db->setQuery($q);
$db->query();
while( $db->next_record() ) {
$childs[] = array (
'category_name' => $db->f("category_name"),
'category_id' => $db->f("category_id"),
'category_thumb_image' => $db->f("category_thumb_image"),
'number_of_products' => ps_product_category::products_in_category( $db->f("category_id")),
);
}
return $childs;
}
and replace with:
/**
* creates a bulleted of the childen of this category if they exist
* @author pablo
* @param int $category_id
* @return string The HTML code
*/
function get_child_list($category_id) {
global $sess, $ps_product, $VM_LANG;
$ps_vendor_id = $_SESSION["ps_vendor_id"];
$db = new ps_DB;
$childs = array();
$q = "SELECT category_id, cat_image_alt, category_thumb_image, category_child_id,category_name FROM #__{vm}_category,#__{vm}_category_xref ";
$q .= "WHERE #__{vm}_category_xref.category_parent_id='$category_id' ";
$q .= "AND #__{vm}_category.category_id=#__{vm}_category_xref.category_child_id ";
$q .= "AND #__{vm}_category.vendor_id='$ps_vendor_id' ";
$q .= "AND #__{vm}_category.category_publish='Y' ";
$q .= "ORDER BY #__{vm}_category.list_order, #__{vm}_category.category_name ASC";
$db->setQuery($q);
$db->query();
while( $db->next_record() ) {
$childs[] = array (
'category_name' => $db->f("category_name"),
'category_id' => $db->f("category_id"),
'category_thumb_image' => $db->f("category_thumb_image"),
'cat_image_alt' => $db->f("cat_image_alt"),
'number_of_products' => ps_product_category::products_in_category( $db->f("category_id")),
);
}
return $childs;
}
Step 5: Open components/com_virtuemart/themes/default/templates/common/categoryChildlist.tpl.php and around line 29 find:
echo ps_product::image_tag( $category["category_thumb_image"], "alt=\"".$category["category_name"]."\"", 0, "category");
Replace with:
echo ps_product::image_tag( $category["category_thumb_image"], "alt=\"".$category["cat_image_alt"]."\"", 0, "category");
That should be it. Please comment below if you find any problems or have suggestions with this code.