Post by fido-x » Mon Jul 28, 2008 12:15 am

First of all, I would like to congratulate troyveluz for the template switcher he has at his site (http://www.veluzarwebdesign.com/octplt/). His use of a javascript function is a far better way to preview template designs than my own method, and I take my hat off to him.

My own method of template switching makes the change by writing back to the settings table in the database using the same method as that used in the administration. This makes a global change for all viewers of the site, while Troy's javascript method is local to the individual viewer, which ultimately makes his method superior to my own.

But, there are always two sides to everything, and that is how I was approaching the issue of a template selector. By that, I mean that I was approaching it from two different directions at the same time - from the store side and from the customer side.

My demostore at http://www.fido-x.net/demostore/ now has two template selectors. The first is in the column, allowing you to change the store template for the purpose of previewing functionality, look and feel, etc. The second template selector is located in the customer's account, allowing the customer to change the template independent of the store template.

Try it out. A dummy account has been created for the purpose. Details can be found at http://www.fido-x.net/demostore/.

Regards, Fido-X.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by troyveluz » Tue Jul 29, 2008 7:20 am

Fido-X,
First of all, thanks for the compliment.
Although my method of changing templates works (some what)the method has some drawbacks and  I am still trying to figure out how to handle them.  Since Opencart has several stylesheets, only the main (default) stylesheet is changed.  It is still sharing the page specific stylesheets.  Maybe you can give me some suggestions on how to handle this problem.  Here's a short description of how I have implemented my theme selector.  I have a "main" stylesheet for each theme that is located in the same location as the "default" stylesheet.  I added PHP code on layout.tpl to capture the style being passed by the dropdown box and adding a cookie to the users browser (cookies also don't work if the user has turned it off).
So, I'm thinking of a way to have a "global/session" variable that I can set for each user session so I can pass this value to the  different pages to locate the correct "page stylesheet" or better yet, the correct template directory.  I still learning PHP although I have been programming for over 20 years concentrating on Microsoft/Windows based software, so I am able to understand some of the PHP stuff.

By the way, I moved my demo store to http://www.VeluzarWebDesign.com/ocdemo

Regards,
Troy

==========================================================================
Veluzar Studios
Web Design and Development


New member

Posts

Joined
Thu Jul 17, 2008 1:45 am
Location - Frisco, TX USA

Post by bruce » Tue Jul 29, 2008 9:39 am

Hi troyveluz, fido-x

The way to do what you want is to...

1) Replace your library\template\template.php with the attached file. The code comments speak for themselves in explaining how this works and there are some other handy tricks there too. If you have questions, feel free to ask.

2) In ALL of your .tpl files, replace the text "/template/default/" with "/template//" so that, for example...

Code: Select all

	<link rel="stylesheet" type="text/css" href="catalog/template/default/css/account.css" />
becomes...

Code: Select all

	<link rel="stylesheet" type="text/css" href="catalog/template/<?php echo $config_template; ?>/css/account.css" />
Now you have a system of switching that affects all users. You can easily extend the concept to use a session variable and make library\template\template.php aware of it.

Bruce

Attachments

[The extension has been deactivated and can no longer be displayed.]


Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by fido-x » Tue Jul 29, 2008 11:08 am

Thanks Bruce,

I can see why you have "hero" status. This should to the job quite well. I'll give it a try later on today.

Regards, Fido-X.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by fido-x » Tue Jul 29, 2008 12:05 pm

Further to Bruce's changes, you should also change the path to the "stars" images in "catalog/template/default/content/review.tpl" and "catalog/template/default/content/review_info.tpl" from:

Code: Select all

<img src="catalog/template/default/image/stars_<?php echo $rating . '.png'; ?>" alt="<?php echo $text_out_of; ?>" class="png" />
to

Code: Select all

<img src="catalog/template/<?php echo $config_template; ?>/image/stars_<?php echo $rating . '.png'; ?>" alt="<?php echo $text_out_of; ?>" class="png" />
Make the same change to "catalog/template/default/module/review.tpl", then make similar changes to "catalog/template/default/module/language.tpl" and "catalog/template/default/module/footer.tpl" for the flag and credit card images.

Regards, Fido-X.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by fido-x » Sun Aug 03, 2008 8:04 pm

I thought I'd make a follow-up on what I achieved (or didn't achieve).

Bruce's contribution was of enormous help in getting a javascript method for changing the templates working. But I was finding a few problems in the way it interacted with (or should I say "interfered with") the "active state" links in my templates. I also found problems when changing from a 2 column layout to a 3 column layout. However, these problems are more likely to have been the result of my own poor javascripting skills and would probably not be an insurmountable problem for someone more knowledgeable than myself.

I also found, during my testing, that it had a minor effect on my own template switcher, which (although it still worked) was no longer showing the current template as the selected template in the list, it was merely showing them in alphabetical order. This was easily fixed by changing a variable name in the controller. It also made me have another look at my own method, which gave me an opportunity to refine my own method to make it a bit more efficient - something I might not otherwise have done.

In the end, I have decided to stick with my own method, which (thanks to Bruce's making me have another look at) works even better than it did before (not that you'd notice from the front-end).

Regards, Fido-X.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by bruce » Sun Aug 03, 2008 8:22 pm

Hi fido-x,

Just to twist your mind a little more...  :D

You could make your template selector submit to a controller that changes the session value containing the template folder name and then redirect back to the original page.

The changes I made to the currency and language modules (posted somewhere on the forums) demonstrate this technique by changing the language and then redirecting to the current page. I plan to do it this way myself... eventually.

cheers

Bruce

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by fido-x » Sun Aug 03, 2008 8:50 pm

Ummm. ???  I think that's a fair bit beyond me, but thanks anyway (I think) ;)

Regards, Fido-X.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by bruce » Sun Aug 03, 2008 9:11 pm

It is easier to do than to describe. What you need is all shown in my forum post here

Make the changes to router.php and then copy the currency selector to make a template selector.

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by fido-x » Sun Aug 03, 2008 11:13 pm

It wasn't so much an issue of returning to the same page after changing the template with a javascript function, but more of following a link to another page, eg. a category or information page, where it would revert back to the template from the settings table. Since "index.php" gets reloaded with a "?controller=whatever" added to it, and "index.php" uses the locator to load (or create) the template, the change made by the javascript was getting wiped out.

I think a change to the "createTemplate" function in the "library/locator.php" file, where it reads:

Code: Select all

return new Template($config->get('config_template'));
and replace it with something like:

Code: Select all

if (!$template_cookie) {
  return new Template($config->get('config_template'));
} else {
  return new Template($template_cookie);
}
should get something working properly.

Regards, Fido-X.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia
Who is online

Users browsing this forum: No registered users and 31 guests