News:

Looking for documentation? Take a look on our wiki

Main Menu

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

helenbn

jenkinhill, thank you for your post but I am not sure I understand. My default template is for everything, including VM, BUT my frontpage, that that one is the assigned one.
I use Virtue Mart 1.1.3 & Joomla 1.5.10

jenkinhill

helenbn - it worked for me but maybe the different templates I used don't have issues? Have not tried it again as I only use one template for my sites.
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

helenbn

so, what's the scuttle butt on Joomla getting this template assigning issue resolved?
I use Virtue Mart 1.1.3 & Joomla 1.5.10

unleash.it

Soeren or Gregdev, can we get any help with this? Can you confirm that the problem is on Joomla's end?

By the way to those who didn't understand my posts earlier. If you assign templates in the admin, every time you (or your client) adds a new page to the site, you'll have to also go to the template manager and manually assign the page to the right template. Not a big problem for a small site that you maintain, but its a drawback if you have clients adding pages.

While my "hack" won't automate the process, it should allow you to have multiple templates now if you need them. Since my previous posts were maybe a bit fuzzy... and I'm about to do this thing again so it's a refresher for me... here goes again. It's not hard, but it will take some basic Joomla template/HTML/PHP knowhow.

STEP 1: In the admin, publish a module to an unused module position like user9. Assign it to whatever pages you want to theme differently. This module doesn't have to actually appear on the front end unless you want it to. One module allows for two "templates". If you need a 3rd look, publish a 2nd module, etc. Important: Make sure you publish each module to a position not occupied by any other module.

STEP 2: Use php If statements in your template to query for the module(s). If the module is published, you are on the page or one of the pages that you assigned the module to.

Something like this could go in the <head>:

<php
   $mytpl=""
   if ($this->countModules('user9')) {$mytpl='template1';} //change user9 to the module position you assigned the module
?>


This checks to see if your module is published. If it is, that means we are on a page(s) that you published it to. Next, wherever you want to vary the template, throughout your html you'd do something like:

<?php if ($mytpl=="template1") { ?>
<!-- your html/modules for template1 -->
<?php } else {?>
   <!-- your html/modules for the alternate look -->
<?php } }?>


This code is set up for two different templates but you can modify it pretty easily to accommodate more. I've tested it in a couple of ways and it worked for me, but it may or may not distinguish the store properly. You might try assigning a module to all pages NOT the store and allowing the store to be the default.

Using this method, you would be doing your template switching using modules which is still manual. If there were only a variable within the Joomla framework to tell what category/component/frontpage we are on (and can be counted on), the process could be automated so no hack like this would be needed. Using the Joomla View DOES work when you're not using VM, which seems a bit strange (to me) that it's a Joomla problem...


breezy

I searched the joomla forum for this issue and I only found 1 post and it remains unresolved. http://forum.joomla.org/viewtopic.php?f=467&t=287369

Has anyone figured this out?  I am not strong in php or any scripting language for that matter but it seems that if there is a way to pass through the url the option and checkout step, the correct template would display.  Example, if you are on step 3, payment method, and you click the link under the second cart (to link back to step 2, shipping methods) the proper template appears.  To a non-programmer like myself it seems possible to pass the '&option=com_virtuemart&checkout_stage=' through the url and still hide all the private data.  Can someone tell me if this is even possible??  the link would be some variant of this for step 2 - shipping methods: https://yourdomain.com/index.php?page=checkout.index&option=com_virtuemart&checkout_stage=2

payment method would be the same only with '&checkout_stage=3', etc.

I am sure this is Joomla related, but I doubt it will be resolved anytime soon, just hoping for a workaround until its resolved completely.

unleash.it: I could not get your fix to work with my joomla/VM application.

helenbn

Hi breezy, I made one change so far to my VM coding and it has fixed the correct template to load when you update the cart. I am not sure if it breaks anything else, but I know that it doesn't fix the coupon application so it probably will need to be used in other pages of code.

What I did was this:

in yoursitejoomla/administrator/components/com_virtuemart/html/basket.php

I searched for the section about half way down:

/* UPDATE CART / DELETE FROM CART */
$action_url = $mm_action_url.basename($_SERVER['PHP_SELF']);


this part 'PHP_SELF' calls for what page loads. I replaced with this:

/* UPDATE CART / DELETE FROM CART */
$action_url = $mm_action_url.basename($_SERVER['REQUEST_URI']);


Notice the 'REQUEST_URI'.See this site for a brief but layman's explaination:

http://php.about.com/od/learnphp/qt/_SERVER_PHP.htm

Now I imagine that I will have to follow this through the checkout into different pages to make it flow. I am not that far along in the setup, but if you get to that, please post whatever other pages you find that are in need of this change.
I use Virtue Mart 1.1.3 & Joomla 1.5.10

jenkinhill

helenbd, that is a neat workaround. I am advised it will only work on Apache servers, though.

There is a code snippet seen elsewere that may enable REQUEST_URI to be used on Windows servers, but this would only be useful to those who use Joomla template switching.

http://api.drupal.org/?q=api/function/request_uri/HEAD
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

johnwasneverhere

i have made some of this work by using this in your frontpage template index.php
<?php if (JRequest::getVar('option') == 'com_virtuemart' ){?>


try like this....



<?php if (JRequest::getVar('option') == 'com_virtuemart' ){?>

  <div  id="main"><jdoc:include type="component" style="xhtml"/>



<?php else {?>


<div  id="bottom-2"><jdoc:include type="modules" name="bottom2_vj22" style="xhtml" />


<?php }?>


you could leave the div after the "else" blank to just have the component included... this will work if your frontpage template is not completely different from you main template and just requires a few different elements... like a header image... for ex ample...

<?php if (JRequest::getVar('option') == 'com_virtuemart' ){?>

<img src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/images/header2.jpg" alt="header" width="910" height="125">

<?php else {?>

<img src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/images/header.jpg" alt="header" width="910" height="346">

<?php }?>



hope this helps

unleash.it

Thanks jwnh... Definitely will give this a try when I have the chance. Have you tested it through checkout and in the account section? That's where 'view' conks out. Actually, if we can do this on any component, it opens up a whole world of automated templating.

On my first site, I only needed a couple variations so my code looked like yours, just do an IF statement when I needed a change. But what about the idea of just having two or more complete templates (one big PHP if statement), one after the other? Does anyone think that may cause a performance hit? I would imagine that the code only gets processed and sent to the browser when the IF is true?

tudor2004

Thanx helenbn. For the last two day i've been thinking how to fix that damn prob. i did like you said and it worked. You be blessed man!

helenbn

Ah, tudor2004. I may be blessed, but my VM sure is not. I found that there were other pages that were also loading the home page template so I gave up. Totally.... :'(

If anyone figures out which other pages need code changes and where, please post back here.
I use Virtue Mart 1.1.3 & Joomla 1.5.10

johk

helenbn,
Could you do a find and replace all ($_SERVER['PHP_SELF']); with ($_SERVER['REQUEST_URI']); or would that casue other problems futher down the track?
Cheers,
jonas

helenbn

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

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

I use Virtue Mart 1.1.3 & Joomla 1.5.10