How to extend JoomlaVirtuemart Module to have RSS List by Categories | 2008-06-05

Technology Blog » Web Development

Joomla has a great module system which allows us to have piece of script that appear in any module position that we set in the template.  Here is the tutorial I wrote to guide you how to extend the module without corrupting the orignal module features......

 

We have a virtuemart module called "mod_product_categories.php" that allow us to show the category list with the product list linked. Bt our objective is to have the RSS feed linked instead.

So you maight think that you can just change the A href in mod_product_categories.php,

however, you can't find it anyway.  Here is part of the original code of mod_product_categories.php:

 switch( $menutype ) {
    
    case 'transmenu':
        /* TransMenu script to display a DHTML Drop-Down Menu */
        include( $mosConfig_absolute_path . '/components/'.VM_COMPONENT_NAME.'/js/vm_transmenu.php' );
        break;

    case  'dtree':
        /* dTree script to display structured categories */
        include( $mosConfig_absolute_path . '/components/'.VM_COMPONENT_NAME.'/js/vm_dtree.php' );
        break;
    
    case 'jscook':
        /* JSCook Script to display structured categories */
        include( $mosConfig_absolute_path . '/components/'.VM_COMPONENT_NAME.'/js/vm_JSCook.php' );
        break;

    case 'tigratree':
        /* TigraTree script to display structured categories */
        include( $mosConfig_absolute_path . '/components/'.VM_COMPONENT_NAME.'/js/vm_tigratree.php' );
        break;

    case 'links' :
    default:
        /* MENUTPYE LINK LIST */
        require_once(CLASSPATH.'ps_product_category.php');
        $ps_product_category = new ps_product_category();

        echo $ps_product_category->get_category_tree( $category_id, $class_mainlevel );
}

So, you see the case option 'link' is very much similar to we we need.

$ps_product_category->get_category_tree
We does this line describing?

That means there is a ps_product_category class under /administrator/classes.
And in this class, there is a function/method called get_category_tree.

So, when we open this class, we find that the function get_category_tree has this line which is the <A> tag:

<a title="'.$catname.'" style="display:block;'.$style.'" class="'. $css_class .'" href="'.
$sess->url(URL."index.php?page=shop.browse&category_id=
".$category_tmp[$row_list[$n]]["category_child_id"]) .'" '.$append.'>'

We look back to Virtuemart RSS page, we found that the only difference to that is the link should go to "shop.feed page" instead of "shop.browse" instead. ( with $categoryid).

We could directly hard this line, but what if we need the "link" optiona as well, so why don't we enable another option in the switch above?

under the switch( $menutype), we add this case:

switch( $menutype ) {
   

//The following code is written by andy [email protected]
//Please keep the above credit

    case 'rsslist':
        /* RSS script to display rss icon with categories */
        /* MENUTPYE LINK LIST */
        require_once(CLASSPATH.'ps_product_category.php');
        $ps_product_category = new ps_product_category();

        echo $ps_product_category->get_category_rsslist( $category_id, $class_mainlevel );
        break;

Once we have this case added, will also need add the option in mod_product_categories.xml file,
so in the <params>, we added the option value "rsslist":

        <param name="menutype" type="list" default="jscook"
            label="Category display type"
            description="You can set the display type to *links* to have the default display type: a link list. If you set it to *dTree*, the categories will be displayed in a dTree structure.">
            <option value="rsslist">RSS List</option>
            <option value="links">Link List</option>
            <option value="tigratree">TigraTree</option>
            <option value="jscook">JSCook</option>
            <option value="transmenu">TransMenu</option>
            <option value="dtree">dTree</option>
        </param>

Anything has been done at this point, the last step is that you should go to the backend module manager, and switch the menutype option to "RSS list". If you are already have this module runing, you may just clonet his module in Backend, and change the option in the new created module without having to touch the orginal module.