Sun 03 Dec 2006
5:00PM
compton

Making Joomla Modules

There are two essential files: one the XML descriptor, and two the PHP code. Both filenames begin mod_, then are followed by the name of the module, and the appropriate file extension of course.

So, to make a new featured items module (or really a special offers module) is fairly straightforward. The problem is how to mark products for display in this module. It would require some new field in the database, say an extra column in the #__{vm}_product table. A way to mark products, which sets this column, is then required in the admin panel.

The current featured items module appears to use the product_special column of this table. So we need to add a second checkbox for setting the new column.

The admin page where this checkbox is to be added is defined by the page=product.product_form parameter. The tabs on this page must be controlled by JS as the querystring is not changed when the active tab is changed.

Let's find where the content for the product admin page is created. The main index2.php page gets its content from the index.php page of the current template. However, the template simply defines the wrapper for the page content. The content itself is loaded into the output buffer, with line 62 of index2.php. The buffer contains the content of the file $mainframe->getPath( 'admin' ), if it exists. If we echo this variable, we can find the page which creates the content for any of the admin sections.

Thus, it seems VirtueMart admin content is generated by /administrator/components/com_virtuemart/admin.virtuemart.php.

compton

11:58 am, Monday, 4 December 06

the page=product.product_form parameter is exploded on '.'. This gives two values (ie there can only ever be one fullstop in this parameter value), the first indicates the name of the module, the second the page name. The appropriate content for the page is thus included with PAGEPATH.$modulename.".".$pagename.".php" (the exploding on '.' is completely redundant so far - perhaps it's used within the included page?).

A search for this product.product_form.php page locates it within \administrator\components\com_virtuemart\html. The form is created in PHP, using a formFactory class.

The labels for the form elements are taken from the language file, as you'd expect. The tabs are handled by the mShopTabs PHP class. To start it off, we call startPane(), and each tab is enclosed by calls to startTab() and endTab().

So, to change the featured item text, which is currently 'On special', we have to change the _PHPSHOP_PRODUCT_FORM_SPECIAL language constant.
 

compton

12:08 pm, Monday, 4 December 06

Rather than creating a new Specials module, it would maybe be best to create a custom Featured module instead. After all, the existing module which is currently being used for the featured item has all the functionality required for a special offers module.
 

compton

11:02 am, Tuesday, 5 December 06

The Featured Product module PHP is found at /modules/mod_virtuemart_featureprod.php. So far the "Special Offers" image and "See all offers" link have been added, as a table above the existing content.

Next I would like to format the items on display in this module to match Kashif's design. Currently the ps_product::show_snapshot() method is used to do this. What I need to do is display the image alone, within a table formatted to match the design.

I have already added the boolean $display_vertical parameter to the ps_product::show_snapshot() function, and this parameter determines whether to show the product info to the right of the image (true) or below it (false).

If this parameter is changed to string, and renamed to say $display_type, the ps_product::show_snapshot() function can be adapted to generate the correct format for snapshots shown in Featured Items, Special Offers, and Top 10. It would also be straightforward to add new display types for other modules as required.
 

compton

10:20 am, Thursday, 7 December 06

I managed to get a module to appear on the static 'Special Offers' page I created. To do so, I had to change the database manually, so that there was a record in the modules_menu table with a moduleid of 38 and a menuid of 27. I got these values by examining the query which is executed by initModules() in the /includes/frontend.php file.

Now I can do this, I can create a new Special Offers module, and have it display only on the static Special Offers page. This new module can be based on the existing one, but showing all special offers.

Kashif's design for this page groups all special offers into their categories. Each product on special appears as a single link within a category box. This has the drawback that when there are different numbers of products on special in different categories, these lists will be a bit messy looking.

An alternative is to 'showcase' 6 special offers, chosen at random, at the top of the page. Below that, special offers are then listed as simpler links, possibly ordered by category. Perhaps showcase items should also appear in the lower list?
 

compton

11:12 am, Saturday, 24 March 07

This particular site was completed some time ago. The customer was extremely pleased, which is always a good result!

The special offers module is available here. You can also see how it appears on the front page here.
 

/xkcd/ Kedging Cannon