News:

Looking for documentation? Take a look on our wiki

Main Menu

VirtueMart URL ?Itemid=0

Started by stevewc84, May 28, 2012, 11:04:19 AM

Previous topic - Next topic

Sirinidis Nikolaos

#15
ok, this might be an old topic but problem still exists in VM 2.0.22c

here is my quick fix/solution:
you have to edit router.php file that is located in /components/com_virtuemart/
somewhere around line 764 you will find a function called "getCategoryRouteNocache"
now you have to replace variable "$category->itemId" (line 768) with the code below:

$menu   = JFactory::getApplication()->getMenu();
//get menu item with virtuemart link
$item = $menu->getItems('link', 'index.php?option=com_virtuemart&view=categories&virtuemart_category_id=0', false);
if ($item[0]->id < 0)
{
$item = $menu->getItems('link', 'index.php?option=com_virtuemart&view=virtuemart', false);
}
//set item id
$category->itemId = $item[0]->id;


this solutions also fixes the problem with SEF url for category module and all other modules that uses JRoute::_ function to generate links
κατασκευή ιστοσελίδων http://www.netikon.gr

Milbo

the function looks now like this


/* Get Joomla menu item and the route for category */
public function getCategoryRouteNocache($virtuemart_category_id){
if (! array_key_exists ($virtuemart_category_id . $this->vmlang, self::$_catRoute)){
$category = new stdClass();
$category->route = '';
$category->itemId = 0;
$menuCatid = 0 ;
$ismenu = false ;

// control if category is joomla menu
if (isset($this->menu['virtuemart_category_id'])) {
if (isset( $this->menu['virtuemart_category_id'][$virtuemart_category_id])) {
$ismenu = true;
$category->itemId = $this->menu['virtuemart_category_id'][$virtuemart_category_id] ;
} else {
$CatParentIds = $this->getCategoryRecurse($virtuemart_category_id,0) ;
/* control if parent categories are joomla menu */
foreach ($CatParentIds as $CatParentId) {
// No ? then find the parent menu categorie !
if (isset( $this->menu['virtuemart_category_id'][$CatParentId]) ) {
$category->itemId = $this->menu['virtuemart_category_id'][$CatParentId] ;
$menuCatid = $CatParentId;
break;
}
}
}
}
if ($ismenu==false) {
if ( $this->use_id ) $category->route = $virtuemart_category_id.'/';
if (!isset ($this->CategoryName[$virtuemart_category_id])) {
$this->CategoryName[$virtuemart_category_id] = $this->getCategoryNames($virtuemart_category_id, $menuCatid );
}
$category->route .= $this->CategoryName[$virtuemart_category_id] ;
if ($menuCatid == 0  && $this->menu['virtuemart']) $category->itemId = $this->menu['virtuemart'] ;
}
self::$_catRoute[$virtuemart_category_id . $this->vmlang] = $category;
}

return self::$_catRoute[$virtuemart_category_id . $this->vmlang] ;
}


How do you mean it? Maybe the new functions fixes it, or you have a better method. Lets discuss it out :-)
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Sirinidis Nikolaos

#17
sorry if I am not that clear :)

Now, in this function... you set
$category->itemId = 0;

and then you make some checks..
first check " if (isset($this->menu['virtuemart_category_id'])) " fails because we are not in any virtuemart category since we are in frontpage and virtuemart is not set as default homepage.
so we then go to the second check " if ($ismenu==false) ".... yes it's false because we have already set it before
then we have "  if ($menuCatid == 0  && $this->menu['virtuemart']) " that fails to assign $this->menu['virtuemart']  to $category->itemId
because $this->menu['virtuemart'] is not set...
and that is how we stuck with $category->itemId = 0; that we have earlier defined.

I don't now if I am correct..
but that is what I thought and understood when I checked your code.


so what I did was to use joomla's methods to get an item id from the first menu item that will have " index.php?option=com_virtuemart&view=categories&virtuemart_category_id=0 " or " index.php?option=com_virtuemart&view=virtuemart "
and then set $category->itemId instead of just having it as 0

download router file from here http://www.netikon.gr/joomla-extensions

κατασκευή ιστοσελίδων http://www.netikon.gr

keran

Sirinidis Nikolaos Thank You! Your router.php fix works! Great job :)

gas79

Hi, after going crazy for some days, and didn't want to touch the router.php core files, I discovered that my only two products that showed 'ItemId=0' had the field 'URL', in the 'Information' tab valorized!
I cleared the 'URL' field, and 'ItemID=0' disappeared, showing my SEF url as expected.
I hope this could help someone.
Bye.