Sie sind auf Seite 1von 8

Register / Login 1149 users online Home Features Features Blog Live Shops Roadmap Demo Download Documentation

Documentation Screencasts Support General Support Community Forums Bug Tracker Contact Us Extensions Partners

Community Forums
Board index General FAQ & Tutorials Themes Change font size Print view Search FAQ Register Login

[Tutorial] Build Opencart Theme


Post a reply

2 posts Page 1 of 1

[Tutorial] Build Opencart Theme


by qahar Fri Jul 22, 2011 9:16 am Opencart use fallback function, it's mean that when opencart doesn't found certain template in your theme, it will find on default theme folder. So to make a new theme, you doesn't need to copy all file from default theme. But, building a theme not just about make new folder theme and change it color. In this tutorial we will learn basic understanding on how controller and model work, it's related to template modification. Before we continue, I want to make it clear that theme in this tutorial is refer to the theme inside theme folder (catalog/view/theme/mytheme) and template refer to .tpl file inside the template folder (catalog/view/theme/yourtheme/template).

Step 1. Build "Very" Basic Theme


1. Create new folder mytheme on catalog/view/theme/, the folder tree will be like this: catalog/view/theme/ |-> default |-> mytheme 2. Now go to Admin -> System -> Setting - > Edit Store ->Tab Store -> template -> mytheme. Refresh your frontpage. Maybe your site litle bit mess, but your new theme is work!!

Step 2. Basic Theme


1. Make folder and copy some files from default theme, but DO NOT copy all files. Follow this folder tree:

catalog/view/theme/ |-> default |-> mytheme |-> image/*.* - copy all image |-> stylesheet/*.* - copy all stylesheet |-> template |-> common |-> header.tpl
i. ii. iii. iv. Note: We need to copy all the images because it's required by stylesheet.css. We need to copy IE stylesheet since it's declared on header.tpl (remove the file when you removing the IE style at header.tpl) We neet to copy slideshow.css and carousel.css since it's needed by opencart module. Rating star image is hard-coded into Page: category, manufacturer_info, product, review, search, special; Module: bestseller, featured, latest, special. It's up to you whether including those module and page to your theme and used another rating image, or just replacing use default rating star image.

2. 3. 4. 5.

Now open header.tpl with text editor. Search word default and replace with mytheme Refresh your frontpage, and everything should be the same as when you used the default theme. To get different visual like changing color etc, you can modificate mytheme/stylesheet/stylesheet.css

Step 3. Customizing Template (1): Understanding Controller


1. What template (*.tpl) is need to customize for a "good theme" ? Well, the answer is relative. In step 2 we already and only customizing the header.tpl. The most important rule to remember is never edit default theme template. Copy what you need to your theme folder, see example bellow. catalog/view/theme/ |-> default |-> mytheme |-> image |-> stylesheet |-> template |-> common |-> header.tpl |-> footer.tpl |-> information |-> information.tpl |-> product |-> product.tpl |-> category.tpl

|-> manufacturer_list.tpl 2. To customizing template and work with the controller, you need to understand that opencart used push-based MVC model -CMIIW. In quick explanation: a. When you accessing route=product/category url, opencart call controller/product/category.php file. b. This controller (ex. category.php) will decide which MV-L: Model, View (tpl), language will be load. In category controller (category.php) load: i. 3 Model (category, product, image): $this->load->model('...'); ii. 2 View (category.tpl & not_found.tpl): $this->template = '...'; iii. 1 Language: $this->language->load('...') c. The controller also decide what data will be pushed into template and how user input will be processed. i. $this->$this->data['text_price'] = $this->language->get('text_price'); will produce Price in template: <?php echo text_price; ?> ii. When you change the product show (from 15 to 25) at frontpage, controller catch the request with if (isset($this->request->get['limit'])) { ... } then process it $this->data['limits'][] = array(... 'value' => 25, ...); 3. Remember that there is no fallback function for controller. If you modificate the controller file manually, it will be replaced when you upgrade the opencart. Instead modificate it manually, you can used vQmod to make "virtual modification". We will talk this on step 5.

Step 4. Customizing Template (2): Understanding Model


1. A Model in MVC in charge to pull and push data to database. Before controller get or post a data through model, the spesific model need to be loaded. a. load model: $this->load->model('catalog/product'); b. get data: $this->model_catalog_product->getTotalProducts() c. post data: $this->model_catalog_product->editProduct() 2. $this->load->model('catalog/product') tell the opencart to load model/catalog/product.php either in admin or catalog controller. getTotalProducts(), editProduct() is a function inside the model/catalog/product.php. 3. Now open model/catalog/product.php and find public function getProduct. a. See list after return array, and you will found all product data. b. The question is, if the getProduct() listed all product data, why it doesn't show at category page (frontpage)? This because the category controller decide not to show all data. c. Open controller/product/category.php, find $this->data['products'][] = array to see what product data is used by controller.

Step 5. Customizing Template (3): Understanding vQmod


1. vQmod is a virtual modificate and usually used to make some change to non-fallback file like controller and model without modificating the default file. 2. You can download latest version and read further explanation about vQmod here. 3. To install vQmod, copy vqmod folder inside the package to opencart root. yoursite

|-> admin |-> catalog |-> download |-> image |-> system |-> vqmod 4. Go to your browser and access: http://localhost/yoursite/vqmod/install. You will see success message: vQmod has been installed on your system! 5. On the vQmod package, you will see folder docs and example to give you a refference how vQmod work. Here I will give you some quick refference: a. vQmod File is an .xml file stored at vqmod/xml folder. When executed, the vQmod force opencart to use the modification instead the default file (original file) and produce cache file at vqmod/vqcache. b. One vQmod File able to modificate multiple file; within one file, vQmod able to do multiple modificate operation. c. Example structure inside a vQmod File: <modification> <id>vQmod File ID</id> <version>1.0.0</version> --> vQmod File version <vqmver>1.0.8</vqmver> --> minimum vQmod version to work <author>your name</author> <file name="catalog/controller/product/category.php "> --> the file to modify <operation> <search position="replace"><![CDATA[ search this code and replace it with code bellow ]]></search> <add><![CDATA[ add this new code to replace code above ]]></add> </operation> <operation> <search position="after"><![CDATA[ search this code and add code bellow after it ]]></search> <add><![CDATA[ add this new code after code searched above ]]></add> </operation> </file> <file name="..."> <operation>

<search position="before"><![CDATA[ search this code and add code bellow before it ]]></search> <add><![CDATA[ add this new code before code searched above ]]></add> </operation> </file> </modification> My product: Opencart Blog Manager First Things First: Opencart Check List - Tips for Requesting Support - Tutorials Collection for 1.5.x Don't forget to add [SOLVED] to your Thread Title (first post), if your issue is solved.

qahar Posts: 1336 Joined: Tue Jun 29, 2010 2:24 pm Location: Indonesia Website Top

Re: [Tutorial] Build Opencart Theme


by qahar Thu Mar 01, 2012 10:09 am

How to use include, require, include_once or require_once that support vQmod? If you use something like this on your theme: Code: Select all
include 'bla_bla.tpl';

vQmod will unable to modificate your included file. To make vQmod able modify the file, you should use the full path. Qphoria on this post suggest to use $vqmod->modCheck(): Example: Code: Select all
include('catalog/view/theme/<themename>/template/product/bla_bla.tpl');

Instead use: Code: Select all


include($vqmod->modCheck('catalog/view/theme/<themename>/template/product/product_options.tpl'));

My product: Opencart Blog Manager First Things First: Opencart Check List - Tips for Requesting Support - Tutorials Collection for 1.5.x Don't forget to add [SOLVED] to your Thread Title (first post), if your issue is solved.

qahar Posts: 1336 Joined: Tue Jun 29, 2010 2:24 pm Location: Indonesia Website

Top Display posts from previous: Post a reply 2 posts Page 1 of 1 Return to Themes Jump to: Sort by

Who is online
Users browsing this forum: No registered users and 5 guests Board index The team Delete all board cookies All times are UTC Powered by phpBB 2000, 2002, 2005, 2007 phpBB Group Copyright 2010 OpenCart - All rights reserved Home | Features | Demo | Download | Support | Extensions | Partners
Hosted by Arvixe Web Hosting.

Das könnte Ihnen auch gefallen