Use Joomla Menu for Virtuemart [Updated]
Written by Thomas Kahl   
Sunday, 05 October 2008 16:48

In Joomla, you can define a virtuemart-menuitem and assign a product-id (for example). This works so far. You can click on the menu item and the product flypage is opened. This way, you are able to publish modules on specific virtuemart products or pages.

The problem is, that the Itemid of the menu is not selected, when you open the product through another way (e.g. browse page, next / previous product). The Itemid is also not selected, when virtuemart has to redirect.

The reason for that is, that virtuemart searches the #__menu table for the first occurance of virtuemart and uses the menu id found as Itemid. This is mostly not the Itemid you want to have.

We have created a small script that corrects this behaviour:

You will have to edit (and backup!!!) the file "/administrator/components/com_virtuemart/classes/ps_session.php". Find the function url(...) and replace the line in the first if-clause (should be around line 499) with the following code:

// Original Virtuemart Code:
// $Itemid = "&Itemid=".$this->getShopItemid();
// VM-Expert Hack – Start

// Strip the parameters from the $text variable and parse to a temporary array
$tmp_text=str_replace('amp;','',substr($text,strpos($text,'?')));
if(substr($tmp_text,0,1)=='?') $tmp_text=substr($tmp_text,1);
parse_str($tmp_text,$ii_arr);

// Init the temp. Itemid
$tmp_Itemid='';

$db = new ps_DB;

// Check if there is a menuitem for a product_id (highest priority)
if ($ii_product_id=intval($ii_arr['product_id'])) {
$db->query( "SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND params like '%product_id=$ii_product_id%' AND published=1");
if( $db->next_record() ) $tmp_Itemid = $db->f("id");
}
// Check if there is a menuitem for a category_id
$ii_cat_id=intval($ii_arr['category_id']);
if ( $ii_cat_id && $tmp_Itemid=='') {
$db->query( "SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND params like '%category_id=$ii_cat_id%' AND published=1");
if( $db->next_record() ) $tmp_Itemid = $db->f("id");
}
// Check if there is a menuitem for a flypage
$ii_flypage=$ii_arr['flypage'];
if ($ii_flypage && $tmp_Itemid=='') {
$db->query( "SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND params like '%flypage=$ii_flypage%' AND published=1");
if( $db->next_record() ) $tmp_Itemid = $db->f("id");
}
// Check if there is a menuitem for a page
$ii_page=$ii_arr['page'];
if ($ii_page && $tmp_Itemid=='') {
$db->query( "SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND params like '%page=$ii_page%' AND published=1");
if( $db->next_record() ) $tmp_Itemid = $db->f("id");
}
// If we haven't found an Itemid, use the standard VM-Itemid
$Itemid = "&Itemid=" . ($tmp_Itemid ? $tmp_Itemid : $this->getShopItemid());

// VM-Expert Hack - End

This code checks the menu table more detailed than virtuemart itself does it. If a matching record is found, this can be product_id, category_id, flypage or pagename, the Itemid is selected. If no match is found, the default virtuemart Itemid is selected.

There is one thing to keep in mind: as described before, virtuemart selects the first Itemid found. To make sure that this is not a “special” menuitem, add a default virtuemart menuitem before you set up the other items so this item has the lowest menu_id.

Another tip: the menu that holds the items can be invisible if you just want this feature to assign modules.

If you have SEO-Tools active, you should purge the old shop-urls, because they may use the old Itemid's.

You need this feature? Let us do the hard work: we apply this hack for you!

Add to Cart
Trackback(0)
Comments (31)Add Comment

Write comment
smaller | bigger

security code
Write the displayed characters


busy
 

Blog Newsletter

Blog RSS-Feed Click here

Subscribe to our Blog Newsletter

Enter your email address:

Delivered by FeedBurner