VirtueMart Forum

VirtueMart 1.1.x [ Old version - no longer supported ] => Questions VM 1.1 ( the only active board for the old version) => Topic started by: metamodguy on January 12, 2010, 06:35:35 am

Title: Switching Joomla template on different shopping pages or different users/langs
Post by: metamodguy on January 12, 2010, 06:35:35 am
I've just released a new component for Joomla that allows you to switch Joomla template based on things like component, user, language, domain name, GeoIP, etc.

The component is Chameleon, http://www.metamodpro.com/chameleon/chameleon

I want to add functionality for it to directly address VirtueMart issues. I figure that there are plenty of VirtueMart admins that would like to be able to switch the overall Joomla template on different VM pages, or for different shopper groups, or any other kind of thing.

So my question is: what sort of features would you like to have?
Under what circumstances would you love to be able to switch to a different template?
- front-end language?
- browser's language?
- domain/subdomain?
- browser type? (e.g. a completely different template for IE users)
- particular VM pages? (e.g. flypage, category listings, checkout, shipping, etc)
- previous history of a logged-in shopper (e.g. previous order history, or country etc) ?
- anything else?

I don't want to spend time building stuff that no-one wants to use, so your feedback will be valuable.


Chameleon comes in 2 flavours - Lite, where you have to code your own rules in PHP, and the full version that has lots of built-in rules like date/time, GeoIP, categories/sections, article id, user groups, user ids, browser type, etc.

Looking forward to feedback,
Stephen Brandon
www.metamodpro.com
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: jenkinhill on January 13, 2010, 10:47:16 am
I can already see a use for this by VirtueMart users. When different templates are used for the "home" page and the main site at the point of checkout in VM the template switches back from main site to home. Although there is a fix for this happening on Joomla 1.5 this is not ideal( http://forum.virtuemart.net/index.php?topic=34989.0 )

I will have to try it out - although I don't usually switch site templates.
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: metamodguy on January 13, 2010, 10:52:39 am
Right, I heard about that issue. I'll take a look and see what recipe could be appropriate. Thanks for the feedback. It's probably going to be easy to code.
Title: Re: Switching Joomla template on different shopping pages or different users/lan
Post by: metamodguy on January 14, 2010, 01:18:58 am
OK, before I build this in to the extension (perhaps as a global preference?), can I get some people to test this out and report back?

Instructions:

1 - download and install ChameleonLite from http://www.metamodpro.com/chameleon/download
2 - create a new Chameleon rule and give it a name
3 - paste the following into the main PHP box, and save it
4 - test out the VM page that was jumping back to the old template. Is this behaviour fixed now?

Code: [Select]
$method = strtolower($_SERVER['REQUEST_METHOD']);
$uri = JURI::getInstance();

if ($method == "post" && substr($uri->_uri,-10) == '/index.php'
 && @$_POST['option'] != '') {
  $newuri = $uri->_uri . '?option='
   .  htmlentities(@$_POST['option'],ENT_QUOTES,'UTF-8')
   . '&Itemid='
   . htmlentities(@$_POST['Itemid'],ENT_QUOTES,'UTF-8');
   $uri->parse($newuri);
}

This works for me on my test site.

On my setup, VM is attached to a menu item so it would be good for someone to test when VM is *not* on a menu item.

I've tested it with built-in SEF both on and off and it's fine with both. It would be good to test with other SEF extensions as well.

Hope this helps other people... this is a good solution in the sense that it does not require hacking any core files, and *should* also fix up any other components that do post requests to plain old "index.php". It's also "sticky" in that any other part of the system that calls JURI::getInstance() will pick up the "fixed" version of the URL and variables.

Once I have some more feedback from people testing it under different conditions I'll put it into the free version of Chameleon as an option.
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: baggiesmad on January 14, 2010, 22:55:17 pm
ill give this a go over the weekend. thanks
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: Eden on January 16, 2010, 12:11:08 pm
I have tested this and found it also to be working on my virtuemart to some degree, i have a rather unique case where i need multiple templates (4) and am willing to do whatever testing needed to help out with the increased production of this component.

While this is working with 2 templates i am actually running 4 differnt templates:

Basically the first template is a landing page, which links to four other templates (for a business running a conglomerate of similar themed business's.)

each of these has products and sales in it, if i use this code it removes the possibility to use some templates.

Im sure there must be some way to do this after reading this thread and other threads i can see the solutions for this have come some way now, i would rather not hack the joomla  core or the vm core and love the idea of this component being the solution. My coding is very poor and if someone could give me a hand with this it would be most apprecaited. Willing to do whatever needed to get this up and running! you can email me at edenb83AThotmail.com if you need a direct line add that to msn.

THanks guys love your work!
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: metamodguy on January 16, 2010, 19:56:39 pm
Hi Edzz83,

Can you be a bit more specific about how you want the different templates applied to your site?

e.g.
- do you have 4 different menu items pointing to the 4 different shops, and you want a different template for each?
- or do you want a different template for each "category" of products in the single shop?

I guess I don't understand the sentence "the first template is a landing page, which links to four other templates (for a business running a conglomerate of similar themed business's.)".

Also I don't get what you mean by "if i use this code it removes the possibility to use some templates". Chameleon (formerly MetaTemplate) will give you all sorts of options for your site - if you can describe what you're after it's likely that you can set it up with Chameleon.

Cheers,
Stephen
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: Eden on January 17, 2010, 00:57:28 am
Thanks for your prompt reply. Im sure there is someway to do this im still trying to wrap my head around metatemplate. Let me explain the my setup a bit more precisely.

Joomla has 4 templates in total installed and one installation of Virtuemart, with 2 seperate menus setup.

The first default template is linked to its own menu with just one default item in it, this is the first page you see when you goto the site, basically this is just a blank template. It shows a single article which links to 3 other menu items in the second menu.

Each of those links and their child items are assigned their own template, giving the illusion of 3 seperate sites. Each on of these menu items has a child which is linked to its own category in the shop, which when clicked on show the sub categories for that specific item. Below is a basic menu tree.


         { EA ENERGY     --> Products
EA GROUP { EA WATER      --> Products
         { EA CONSTRUCTION  --> Products

when i goto for instance ea energy, and then products and try to view one of the sub categories, the content appears in the ea water template.

when i applied your fix (i probably went the wrong way about doing it im not sure) but i found that the landing (ea group) would no longer show, and it would come up with the ea energy first up but the categorys would view fine and you could goto water and view its category fine also.

Please check your PM as i will provide you with a login for further clarification. Its one of those , hard to explain things ;)
Title: Re: Switching Joomla template on different shopping pages or different users/lan
Post by: metamodguy on January 17, 2010, 03:37:55 am
Thanks for the details and more explanation, will take a look at that in the next 24 hours.
Cheers,
Stephen
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: Eden on January 17, 2010, 09:09:17 am
Thanks mate, your help is much appreciated!
Title: Re: Switching Joomla template on different shopping pages or different users/lan
Post by: metamodguy on January 17, 2010, 23:52:49 pm
Found a bug in VM that was part of the cause of one of the problems on that site:

http://forum.virtuemart.net/index.php?topic=65719.msg217326

This is to do with inconsistent Itemids, when you have more than one menu link to the VM component.
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: Eden on January 18, 2010, 02:40:02 am
Your a genius ;) been racking my brain over this one for some time!!! sooo much appreciated. Still have further testing to go now hopefully it holds the template through the shopping process also as i hear others have issues with this too.

Cheers for the help!
Title: Re: Switching Joomla template on different shopping pages or different users/lan
Post by: metamodguy on January 18, 2010, 02:56:23 am
So far we're dealing with 2 different issues with respect to "holding the template through the shopping process".

The first one is regarding what happens to the template when you submit a form in the shopping cart, and when you have allocated a specific template to the front page. This is the one addressed with Chameleon plus the snippet of code earlier in this thread. I'm still hoping to hear back from anyone who has tried this out and can confirm that it solves this problem on their site.

The second one is what I wrote about on http://forum.virtuemart.net/index.php?topic=65719.msg217326 which is concerned with wrong itemids, when you have a direct menu link to a particular category, then that category has links to subcategories. The subcategory links end up with the wrong Itemid, unless you use the fix in that post.

Happy to help :)
Stephen
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: Eden on January 18, 2010, 04:01:48 am
I am close to product cart testing just finishing up a few visual template tweaks then onto virtuemart stuff tonight, as i have not addressed the first issue yet, i would assume that it will still be apparent on my site, could you provide any clarification on how to implement your solution in my multi-template environment (eg the settings for metatemplate if anything is different for my setup) Im more than happy to do any testing and give feedback :-)

 Especially after all the help you've given!!!
Title: Re: Switching Joomla template on different shopping pages or different users/lan
Post by: metamodguy on January 18, 2010, 04:08:11 am
Hi Edzz,

the first problem (with POST requests in the shopping cart) should be able to be fixed with Chameleon and the tweak above, even (or especially) in multi-template environments.

If you're having trouble with that (i.e. you try it with MetaTemplate and it stuffs things up, then you turn off Chameleon and it comes back to normal again), then please let me know! I need some more feedback on that!

Cheers,
Stephen
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: silentBob on January 28, 2010, 13:50:59 pm
can i use this: MetaTemplate 1.0 (http://www.metamodpro.com/software/metatemplate/download)
to use Template1 for VM-Category-Example1
and
use Template2 for VM-Category-Example2

did i understand it right?
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: metamodguy on February 03, 2010, 12:11:42 pm
Hi Bob,

yes, you should be able to do that with a modification of the rules found on http://www.metamodpro.com/support/recipes/36-component-specific/76-control-modules-on-virtuemart-pages

The rules on there are for MetaMod (rather than MetaTemplate), but all you have to do to change them is to change lines like this:

return 101;

to this:

return true;

... then use MetaTemplate in the normal way.

Hope that helps get you started,
Stephen
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: metamodguy on February 03, 2010, 12:20:34 pm
MetaTemplate 1.2 is now out, which has a built-in fix for the Front-Page Template bug in VirtueMart, mentioned earlier in the thread.

All you have to do to use it is this:
- download MetaTemplate 1.2 from http://www.metamodpro.com/software/metatemplate/download/category/47 and install it
- that's it. The "front page fix" is enabled by default.

If you want to disable the fix, e.g. for testing, you can do the following:
- go to Components->MetaTemplate in the Joomla admin menu
- click on the Parameters icon (top right of window)
- turn the fix on or off with the selector
- click on "save" in the Parameters window.

MetaTemplate also has a new feature that allows you to duplicate any installed template, in 1 click. This makes it easy to make a copy of any template that's already installed, then use that copy (with any modifications you want to make) just for selected pages. More about that on the download page.
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: Eden on February 03, 2010, 23:58:18 pm
Sweet with the new version will upgrade now!

Im getting another issue although i think it may be with a third party mod, maybe you can share some light. My site now has a product scroller on it. When clicking on a particular product it always opens in the first template no matter what template your on... weird! Any ideas ?? If you like you can login and take a look (i p'md u a little bit ago)

As with testing shopping seems my client for the moment is only interested in a product catalogue so wont be able to test that til later.
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: Eden on February 04, 2010, 00:38:55 am
Found a fix for my above post, seems it was once again grabbing the path incorrectly from virtue mart and reverting the default template again... I found a fix though for anyone else that comes across this issue.

Most third party mods will grab paths from the virtuemart paser, when i installed the SEF friendly urls router from http://joomlaplugins.net/joomla-extension-download/cat_view/34-virtuemart-specific-extension.html, and followed the easy instructions, joomla and virtuemart seem to have a better understanding of the correct template to use now :).

Another template issue resolved :) (this fix may be a compliation of all the fixes i have now added all of which can be found in this thread, including one core hack and metatemplate install)
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: Eden on February 04, 2010, 02:10:28 am
 :o

ok hit yet another snag, product scroller (modified version from here http://forum.virtuemart.net/index.php?topic=57659.msg195029)

This is a very weird anomaly now.

If i goto my landing page, and through to ea energy (the second template in my group of four), the products on the scroller will correctly view in the energy template, if i do to ea-water, view a product, then go back to ea energy again, the links in the scroller have changed now to the ea water template, and products now view in there!

I cannot comprehend how this works ... maybe cookie related somehow ? im not quite sure, maybe you could shed some light on it ?? Weird that it works but if u travel around and come back it breakss again.
Title: Can VM Store always return to default template
Post by: scottiedb on February 09, 2010, 18:33:40 pm
I have a Virtuemart store plugged into a Joomla 1.5 site using 3 different templates. I want the ability for the store to ALWAYS return to the default template when viewing any page in the store. Currently, the VM store shows up surrounded by whatever template you were in before you clicked on store related content. It feels like there is an easy way to do this, but I'm just not seeing it. I have MetaTemplate component installed, but I'm not really good with coding, can anyone help? Thanks!
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: metamodguy on February 09, 2010, 19:08:59 pm
Well, you can generally achieve this without MetaTemplate. All you would need to do is ensure that there's a menu link to the VM component, then you would assign the desired template to that menu item in Joomla's Template Manager.

The advantage in MetaTemplate, if you want to use it, is that it does not require you to assign VM to a menu item. You can also be more specific about exactly which pages inside VM you want styled.

MetaTemplate Pro: just use the Components selector box on one of the rules, and choose VirtueMart from the box.

MetaTemplate: in the PHP box, use the following rule:

if ($option == "com_virtuemart") return true;
else return false;

For both the Pro and free version, you then do this:
- in the Actions section of the rule, use the drop-down to select the desired template for SUCCESS.

Hope that helps,
Stephen
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: scottiedb on February 09, 2010, 19:48:45 pm
Wow. It worked, that is exactly what I was looking for! Thanks Stephen!! I greatly appreciate this!
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: metamodguy on February 09, 2010, 19:55:48 pm
Using the standard Joomla Template Manager, or MetaTemplate?
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: scottiedb on February 10, 2010, 01:16:31 am
I used the tidbit line of code you gave me, used it in MetaTemplate, I didn't insert VM in a menu because I have a module that is always on the left side, and I wanted the store module to be seen on every page. So I figured it was useless to have a link to something that everyone can always see. Thanks again!
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: metamodguy on February 10, 2010, 01:26:48 am
Great, glad it worked :)
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: Forrest on April 03, 2010, 19:33:24 pm
Excellent way around this J! issue, thanks metamodguy.
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: gok on April 26, 2010, 12:27:44 pm
Hi everyone,

This is a must extension for virtuemart...
But I need something rather easy, I just want to change site background for each category and relevant product pages, What is the best way to achieve this...

Thanks before hand...
Title: Re: Switching Joomla template on different shopping pages or different users/langs
Post by: Archy on May 13, 2010, 13:06:57 pm
Could some post a simple step by step on here as im a novice to PHP.

Posting a link is very nice but how to would it would be even better!!!

How come there isnt a simple way to do this in the component? Maybe they should be looking to this for the next update!!