Author Topic: JRequest::getVar('view') returns 'Frontpage' on VM pages and URL problems  (Read 137192 times)

baggiesmad

  • Jr. Member
  • **
  • Posts: 308
Re: JRequest::getVar('view') returns 'Frontpage' on VM pages and URL problems
« Reply #75 on: September 20, 2010, 17:58:12 pm »
Hello,

This problem is mostly on VM's side. Joomla 1.5 has new way of resolving Itemid and option values. It uses JURI class to parse query string. VM passes 'index.php' instead of 'index.php?option=com_virtuemart&Itemid=<some id>' to JURI parser. So joomla just can't resolve correct option and Itemid values and uses default ('frontpage' with Itemid=1).

How to fix it? There are two ways. The first one is fixing all 'incorrect' VM's forms by changing tiny 'action="index.php"' to correct URIs with option and Itemid arguments. This solution is already provided by johk.

The second way to alter joomla code a little bit to support Itemid and option values from $_REQUEST. So here is my solution.

1. Find file named 'libraries/joomla/application/application.php'

2. Find these 2 lines (they are located somewhere around line #191):

Code: [Select]
// get the full request URI
$uri = clone(JURI::getInstance());

3. Just after these lines add this code:

Code: [Select]
// VM uri fix
if (!$uri->getVar('Itemid') && isset($_REQUEST['Itemid']) || !$uri->getVar('option') && isset($_REQUEST['option'])) {
if (!$uri->getVar('Itemid') && isset($_REQUEST['Itemid'])) {
$uri->_query = ($uri->_query ? '&' : '').'Itemid='.(int)$_REQUEST['Itemid'];
}
if (!$uri->getVar('option') && isset($_REQUEST['option'])) {
$uri->_query = ($uri->_query ? '&' : '').'option='.$_REQUEST['option'];
}
parse_str($uri->_query, $uri->_vars);
}
// end VM uri fix

The final result must be:

Code: [Select]
// get the full request URI
$uri = clone(JURI::getInstance());

// VM uri fix
if (!$uri->getVar('Itemid') && isset($_REQUEST['Itemid']) || !$uri->getVar('option') && isset($_REQUEST['option'])) {
if (!$uri->getVar('Itemid') && isset($_REQUEST['Itemid'])) {
$uri->_query = ($uri->_query ? '&' : '').'Itemid='.(int)$_REQUEST['Itemid'];
}
if (!$uri->getVar('option') && isset($_REQUEST['option'])) {
$uri->_query = ($uri->_query ? '&' : '').'option='.$_REQUEST['option'];
}
parse_str($uri->_query, $uri->_vars);
}
// end VM uri fix

That's all. I haven't tested it alot but seems it is working for me.


fixed! thanks

Lee Wilson

  • Jr. Member
  • **
  • Posts: 82
Re: JRequest::getVar('view') returns 'Frontpage' on VM pages and URL problems
« Reply #76 on: October 20, 2010, 18:24:57 pm »
A thumbs up for this. I still can't quite believe that this is an issue after reading threads of up to 2 years old with no fix.... finally stumbled on this. Thank you

flora01

  • Beginner
  • *
  • Posts: 23
    • Flora Organica
Re: JRequest::getVar('view') returns 'Frontpage' on VM pages and URL problems
« Reply #77 on: October 26, 2010, 08:44:31 am »
thanks pollar :D
you just made my day :D

I'll append this link to the list of the
"joomla/virtuemart posts that made my day" in my signature

again, a million thanks :)

PS, i'm on  VM1.5 joomla 1.5.21
no probs so far :)
Live Smart, Eat Smart,
Flora Organica http://www.flora-organica.com

the Joomla/Virtuemart links that made my day
"checkout redirects to index.php"? read this: http://forum.virtuemart.net/index.php?topic=34989.msg170542#msg170542

Brick Stone

  • Beginner
  • *
  • Posts: 11
My version of issue is solved
« Reply #78 on: January 13, 2011, 15:50:39 pm »
I was not doing well with this... not after metamodguy posted his snippet.  Then it dawned on me...

All these codes do fix everything... but then if you apply his to my situation

Quote
the pop confirmation dialogue pointed to some different cart.  I made a menu link to this url.  but this version of the cart still malfunctioned.
Well here is what happened.

All the fixes tell Virtuemart to get an actual Itemid or to at least try...

But then Metamod's snippet told the whole system to reference and redirect to Itemid=1  and that was still not working... one cart button brought up one page... and the tiny cart button in the pop up dialogue... pointed to another verion of the main storefront....  ODD!!! and this one was still broken


so I changed metatmod's code to make it a different number... and all is well

Code: [Select]
function getShopItemid() {

if( empty( $_REQUEST['shopItemid'] )) {
$db = new ps_DB;
$db->query( "SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND published=1");
$ids = $db->loadResultArray();
if ( !is_array($ids) or count($ids) == 0 ) {
$_REQUEST['shopItemid'] = 18;
} else if ( array_search( $_REQUEST['Itemid'], $ids ) !== false ) {
$_REQUEST['shopItemid'] = $_REQUEST['Itemid'];
} else {
$_REQUEST['shopItemid'] = $ids[0];
}
}

return intval($_REQUEST['shopItemid']);

}


Yeah so far so good. Thanks for everyone's help on this!

martin

  • Beginner
  • *
  • Posts: 3
Your a genious Pollar, really saved my day. Those this file get overridden often when joomla updates its core files?

Thanks

jeffhoneyager

  • Jr. Member
  • **
  • Posts: 54
  • Matt. 11:28
    • Expert Web Professionals
  • VirtueMart Version: 2.0.20b
Thank you Pollar!

I made this change in the application.php file and so far my testing is fruitful.  It worked!

Now I hope I remember this hack when there is a new upgrade to Joomla...
Peace & Joy,
Jeff Honeyager
...using VirtueMart since 2006
http://jeff.honeyager.com

cclay

  • Beginner
  • *
  • Posts: 4
    • Digital Bloom
Just want to add my thanks to pollar for his fix. It worked perfectly...  :) 

I don't understand why this would still be an issue with Virtuemart after all this time.  :o  Hopefully a fix can be built into future versions.

Cheers,
Chris

dontflinch

  • Jr. Member
  • **
  • Posts: 152
Re: JRequest::getVar('view') returns 'Frontpage' on VM pages and URL problems
« Reply #82 on: November 18, 2011, 00:34:51 am »
Hello,

This problem is mostly on VM's side. Joomla 1.5 has new way of resolving Itemid and option values. It uses JURI class to parse query string. VM passes 'index.php' instead of 'index.php?option=com_virtuemart&Itemid=<some id>' to JURI parser. So joomla just can't resolve correct option and Itemid values and uses default ('frontpage' with Itemid=1).

How to fix it? There are two ways. The first one is fixing all 'incorrect' VM's forms by changing tiny 'action="index.php"' to correct URIs with option and Itemid arguments. This solution is already provided by johk.

The second way to alter joomla code a little bit to support Itemid and option values from $_REQUEST. So here is my solution.

1. Find file named 'libraries/joomla/application/application.php'

2. Find these 2 lines (they are located somewhere around line #191):

Code: [Select]
// get the full request URI
$uri = clone(JURI::getInstance());

3. Just after these lines add this code:

Code: [Select]
// VM uri fix
if (!$uri->getVar('Itemid') && isset($_REQUEST['Itemid']) || !$uri->getVar('option') && isset($_REQUEST['option'])) {
if (!$uri->getVar('Itemid') && isset($_REQUEST['Itemid'])) {
$uri->_query = ($uri->_query ? '&' : '').'Itemid='.(int)$_REQUEST['Itemid'];
}
if (!$uri->getVar('option') && isset($_REQUEST['option'])) {
$uri->_query = ($uri->_query ? '&' : '').'option='.$_REQUEST['option'];
}
parse_str($uri->_query, $uri->_vars);
}
// end VM uri fix

The final result must be:

Code: [Select]
// get the full request URI
$uri = clone(JURI::getInstance());

// VM uri fix
if (!$uri->getVar('Itemid') && isset($_REQUEST['Itemid']) || !$uri->getVar('option') && isset($_REQUEST['option'])) {
if (!$uri->getVar('Itemid') && isset($_REQUEST['Itemid'])) {
$uri->_query = ($uri->_query ? '&' : '').'Itemid='.(int)$_REQUEST['Itemid'];
}
if (!$uri->getVar('option') && isset($_REQUEST['option'])) {
$uri->_query = ($uri->_query ? '&' : '').'option='.$_REQUEST['option'];
}
parse_str($uri->_query, $uri->_vars);
}
// end VM uri fix

That's all. I haven't tested it alot but seems it is working for me.


fixed! thanks

ditto, thanks from me too!

David Richmond

  • Beginner
  • *
  • Posts: 29
Re: JRequest::getVar('view') returns 'Frontpage' on VM pages and URL problems
« Reply #83 on: February 18, 2012, 01:52:42 am »
BIG THANKS!!

searched forums and tried hacking action_urls for 2 hours!

You saved my bacon!

David

adeelsikander

  • Beginner
  • *
  • Posts: 1
Re: JRequest::getVar('view') returns 'Frontpage' on VM pages and URL problems
« Reply #84 on: October 03, 2012, 16:00:38 pm »
I was stuck on this problem since last two days it really help full for me