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

johk

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

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:

<?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

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

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

johk

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

Just wondering if anyone found a solutions or a work-around that works?

Kai920

Quote from: unleash.it on August 01, 2008, 04:46:30 AM
<?php if (JRequest::getVar('option')=='com_content' && JRequest::getVar('view')=='frontpage') { ?>

the html

<?php ?>


THANK YOU... worked beautifully.  :D

robkristie

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

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

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.

mmtcbrick

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

radagast

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

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

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

pleaseeeee

rgibbs421

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.