News:

Support the VirtueMart project and become a member

Main Menu

Routing and pagination

Started by ereallstaff, January 20, 2014, 13:34:12 PM

Previous topic - Next topic

ereallstaff

Un virtuemart 2.0.26d and joomla 2.5.14

I make the menu of categories with joomla component ( I don't use a component of menu three )

I have one menu for mobile and one menu for standard version for each language. 

I was having problem with pagination and limitBox.   The template use standard methods, but in SEF version it generates wrong link

After lots of debugging I have found the instruction making the system crazy :

// components/com_virtuemart/router.php - function virtuemartBuildRoute  -- line 90

     if ( isset($jmenu['category']) ) $query['Itemid'] = $jmenu['category'];


the jmenu in all template came always with $jmenu['category'] = 801 on each category triggered.

That brought up to errors in each category or search. I couldn't find the reason , but every time a $helper = vmrouterHelper::getInstance($query); is called, it gets also a menu ['category'] = 801

commenting this ( for now ) seems making all works fine

Thanks

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ì
Try out our new joomla background rotator ( for joomla 1.x or 2.x), for only 14,99 eur @ innovailweb.it

Milbo

Strange that you have problems with it. This is the function imho attaching the itemId given by joomla. Defined by the menuitem.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

mbarry

Hi ereallstaff,
I found exactly the same problem in VM 2.0.26d. After a day of debugging this issue where all my Category links and Continue Shopping Link displayed on the Shopping Cart page were broken.

The category link for Accessories would be built as
      <site>/index.php/shopping-cart/accessories

The Continue Shopping link would be built as
     <site>/index.php/shopping-cart/accessories


I came up with a similar fix but to a different section of the same category routing code.
In my case, I commented out the test and simply assigned the value in the event that $categoryRoute->itemId might have a valid value under some conditions.
I tested as many paths through our site and could not find any side effect as yet.
   

commented out          //if ($categoryRoute->itemId) $query['Itemid'] = $categoryRoute->itemId;
replaced with this
                                  $query['Itemid'] = $categoryRoute->itemId;


I noticed that whenever I clicked on a link to go to the shopping cart via a menu or the modal popup this problem would occur.

As an example:
The call to $continue_link = JRoute::_('index.php?option=com_virtuemart&view=category' . $categoryLink, FALSE);
from the components/com_virtuemart/view/cart/view.html.php line 197 would fail however, the same call from components/com_virtuemart/view/cart/view.json.php line 66 works fine.

In both cases build($url) line 188 in libraries/joomla/application/router.php calls $this->_createURI($url) see code fragement below.

The key difference is when line 472 is evaluated. $item  = $menu->getItem($this->getVar('Itemid'));
In the instance that where the links work, this returns $item  = <uninitialised>, in cases where it doesn't work, it returns the value of 128 where in my case this is the ID of the shopping cart alias shopping-cart.
As Milbo points out this is Joomla adding the ItemId using $this->getVar('Itemid') when $uri->getVar('Itemid'); failed earlier.


includes/router.php

protected function _createURI($url)
{
//Create the URI
$uri = parent::_createURI($url);

// Set URI defaults
$app = JApplication::getInstance('site');
$menu = $app->getMenu();

// Get the itemid form the URI
$itemid = $uri->getVar('Itemid');   <- For "view=category" $itemid is <unitialised>

if (is_null($itemid)) {
if ($option = $uri->getVar('option')) {
$item  = $menu->getItem($this->getVar('Itemid')); <- For "view=category", this is evaluated as $this->_vars[$key] and returns (in my case) 128 which is the ID of the shopping-cart Object
if (isset($item) && $item->component == $option) {
$uri->setVar('Itemid', $item->id);



Function build($url) then goes on to call $this->_buildSefRoute($uri); line 205 

includes/router.php line 347:  _buildSefRoute($uri) calls the virtuemart router where we have made the changes identified above.

Finally, _buildSefRoute($uri) tests the existance of $query['Itemid'] and that it is not empty on line 372 
if (isset($query['Itemid']) && !empty($query['Itemid'])) {

Since it now has a value of 128 instead of either value zero or <uninitialised>, the preceeding code is executed building an incorrect sefroute line 376
$tmp = !empty($tmp) ? $item->route.'/'.$tmp : $item->route;

The correct path to be taken should have been line 383
$tmp = 'component/'.substr($query['option'], 4).'/'.$tmp;

I'm not sure what the correct fix is and it seems like there are multiple ways this can get messed up.


ereallstaff

I don't know if I have read correctly your reply

Anyway I suppose you are having same problem than me, but I didn't understand how you did modify this?

I think that commenting out the line I did could be less troubling on next virtuemart update ( as it's just one line ) . And I hope in next version could not change much more.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ì
Try out our new joomla background rotator ( for joomla 1.x or 2.x), for only 14,99 eur @ innovailweb.it

mbarry

Sorry post is a little confusing as the change was simple enough; the remainder was an attempt to explain where it was going wrong.


components/com_virtuemart/router.php - function virtuemartBuildRoute

if ( isset($query['virtuemart_category_id']) ) {
     if (isset($jmenu['virtuemart_category_id'][ $query['virtuemart_category_id'] ] ) )
$query['Itemid'] = $jmenu['virtuemart_category_id'][$query['virtuemart_category_id']];
     else {
$categoryRoute = $helper->getCategoryRoute($query['virtuemart_category_id']);
if ($categoryRoute->route) $segments[] = $categoryRoute->route;
//if ($categoryRoute->itemId) $query['Itemid'] = $categoryRoute->itemId; <- my line which I commented out
$query['Itemid'] = $categoryRoute->itemId;                      <- added this line to override the current value inserted into $query['Itemid'] by _createURI($url) in includes/router.php

    }
    unset($query['virtuemart_category_id']);
}
if ( isset($jmenu['category']) ) $query['Itemid'] = $jmenu['category'];   <- Your line 90 which you commented out


Milbo

Please try this router

[attachment cleanup by admin]
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

mbarry

Thanks Milbo; updated router works.