Virtuemart and the impossible Modules

posted in: Stuff | 0

Geekspeak alert. The following is a horror story about playing with Joomla, VirtueMart and its PHP files. May this help anyone looking for a solution to the itemID problem in VirtueMart. The following may not be a perfect solution, however, in the particular situation it worked like a charm and continues to work.So, on to the story. Recently, a client and friend of mine had been trying to get a Joomla VirtueMart installation to work. His designer/programmer and him had been trying to fix it for some time and their end client was very precise about having a carousel with each category’s products scrolling in said category’s products’ page. This meant that they needed an instance of the the module with each different set of products scrolling on every page related to a category.

Now, this doesn’t work in Virtuemart as expected. For some reason, it kept showing only one of the carousel modules on every single category. The designer/programmer and my client were at their wits’ end after trying various modules, setups and menus. When I looked at it, I noted that the itemID was the problem as it wasn’t adapting to each category and thus, just showing the same carousel module on every category.

So, the problem was it kept generating URLs with a default itemID for all menu items and showing the same carousel for all categories. To find a solution I would have to dig deeply into the VirtueMart code.

It turns out that VirtueMart has a failsafe to generate a base itemID URL when no itemID is available. Most of the time this is not really necessary and in my client’s case, it wasn’t. So out with it. Hard problem, seemingly easy solution (just need to find it though!).

The culprit (for those who need to know) is this little file: (home folder)/administrator/components/com_virtuemart/classes/ps_session.php

The code removed (just delete it):

$Itemid = "&Itemid=" . ($tmp_Itemid ? $tmp_Itemid : $this->getShopItemid());

It is supposed to put the shop item ID when no item ID can be found, however that is not the case as it takes all perfectly functional IDs and trades them for the first ID available in the menu. The result, the same modules on all categories instead of the modules you want displayed.

So, once that done, the system began showing the proper modules in each category and managing the site became much easier.