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.
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!
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
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" />
Code: Select all
<link rel="stylesheet" type="text/css" href="catalog/template/<?php echo $config_template; ?>/css/account.css" />
Bruce
Attachments
[The extension has been deactivated and can no longer be displayed.]
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.
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!
Code: Select all
<img src="catalog/template/default/image/stars_<?php echo $rating . '.png'; ?>" alt="<?php echo $text_out_of; ?>" class="png" />
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" />
Regards, Fido-X.
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!
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.
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!
Just to twist your mind a little more...
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
Regards, Fido-X.
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!
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'));
Code: Select all
if (!$template_cookie) {
return new Template($config->get('config_template'));
} else {
return new Template($template_cookie);
}
Regards, Fido-X.
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!
Users browsing this forum: No registered users and 31 guests