2. OOP- Constructors & Destructor

If you create a __construct() function (it is your choice,) PHP will automatically
call the __construct() method/function when you create an object from your class.

The ‘construct’ method starts with two underscores (__) and the word ‘construct’. You ‘feed’ the constructor method by providing a list of arguments (like a function) after the class name.





1. Object Oriented Programming (OOP)

Object-Oriented Programming (OOP) is a type of programming added to php5,With the release of php5, php programmers finally had the power to code with the ‘big boys’. Like Java and C#, php finally has a complete OOP infrastructure.

Before we move onto writing object-oriented code in PHP, it’s important to understand 4 fundamental OOP concepts: classes, objects, properties, and methods.

A class is a blueprint for objects. When you build your object-oriented application, you typically create one or more classes representing various types of entities in your app.For example, if you’re writing a forum application, you might create classes called Forum, Topic, Post, and Member.


You define your own class by starting with the keyword ‘class’ followed by the name
you want to give your new class.

<?php class person { } ?>

This class doesn’t do much until you’ve added properties and methods to the class.
Nevertheless, the above code creates a valid, usable class in PHP.

[ It’s good programming practice to put each class’s code in its own file, with the same name as the class.For example, you might put the above Member class code in a file called Member.php, and store the file in a folder called classes. ]

An object is a special type of variable that is created from a class.It contains actual data, and you can call the object’s functions to do stuff to that data.You can create as many objects as you like from a single class.Each object functions independently of the others, even if they all come from the same class.

To use a real-world analogy:
. A class is like a blueprint for a car. It defines how cars created from the blueprint will look and behave, but it’s still an abstract concept.
. An object is like a real car created from the blueprint. It has real properties (such as how fast it’s going), and real behaviors (like “accelerate” and “brake”).


How to create objects in PHP:
You create an object from a class by using the new keyword, as follows:

<?php $stefan = new person(); ?>

Class member variables are called “properties”.They are defined by using one of the keywords public, protected, or private, followed by a normal variable declaration.This declaration may include an initialization,but this initialization must be a constant value–that is,it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

Within class methods non-static properties may be accessed by using -> (Object Operator): $this->property (where property is the name of the property).
Static properties are accessed by using the :: (Double Colon): self::$property.
Scope Resolution Operator (::) (also called Paamayim Nekudotayim)

The ‘$this’ variable:
You probably noticed this line of code: $this->name = $new_name The $this is a built-in pseudo variable (built into all objects) which points to the current object. Or in other words, $this is a special self-referencing variable. You use $this to access properties and to call other methods of the current class.

The functions that are defined within a class — and used in an object — are known as methods.In many ways, they’re just like regular functions — you can pass values to them,they can contain local variables, and they can return values.




16. Array

Array: An array is a special type of variable that can hold many values at once all accessible via a single variable name.Arrays are very useful whenever you need to work with large amounts of data — such as records from a database — or group related data together.

How arrays work:

  • An array can hold any number of values.
  • Each value in an array is called an element.
  • You access each element via its index, which is a numeric or string value. Every element in an array has its own unique index.
  • An element can store any type of value, such as an integer, a string, or a Boolean.

There are three different kind of arrays:

  1. Numeric array − An array with a numeric index
  2. Associative array − An array with strings as index
  3. Multidimensional array or Nested Array − An array containing one or more arrays

Indexed Array or Numeric Array:
These arrays can store numbers, strings and any object but their index will be represented by numbers. By default array index starts from zero.

Numeric array example:

 $arr=[3,5,7,9.5,true,"a","c","eeee"];        //latest Method
//$arr=array(3,5,7,9.7,true,"a","c","e");    //old Method
echo "<pre>";        //html tag
print_r($arr);      //function
//var_dump($arr);  // funcion
//echo $arr[6];   // If you want to access single element

for($i=0;$i<count($arr); $i++){  // If you want to access all element
//echo $arr[$i],"<br>";

Associative Array:
The associative arrays are very similar to numeric arrays in term of functionality but they are different in terms of their index. Associative array will have their index as string.
To store the salaries of employees in an array, a numerically indexed array would not be the best choice. Instead, we could use the employees names as the keys in our associative array, and the value would be their respective salary.

associative array example:

$arr2=['a'=>'America','b'=>'Bangladesh','c'=>'China'];                   //latest Method
//$arr2=array('a'=>'America','b'=>'Bangladesh','c'=>'China','d'=>4);    //old Method
echo "<pre>";

/*foreach loop*/  
echo "<pre>";
foreach($arr3 as $a){           // If you want to only value, for this
	//echo $a,"<br>"; 

foreach($arr3 as $k=>$a){      // If you want to access index, for this 
	//echo $k,"<br>";

foreach($arr3 as $k=>$a){     // index and value 
	//echo $k,"=>", $a,"<br>";

Hybrid array Example:


Multidimensional Arrays or nested Arrays:
A multi-dimensional array each element in the main array can also be an array. And each element in the sub-array can be an array, and so on. Values in the multi-dimensional array are accessed using multiple index.

//echo $arr6[8];
//echo $multi[4]['c'][2];

echo $multip[0][0][0][0][0][1];

Array Function:

// extract function used with array
	extract($arr8); // if you want to convert associative array index as variable
	//echo $m;
// EXTR_PREFIX_ALL function used with array
	echo $b_2;
// Normally numerical array's index does not converted in variable, because these index is number.but if you want to convert numeric index as variable, You can use function.

Useful websites on Magento:

In this section, you can fnd a lot of interesting articles about Magento development,Magento design, and free extensions.

Excellence Magento blog:
This is the blog of Manish Prakash, a Magento and mobile app developer.His blog is full of interesting tutorials and articles on Magento development.Check out at http://excellencemagentoblog.com.

Fabrizio Branca blog
Fabrizio Branca is a certifed developer, and he released a number of free extensions to boost up your Magento, especially the cache.You can fnd all the free extensions he created at http://www.fabrizio-branca.de/magento-modules.html

Bubble codes by Johann Reinke
In this website blog, you can fnd interesting articles and resources related to Magento as well as the free Magento Go admin theme.You can check this out at http://www.bubblecode.net/en

Inchoo’s blog
Inchoo is a web company specialized in Magento and they own a blog full of useful information, tips, and free modules that you can use for your project and to understand a lot of things about Magento development, e-commerce-related marketing, and Magento custom free and useful extensions.You can fnd the blog at http://inchoo.net/blog

Tuts plus Magento tutorials
If you are looking for some other neat, simple tutorials on Magento and Magento design, you can fnd some interesting articles when you go to the Tuts plus website and search for Magento.You can access all the Magento articles at http://tutsplus.com/tutorials/search?utf8=%E2%9C%93&search%5Btopic%5D=&search%5Bterms%5D=magento&button=

Smashing magazine
Smashing magazine is an online magazine for web designers and developers.Here too, you can fnd a lot of articles about Magento. You can access this at http://coding.smashingmagazine.com/tag/magento/

Free resources for design, UI, and web design
There have a few links about design, responsive design, and other interesting topics.

UI – UIX resources:
Ux news: http://uxmag.com/topics/e-commerce

Social media
The following is a useful link that can be used for reference:
• AddThis social media: http://www.addthis.com

Free resources
The following are some useful links that can be used for reference:
• Free mockup to present your theme: http://line25.com/articles/40-free-mockup-templates-to-present-your-ui-designs
• Freebies bug: http://freebiesbug.com/
• Pixeden: http://www.pixeden.com/

In this book, we have seen how to create and develop a responsive Magento theme with custom widgets and the custom admin theme panel. We have also seen how to customize the admin theme to make it look better and similar to the front end.The responsive web design is very important, especially during a time like this, when mobile devices are constantly developing and being disseminated, and purchases via smartphones are increasing. If you improve and learn how to do this in the better way, you can offer very high quality services to your clients.I hope you found this guide useful and that it has offered you the fundamental knowledge to be able to continue your work and realize some fantastic Magento themes.

Magento Front End certifcation

Do you know that Magento has also introduced the Front End Developer certifcation? This certifcation is aimed at all the frontend developers with a good knowledge of the Magento front end, whose main focus is on modifying the user interface (UI) of existing themes or on creating new themes.

To become a certifed frontend Magento developer, you have to register on the Magento web site at http://magento.com/training/catalog/certification The certifcation voucher costs 260 USD and you can take the exam at a specifc center nearest to you.

After I took this certifcation, many companies contacted me for professional services to create custom Magento themes or to improve their stores.Thanks to the certifcation, you can assure your customers and the agency you work with that you have all the capabilities and a full understanding of Magento theming

3. Andrea Saccàs personal experience

My personal experience:
I would like to share my personal experience. The frst time I sent the theme Emphasis to the ThemeForest team, the review team there loved it; however, for some reason, they did not accept it because there were some concerns regarding the copyright issues with the brands used in the theme.So, I corrected the problems indicated by the team and then submitted the theme again. After those small modifcations, my theme was approved. Emphasis made 60 sales between October 2013 and March 2014. A good result for the frst theme! A few months after the Emphasis theme publication on ThemeForest, the Envato team selected my theme to include it into a special e-commerce bundle pack. This was another very good occasion and I had the opportunity to earn some extra money with that special event.

The eCommerce Sampler Pack included four themes for four of your favorite e-commerce platforms; mine included the following:
• WooCommerce
• Magento
• Opencart
• Prestashop
The Emphasis theme was selected to represent the Magento category. I was really surprised with this occasion and I earned a lot of popularity in the marketplace.

Now the pack is complete; you can see the landing page created for it at http://go.themeforest.net/the-ecommerce-sampler-pack/.

This is only to let you understand that sooner or later, the effort you put in to create a theme will be paid for. So if you do a great work, you have a great possibility of gaining a lot with ThemeForest and other marketplaces

Theme pricing:
The theme pricing is decided by the review team. Consider that the pricing of Magento themes start from $80 on ThemeForest and are the most expensive items on the marketplace.Also, consider that you will not earn the full quoted price of the theme; ThemeForest will initially give you a commission of 50 percent that will increase based on the sales. You can see the actual commission rate table at

You can also consider the possibility of selling the theme in other marketplaces too; however, the commission will decrease to 30 percent

So the more you sell, the more you earn. You may think that this is not very fair, but this is the easiest way to start selling your creations and getting some extra money for your work.

Inserting the theme on the Magento Connect site:
Another great channel where you can distribute and publicize the theme is the Magento Connect website. This site is the place where you can fnd free and premium extensions and themes for Magento. The sales will not be through this website, but you have to share the link to the theme page of ThemeForest.The following screenshot shows what the Magento Connect website looks like

Register an account and then you will have the option to upload your extension with all the details using a form similar to the one used by ThemeForest. The item must be approved by the team, and only then can it be found on the website. The approvals take about 48 hours and the price is the cost of the extension that you can fnd in your theme page.
You can also consider selling the theme without going through a marketplace such as ThemeForest; in this case, you can set your own price in Magento Connect.

Support and updates
A parenthesis needs to be done on the support and on the updates of the theme. Keep in mind that your theme will be visited and bought by a lot of people. They may fnd some issues or problems that you can solve or help to solve.Fixing the bugs and adding new features Reserve some extra time to collect all the bug fxes and release all the updates for the theme once in a month. This will ensure that the theme is always updated and that users can rely on your products and services.To do this, you can collect some bugs and fx them in the current version of the theme; once fxed, repackage the fles and resubmit the new ZIP fle in the marketplace.To maintain a report of the modifcations you make for each version, you can
create a fle called changelog.txt and add all the fxes or the new features in the following manner:
Version 1.1 (September 6, 2013)
– FIX: Minor Css bugs fixed
– FIX: Top Cart Background fix
– FIX: Responsive Menu
– FIX: Fixed bug in Google font selector
– FIX: Mobile Account links made like Flags and currency dropdown
– NEW: Animated Scroll to top on top Cart click for better user experience
– NEW: Animated Scroll to top on Menu click for better user experience
Version 1.0 (September 1, 2013) – Initial release Through this fle, both the fnal user and you will have a report of all the improvements you make to the theme.The update approval of ThemeForest usually takes about 24 hours, and the users who buy the theme can choose to be notifed when the theme is uploaded through their account. In this way, the users will be notifed once the theme is updated

Now you have the key to start creating a powerful theme for the most-used e-commerce CMS of the world. You can create a theme from scratch with the powerful framework Bootstrap and make it responsive.You also learned how to distribute it on the most important marketplaces, and now, I hope that you can test and create your very own theme for your customer or sell it on the marketplace and become one of the best Magento theme designers! In the appendix that follows, you will fnd all the references and resources used in the theme.Thank you for reading and keep designing and coding!


2. Creating the documentation of the theme

Now you have a working demo and the theme pack installation ready. Before submitting the theme to be sold, or giving the theme to the fnal user/customer,it is good practice to send a detailed documentation along with the theme.The documentation must contain all the instructions to install the theme, the code for the static blocks, and an FAQ section. The documentation is very important and needs to be well written and organized to increase the chances for the theme to be accepted by marketplaces such as ThemeForest. In fact, if the documentation is not good or the theme is not well documented, there are a lot of possibilities of it being rejected.It is recommended that the designer have an editor or a copyeditor proofread the theme’s documentation for a polished, professional end result. Most coders and designers aren’t perfect writers, so getting an extra pair of eyes to make sure all the commas and apostrophes are in place would be a good idea.

[If the documentation is accurate and detailed, you will receive less support requests from the users, and the users will be happy to find all the instructions along with the theme.]

To create good documentation and make sure the help documentation is in a fle format readable by all operating systems and devices, you can create a PDF, HTML, and TXT fle that are preferred, say, .docx.To speed up this process, you can use a preset HTML template that will help you write an organized fle.Let us discuss the two different theme documentation fles that you can use.

The Documenter tool:
Documenter is a great tool to generate custom documentation fles with the capability of customizing the template and many other features. You can fnd the tool at http://revaxarts-themes.com/documenter/ and the following is a screenshot of what the Documenter page looks like

Insert all the theme information, as shown in the following screenshot, along with the full documentation on how to install the theme and all the features that are included in the theme:


By setting up some options, you can create your own style. For example, you can create a custom documentation with the color scheme of the theme: orange, black, and white. The fnal result is shown in the following screenshot:


Some tips to write better documentation:
After you download the source fles, you can open and edit them as you want by adding the section of your choice. The documentation needs to be clear and easy to navigate. You can create a well-organized fle by dividing it into the following sections:
• Start
• Introduction
• Installing the theme
• The theme options panel
• Importing static CMS blocks
• Editing or restoring CMS blocks
• Confguring the home pageChapter 10
• Confguring the products in the home page
• Editing the theme
• Updating the Theme
• Support
• Change log
• Credits

Packaging the theme:
After you create a well-organized piece of documentation, ZIP everything and the theme is ready to be distributed.Sometimes, in the pack, you need to insert the mockup of the theme, or if you prefer, only some features such as the product list, the logo, and so on. So, create an additional folder where you can include all the graphics source fles.To complete the pack, name the folder that must be distributed with the theme name and the theme version. This will help to keep you organized with the feature releases
of the theme. For example, you can create the folder BookStore_theme_v1 and you can organize the content with the following folders:
• Theme
• Documentation
• Mockup

Selling the theme on ThemeForest:
As you know, ThemeForest is the most popular marketplace where you can sell professional themes and get some extra money. To sell a theme, you need to perform the following simple steps:
1.First, create an account and pass a simple test to check if you understood the conditions of the site.
2.Once you create an account and are ready to sell, open the Upload page, as shown in the following screenshot, from your account menu at the top:


3.On this page, shown as follows, you have to select the category where you want to upload the theme; in our case, we will select the eCommerce category:


4.In the next step, you need to insert all the theme information, such as the Name and Description:


As you can see from the tip, the name of the theme must have maximum 50 characters.You can use a name such as BookStore Responsive Magento theme.You need to think of a name that reassumes the theme concept and the main features.Think of it with the SEO (Search Engine Optimization) techniques
in mind, because the keyword you use will also appear on the search engines.For example, try to search Magento Responsive Theme on Google. Actually, this was the frst theme I created while I was writing this book, which is on the ThemeForest Marketplace on the frst page of Google. This is because I used some SEO techniques while writing the title and the description.


5.In the next section, you need to insert all the fles. As you can see in the following screenshot of the theme, you can upload the zip fle you created (Bookstore_Theme_1.zip):


6.Then, you need to upload all the fles including the theme ZIP fle and a custom image to represent the theme that will be the cover of the ThemeForest item page. For example, you can create a custom cover to represent the theme features, as shown in the following screenshot:


7.Next, you need to insert all the theme specifcations. Fill in all the fles and select all the options, and fnally, submit the theme.In a few hours, you will get an answer from the ThemeForest team; if everything is done well, the team will accept the theme and you are ready to make money!


Top Fixed Menu Bar on Scroll

1.jQuery Library add

<div class="nav-container">
	 <div class="nav">
			   <li><a href="">Menu I</a></li>
			   <li><a href="">Menu II</a></li>
			   <li><a href="">Menu III</a></li>


.fix-nav {
/* this make our menu fixed top */
    z-index: 9999;
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
.fix-body {
/* this will adjust body top margin to prevent content jumping when nav gets fix  */
    margin-top: 50px;
/* adjust as per height of your menu */;
.nav-container {
    background-color: #f86d5a;


$(window).scroll(function () {
     if ($(this).scrollTop() > 250) {
     } else {