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

radagast

  • Beginner
  • *
  • Posts: 12
mkiehl:
Those single line changes in basket.php and checkout.index.php fixed it for me. 
J1.5.10, VM1.1.3, Apache.

The problem existed with and without the global SEF URLs, and it's fixed with and without them too (a lot of other threads suggest the problem is due to SEF stuff)

I suspect Pollar has the more correct solution - as already noted, REQUEST_URI won't work on IIS, and i've got a feeling it might cause trouble if you're using SSL.  but for an easy fix that doesn't modify the J! core, i'm pretty happy.

thanks!
[a couple of edits for completeness]

ehermouet

  • Beginner
  • *
  • Posts: 8
thank you pollar it s work good with step2 but when you trie to add product in cart it's not work. i am redirected in my home page  :-[ . if you have an idea thank you.

ehermouet

  • Beginner
  • *
  • Posts: 8
Ok it's work with john methode but when we can confirm order there is blank page do you have an idea ?

pleaseeeee

rgibbs421

  • Beginner
  • *
  • Posts: 32
Okay, this was the closest forum that I found to help me solve my problem so I will add my solution too. I was wanting to use two templates one for the front page one for the rest. Every time i tried to access the store it would send me to the front page template which was just flash... After researching i started digging into the code..
in the ps_session.php file located in administrator/components/com_vertuemart/classes i changed the line 503

"$Itemid = "&Itemid=".$this->getShopItemid();"
 to
"$Itemid = "&Itemid=1".$this->getShopItemid();"

This changes the item id to have an extra one in it which cause joomla to think that it is not the front page... I am not sure how good of a fix this is yet since i will only be using about half of the stores ability.

rgibbs421

  • Beginner
  • *
  • Posts: 32
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

  • Beginner
  • *
  • Posts: 18
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

  • Beginner
  • *
  • Posts: 45
Thank you - this worked for me perfectly - tested live also.

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


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.




tubaad

  • Beginner
  • *
  • Posts: 14
Brilliant Pollar!!

tubaad

  • Beginner
  • *
  • Posts: 14
Re: JRequest::getVar('view') returns 'Frontpage' on VM pages and URL problems
« Reply #53 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.
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.


rian

  • Beginner
  • *
  • Posts: 15
Re: JRequest::getVar('view') returns 'Frontpage' on VM pages and URL problems
« Reply #54 on: September 30, 2009, 09:56:43 am »
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

  • Jr. Member
  • **
  • Posts: 58
Re: JRequest::getVar('view') returns 'Frontpage' on VM pages and URL problems
« Reply #55 on: October 01, 2009, 04:09:25 am »
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:
Code: [Select]
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

  • Beginner
  • *
  • Posts: 3
Re: JRequest::getVar('view') returns 'Frontpage' on VM pages and URL problems
« Reply #56 on: October 19, 2009, 23:54:32 pm »
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.
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.


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

Code: [Select]
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

  • Jr. Member
  • **
  • Posts: 52
Re: JRequest::getVar('view') returns 'Frontpage' on VM pages and URL problems
« Reply #57 on: November 27, 2009, 04:51:48 am »
damnnn pollar I WANNA KISS you !! that worked perfectly thanks!!!

steveshore

  • Beginner
  • *
  • Posts: 7
Re: JRequest::getVar('view') returns 'Frontpage' on VM pages and URL problems
« Reply #58 on: December 02, 2009, 00:13:17 am »
I second, pollar definitely deserves some lip love!

Worked perfect!!!!

ctilley

  • Beginner
  • *
  • Posts: 3
Re: JRequest::getVar('view') returns 'Frontpage' on VM pages and URL problems
« Reply #59 on: December 10, 2009, 23:43:58 pm »
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??