JRequest::getVar('view') returns 'Frontpage' on VM pages and URL problems

Started by unleash.it, December 28, 2007, 05:36:15 AM

Previous topic - Next topic

rgibbs421

That seemed to mess a few things up so I also used dreamweavers ability to do a site wide replace and replaced all the virtuemart&Itemid=1 with virtuemart&Itemid=11.. looks to be working fine now..
NOTE: I am not using the cart or pay online just the CMS part of the component

webmonkiee

Was this ever fixed? Well, that's a silly question because I'm using the latest stable version and the problem still exists.

Is there a "working" solution to this?

287d

Thank you - this worked for me perfectly - tested live also.

Note to everyone that tries it - ensure file is saved with ANSI encoding!


Quote from: pollar on March 06, 2009, 02:09:56 AM
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):

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


3. Just after these lines add this code:

// 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:

// 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.





tubaad

The solution below can screw up other mods.
I chased a problem with the Acajoom newsletter subscriber module (It did not work at all) that was solved when removing this hack.
So, back to square one I guess.
Quote from: pollar on March 06, 2009, 02:09:56 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):

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


3. Just after these lines add this code:

// 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:

// 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.


rian

thank you pollar!! i tried so many things and finally you solved it! i didn't encounter any troubles so far.
i changed the php_self to request_uri in some files before. is this causing any problems with your hack and should i therefore revert this change?
thank you

Piszi

Hi.

I made a small modifaction in the ps_session.php and now I get the right item ids.

I made it becuse i have 2 different templates for 2 different categories but always when i clicked on a product the template changed back to the default.


This is my solution:

In ps_session.php go to line 463 and change the db SELECT to something else.
for example: $db->query( "SELECT category_id FROM #__vm_category WHERE category_publish=Y");

and than change the $db's value on line 465
for example: $db->f("category_id")

So it should look like this: function getShopItemid() {

if( empty( $_REQUEST['shopItemid'] )) {
$db = new ps_DB;
$db->query( "SELECT category_id FROM #__vm_category WHERE category_publish=Y");
if( $db->next_record() ) {
$_REQUEST['shopItemid'] = $db->f("category_id");
}
else {
if( !empty( $_REQUEST['Itemid'] )) {
$_REQUEST['shopItemid'] = intval( $_REQUEST['Itemid'] );
}
else {
$_REQUEST['shopItemid'] = 1;
}
}
}

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

}


I know this is not the right way but it works and until now i didn't managed any error.

You have to manage that I don't have any extra functions turned on in the VM temlpate config so i don't have fetured products, or recently viewed products on category pages.


pollar

Quote from: tubaad on September 30, 2009, 09:37:04 AM
The solution below can screw up other mods.
I chased a problem with the Acajoom newsletter subscriber module (It did not work at all) that was solved when removing this hack.
So, back to square one I guess.
Quote from: pollar on March 06, 2009, 02:09:56 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):

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


3. Just after these lines add this code:

// 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:

// 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.


Tubaad, I think I made a small misstake. Please try this code and tell me if it works for you.


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'];
}

'$uri->_query =' replaced to '$uri->_query .='

rian, I don't know if your modifications can be a problem. I run about 100 shops on virtuemart with this hack. No troubles so far too... :)

kakashi807

damnnn pollar I WANNA KISS you !! that worked perfectly thanks!!!

steveshore

I second, pollar definitely deserves some lip love!

Worked perfect!!!!

ctilley

Hey guys,

I have tried both of these solutions and I cannot get past the first step of the checkout process, it still just goes to a blank page.

I am using joomla 1.15 and the newest version of the vm component, any ideas why this still isn't working??

chetanmadaan


baggiesmad

The second method fixed it for me!!! Thanks Pollar!

I did have to disable SEF URL's and uninstall the "SEF Router for Virtuemart"

metamodguy

Hi all,

there's another discussion about another solution for this, over on http://forum.virtuemart.net/index.php?topic=65450.0

vannquish, I know your problem is already solved, but could you possibly try out the method on that page, and see if it works with SEF URLs and the SEF Router for Virtuemart?
Regards,
Stephen Brandon
MetaMod and MetaTemplate author

abhaykochar

I did a simple trick
Quote
if(JRequest::getCmd( 'view' ) == 'frontpage' AND JRequest::getCmd( 'option' ) != 'com_virtuemart')
This worked for me