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

helenbn

  • Beginner
  • *
  • Posts: 40
    • Pretty Good Designs | Hey, that's pretty good!
jonas,

Locally, I could do a find and replace. I am not real good at this, but when you unzip the component for VM locally, it doesn't build all the files. So something else must happen upon install. So I don't know how to do it on the server without downloading every dang file in the directory.  >:(

But if someone knows another way, I'm all ears.
I use Virtue Mart 1.1.3 & Joomla 1.5.10

johk

  • Jr. Member
  • **
  • Posts: 107
I don't know how to do the find and replace on the server - but I guess it is a good practise to have a local install of your site. You could download the whole site and set it up  locally for testing etc.
Thanks
Jonas

helenbn

  • Beginner
  • *
  • Posts: 40
    • Pretty Good Designs | Hey, that's pretty good!
In a perfect world...
I use Virtue Mart 1.1.3 & Joomla 1.5.10

johk

  • Jr. Member
  • **
  • Posts: 107
Does anyone know how it would affect VM if I would do a find and replace for ($_SERVER['PHP_SELF']); with ($_SERVER['REQUEST_URI']); in the core files?
Would it completely stuff everything up?
Cheers
J

unleash.it

  • Jr. Member
  • **
  • Posts: 150
For the few who are following this that prefer to code their separate templates (rather than use the switcher), I've tried johnwasneverhere's method. I've tested on a local site with no SSL, but it appears to work fine through checkout and in the account areas, etc.

JRequest::getVar('option') returns the name of the component. In other words, if you are on the front page, or any normal Joomla page... you will get 'com_content'. If you are on a VM page you will get 'com_virtuemart', etc.

By itself, this is good if your design changes are segregated to your Joomla site (style #1) and your shop (style #2). However, it won't discriminate your front page, or any other particular Joomla page/VM/whatever page unless it uses a different component. One work around that seems to work for me (I like templates that have a different front page than the rest of the site ;), is to go:

Code: [Select]
<?php if (JRequest::getVar('option')=='com_content' && JRequest::getVar('view')=='frontpage') { ?>

the html

<?php ?>

This combination seems to work and makes me pretty happy at least!

jonk: You should always try something drastic like that on a site that isn't live. With WAMP or XAMP, it's pretty easy to set up your own environment locally. If you get it to work, let us know. FYI, Dreamweaver has the ability to do a pretty good sitewide find/replace if you have it (it works on all PHP/HTML/XML files at least). If you make a backup before you do anything, you can easily restore if it fails.

johk

  • Jr. Member
  • **
  • Posts: 107
Hi,
I did a find an replace for for ($_SERVER['PHP_SELF']); with ($_SERVER['REQUEST_URI']);  but it didn't work for me. (The files changed were:basket.php savedbasket.php shop.savedcart.php )

I also tried the if statement but I must have done something wrong as it mess up the cart. When I press proceed (or next) the cart gets emptied. This works perfectlt on my localhost but when I uploaded the files it doens't work. Would it make a difference that  I have shared SSL ie my URL change from http://www.mysite.com to https://www.webserver.sharedssl/mysite ?
Thanks
jonas

unleash.it

  • Jr. Member
  • **
  • Posts: 150
Hi Jonas, my guess is it might be the your ssl setup in the VM configuration, or something with your host. Try https://www.webserver.sharedssl/mysite/. That ending slash does make a difference if it isn't there already.

Also, if you're trying the IF statement, did you remember to make one template the default for all pages in Joomla? I doubt you'd be getting the problem because of some If statements. If anything, you'd see visual problems (i.e. your template changes didn't happen or reverted) if it wasn't working.

Using my old technique at least, works fine on live sites with SSL (but haven't tried w/shared).

unleash.it

  • Jr. Member
  • **
  • Posts: 150
Well I just did a quick find for $_SERVER['PHP_SELF']. Just in /administrator/components/com_virtuemart there were 396 documents. Then there is /components/com_virtuemart...

I don't have time to give this a try, but if any one does...this would be a very simple way to get template switching to work. Could it also help advance native SEF in Virtuemart??? With the latest Joomla release 1.55, I'm beginning to really like the native SEF :)

johk

  • Jr. Member
  • **
  • Posts: 107
I have now tried this a bit more.
I did a find and replace for ($_SERVER['PHP_SELF']) with ($_SERVER['REQUEST_URI'])
When I did that at first my links from the categories to the flypage didn't work - when I clicked the link it only reloaded the page.
I went back changed back most of them to ($_SERVER['PHP_SELF']) . Please see below for files that I did change. The number with in the brackets indicates how many instance it was in that file. I have tried it with coupons and it works. My site is not "live" (but I tried on the live server) as the payment gateway is not set up but it works up to that point.

The only problem I have is when I am at the checkout process all my links has the "prefix" of the Shared SSL (https://......) rather that the normal http. I am not to sure how to fix that and I don't know if that is how it is or if that is due to the changes I did. Any feedback regarding this would be appreciated.

Front End:
checkout\get_shipping_address.tpl.php
common\couponField.tpl.pnp
pages\checkout.thankyou.tpl.php
Back End
classes\ps_checkout
html\basket.php (3)
html\checkout.index.php (1)
html\ro_basket.php (3)
html\savedbasket.php (3)
html\shop.savedcart (1)

Cheers,
jonas

MapleWeb

  • Beginner
  • *
  • Posts: 1
Re: JRequest::getVar('view') returns 'Frontpage' on VM pages and URL problems
« Reply #39 on: November 06, 2008, 03:06:56 am »
Just wondering if anyone found a solutions or a work-around that works?

Kai920

  • Beginner
  • *
  • Posts: 34
Re: JRequest::getVar('view') returns 'Frontpage' on VM pages and URL problems
« Reply #40 on: December 18, 2008, 12:23:33 pm »
Code: [Select]
<?php if (JRequest::getVar('option')=='com_content' && JRequest::getVar('view')=='frontpage') { ?>

the html

<?php ?>

THANK YOU... worked beautifully.  :D

robkristie

  • Beginner
  • *
  • Posts: 2
Re: JRequest::getVar('view') returns 'Frontpage' on VM pages and URL problems
« Reply #41 on: December 31, 2008, 12:29:11 pm »
On my localhost setup johk's solution seems to work fine.

to johk, are you referring to the links in menus?  If so, there is a setting in the menus through joomla that you can turn the SSL off for menu items, should fix your problem.

mkiehl

  • Beginner
  • *
  • Posts: 12
Re: JRequest::getVar('view') returns 'Frontpage' on VM pages and URL problems
« Reply #42 on: February 22, 2009, 20:19:35 pm »
In response to hellenbn (post 26) you will also have to alter checkout.index.php line 96 with the following
$basket_html .= '<form action="'. SECUREURL.basename($_SERVER['REQUEST_URI']) .'" method="post" name="adminForm">

:)

Mkiehl

pollar

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

mmtcbrick

  • Beginner
  • *
  • Posts: 3
Pollar,

This one worked great for me. Fixed everything in one shot! I've been searching for hours and did not want to make all of the changes to my template with if statements.

Thanks,
Brick