Adding Positions to OpenCart 1.5.1.1 Theme
Jamie Taylor
August 24, 2011
What you should know:
- I should start by saying that I am by no means an OpenCart expert. In fact, This is on my third day every using OpenCart. As such, I have no idea if this works with 1.5.1 or older versions of the platform.
- The changes in this tutorial are made to files that might be overwritten with upgrades or make future updates more difficult. You may be able to include all catalog files into your custom theme folder, however... I have not tested this theory.
- This is a relatively exhaustive process that much be done to every module for every new position you wish to add. (though it gets easier once you get the hang of it).
- This tutorial only adds positioning to the "Home" layout. I would assume to add it to other layouts you would just need to edit the corresponding template files (below) but there I go assuming again.
Getting Started:
I started by downloading and installing Hildebrando's Free Youtube Video module for OpenCart v1.5.1.1. I chose this mod mainly because it was highly rated and didn't involve too much back-end functionality. I assume you could modify any module similarly, however we all know that they say about assumption. If you're unsure I would get the feel of HildeBrando's version first so as not to waste your time.Adding Positions in Admin:
First, you need to open the module's language file located in; /admin/language/english/module/ and add your new position. For this tutorial we're going to be adding a new position called: Content Middle.
01
| $_ [ 'text_content_middle' ] = 'Content Middle' ; |
<?php if ( $module [ 'position' ] == 'content_middle' ) { ?> <option value= "content_middle" selected= "selected" ><?php echo $text_content_middle ; ?></option> <?php } else { ?> <option value= "content_middle" ><?php echo $text_content_middle ; ?></option> <?php } ?> |
01
| html += ' <option value="content_middle"><?php echo $text_content_middle; ?></option>' ; |
01
| $this ->data[ 'text_content_middle' ] = $this ->language->get( 'text_content_middle' ); |
Adding Positions to Your Template:
First, you must add the position to the array located in; /catalog/controller/common/home.php around line 20.
01
| 'common/content_middle' , |
<?php class ControllerCommonHomeOne extends Controller { public function index() { $this ->load->model( 'design/layout' ); $this ->load->model( 'catalog/category' ); $this ->load->model( 'catalog/product' ); $this ->load->model( 'catalog/information' ); if (isset( $this ->request->get[ 'route' ])) { $route = $this ->request->get[ 'route' ]; } else { $route = 'common/home' ; } $layout_id = 0; if ( substr ( $route , 0, 16) == 'product/category' && isset( $this ->request->get[ 'path' ])) { $path = explode ( '_' , (string) $this ->request->get[ 'path' ]); $layout_id = $this ->model_catalog_category->getCategoryLayoutId( end ( $path )); } if ( substr ( $route , 0, 15) == 'product/product' && isset( $this ->request->get[ 'product_id' ])) { $layout_id = $this ->model_catalog_product->getProductLayoutId( $this ->request->get[ 'product_id' ]); } if ( substr ( $route , 0, 23) == 'information/information' && isset( $this ->request->get[ 'information_id' ])) { $layout_id = $this ->model_catalog_information->getInformationLayoutId( $this ->request->get[ 'information_id' ]); } if (! $layout_id ) { $layout_id = $this ->model_design_layout->getLayout( $route ); } if (! $layout_id ) { $layout_id = $this ->config->get( 'config_layout_id' ); } $module_data = array (); $this ->load->model( 'setting/extension' ); $extensions = $this ->model_setting_extension->getExtensions( 'module' ); foreach ( $extensions as $extension ) { $modules = $this ->config->get( $extension [ 'code' ] . '_module' ); if ( $modules ) { foreach ( $modules as $module ) { if ( $module [ 'layout_id' ] == $layout_id && $module [ 'position' ] == 'home_one' && $module [ 'status' ]) { $module_data [] = array ( 'code' => $extension [ 'code' ], 'setting' => $module , 'sort_order' => $module [ 'sort_order' ] ); } } } } $sort_order = array (); foreach ( $module_data as $key => $value ) { $sort_order [ $key ] = $value [ 'sort_order' ]; } array_multisort ( $sort_order , SORT_ASC, $module_data ); $this ->data[ 'modules' ] = array (); foreach ( $module_data as $module ) { $module = $this ->getChild( 'module/' . $module [ 'code' ], $module [ 'setting' ]); if ( $module ) { $this ->data[ 'modules' ][] = $module ; } } if ( file_exists (DIR_TEMPLATE . $this ->config->get( 'config_template' ) . '/template/common/home_one.tpl' )) { $this ->template = $this ->config->get( 'config_template' ) . '/template/common/home_one.tpl' ; } else { $this ->template = 'default/template/common/home_one.tpl' ; } $this ->render(); } } ?> |
<?php foreach ( $modules as $module ) { ?> <?php echo $module ; ?> <?php } ?> |
<?php echo $content_middle ; ?> |
Well that's it, I hope it helped. It's definitely not the most straight forward thing in the world but after a while it does start to make sense. I do feel like there's plenty of opportunity to improve, but even still, OpenCart is the cleanest eCommerce solution I've worked with.
If this tutorial has helped you, if you have any questions, or know a better way, please don't hesitate to leave a comment.
No comments:
Post a Comment