OpenCart Theme and Module Development - Sample Chapter
OpenCart Theme and Module Development - Sample Chapter
ee
$ 29.99 US
19.99 UK
P U B L I S H I N G
Rupak Nepali
pl
C o m m u n i t y
E x p e r i e n c e
D i s t i l l e d
Sa
m
Rupak Nepali
on the OpenCart framework since 2010. He has also completed many projects
and built many modules on OpenCart to meet his clients' requirements. He is
currently working as a web developer at Corner Edge Interactive, Arizona, and as
a freelancer on Elance, oDesk, and other freelancer sites. Rupak holds a bachelor's
degree in computer information systems from Nobel College, Kathmandu, Nepal.
He is currently studying for his MS degree in computer science from the Maharishi
University of Management, Iowa, USA.
Preface
Preface
If you can build OpenCart themes, then you can also customize the presentation
layer of OpenCart. Likewise, if you can code OpenCart's extensions or modules, then
you can also customize the functionality of the OpenCart e-commerce framework
and make an e-commerce site easier to administer and look better. You can also
change the way the default OpenCart system works. In this book, you will learn
about the third-party frameworks used in the OpenCart framework, such as
Bootstrap, Font Awesome, and FlexSlider. Similarly, you will learn about the global
methods used in OpenCart. We will create a custom theme and describe most of
the code of the presentation layer. Then you will be able to get a description of the
modules' code and create a custom module.
In OpenCart, modules are a way of customizing and extending the functionality of
OpenCart. This book shows you how to create a customized theme and make all sorts
of extensions: OpenCart modules, an Order Total module, the idea of creating payment
and shipping modules, and ways of creating custom pages and forms on an OpenCart
module to carry out insert, edit, delete, and list operations (the CRUD functionality).
This book focuses on teaching you all aspects of OpenCart's modules and themes
by showing and defining code examples. We describe how to build a new theme
and module from the default OpenCart theme and module. This book describes
every line of code so that you will know what the code does. You will be cloning
the default theme to make a new customized theme.
Each chapter teaches you how to create a new customized OpenCart theme. You will
be able to create a customized theme and a Hello World module by cloning HTML.
Likewise, you will get a description of every line of code of the default Featured
module of OpenCart. Then we will create feedback pages used to manage feedback,
and you will be able to create an Order Total module called Tips Order Total module.
Each chapter builds a practical theme and a module from the ground up using
step-by-step instructions and examples.
Preface
[1]
It also supports:
Downloadable products
Multilanguage
Multicurrency
PCI-compliant
It is search engine optimized and has backup and restoration tools. It provides
features such as printable invoices, sales reports, error logging, multistore features,
multiple marketplace integration tools such as OpenBay Pro, and many more.
Now, let's start with some basic general setting that will be helpful in creating our
theme and module.
[2]
Chapter 1
[3]
After editing, you have to click on the Image tab. You will notice that most of the
image settings are done from here except for the module image setting. In the Image
tab, you will see something like this:
We can change the logo from here, so when designing a new OpenCart theme, we
must take care to ensure that the logo is retrieved from the database. Likewise, the
favicon icon is also inserted from the Image tab, so we should take care about
that as well. Category image sizes are also managed from here. Let's check out the
Desktops category page, you can see the page by hovering the cursor over Desktops
in the menu and clicking on See All Desktops. This is what you will see from the
default options:
[4]
Chapter 1
Now, change the * Category Image Size: input field from 80 to 770, and the next
field from 80 to 100 (the length is in pixels). Then, refresh the Desktops category
page link and you will see the changes in the Desktops category image size.
Similarly, images in the product details page are also adjustable. The product's main
image is adjustable from * Product Image Thumb Size as well as additional product
image size. The following screenshot shows the product image thumbnail and
additional product images:
When you click on the main image or the additional image, it then pops up to show
a larger image in the color box, whose image size is managed by the * Product Image
Popup Size:.
In the same way, related products' images, the compare image size, image sizes in
the wish list, and cart image sizes are all managed from image's settings page.
Downloading the example code
You can download the example code fies from your account at
http://www.packtpub.com for all the Packt Publishing books you
have purchased. If you purchased this book elsewhere, you can visit
http://www.packtpub.com/support and register to have the fies
e-mailed directly to you.
[5]
You can see this by going to the admin dashboard's menu and then to Extension |
Module. Edit the Latest module. You can insert the width and height of the image
to be shown in the frontend in the module. It is flexible, which means that you can
show images in different sizes on different pages and positions. So, while creating
the theme we have to take care of this as well.
[6]
Chapter 1
Title: Enter a title that will be shown to the customer when he hovers the
cursor over the banner
Link (icon): This sets the URL to which the banner will direct the user to
The following shows the Banners page that has the preceding fields in it:
After filling in the input fields, click on the save button, and your banner is ready to
use in the modules.
[7]
[8]
Chapter 1
Banner: This contains the settings to choose from the list of banners
Width and Height: Insert the dimensions of the image that will be shown on
the frontend; enter 180 and 150 in the Width and Height fields respectively
[9]
You can choose four positions: content top, content bottom, column
right, and column left as per your wish as to where the module should
be seen. The Sort Order field shows the module to be displayed first when
there are multiple modules in the same layout and position. Then, the
lower number has higher priority. Let's take an example, as shown in the
following screenshot:
2. As seen here, we have added the Category module with its position set to
Column Right. Now, if you want to show the Account module at the top
and the Category module just below it, in this case, the Sort Order option
plays an important role. As seen in the screenshot, the Account module will
show up first, and then the Category module show up below it. In this way,
you can add many modules in any position and show them in any order as
you please.
3. If you want to show the modules in the Affiliate section, you have to choose
the Affiliate layout as the route is affiliate/%, that is, anything starting
with route=affiliate/ in the URL.
4. Similarly, for other layouts, check the route at Administrator | System |
Setting | Design | Layouts | Edit, see the route, and check the URL route;
you will find where the module will show on choosing the layout name.
[ 10 ]
Chapter 1
5. You can add a new layout from Administrator | System | Setting | Design
| Layouts by clicking the blue plus sign at the top right corner. Then, insert
the layout name, like Special, then click on Add Route, and choose the
Default store to show in the default store, or you can choose required store
and insert value of Route to product/special. Then, click Add Module and
choose one of the module listed (in our case Category), then choose the
position Column left, and then click on the save button to save. Now, check
the front special page; you will see the category module on the left, as shown
in the following screenshot:
[ 11 ]
The system folder consists of a library folder, which consists of many classes
and method files such as cart, customer, affiliate, and more. The cache folder
contains cache files. The database folder consists of database drivers meant for
supporting different types of database engines, and the logs folder contains the
error log files. Similarly, the root image folder contains all the uploaded images and
the downloads folder contains all the downloadable files. The default theme files and
folders are located at catalog/view/theme/default/ and are structured as shown
in the following screenshot:
The view folder contains all the files necessary for changing the style and appearance
of the presentation layer of the site. The default theme is at catalog/view/theme/
default. The default/ folder contains three folders:
image: This contains all the image files used in the theme or template file. It
[ 12 ]
Chapter 1
template: The template folder contains multiple folders and each folder
contains many template files (.tpl). Each folder is meant for creating a
collection of related files. For example, the product folder contains all
template files related to the products, such as category.tpl, product.tpl,
compare.tpl, manufacturer_info.tpl, manufacturer_list.tpl, review.
tpl, search.tpl, and special.tpl. The default template folder contains
Account
Affiliate
Checkout
Common
Error
Information
Module
Payment
Product
Sometimes, we need to add our own JavaScript functionality. In that case, we can
create extra folders here and insert those files. Default JavaScript files are not stored
in the theme location but are in the catalog/view/javascript folder.
[ 13 ]
Summary
In this chapter, we described the file and folder structure of a default theme. You
learned how to change the general settings of images and module images. You also
learned how to create and manage banners and layouts, carousels, and slideshows.
One main thing to remember is never ever delete the default theme folder. Always leave
it in place, as it is used as a fallback if a custom theme does not have template files.
So, in this way, you learned about the theme structure. In the next chapter, we will
deal with basic knowledge of Bootstrap, Font Awesome, and FlexSlider of OpenCart
version 2.
[ 14 ]
www.PacktPub.com
Stay Connected: