OpenCart 2.0 (Code Formatting)

It is inevitable that if you spend enough time within the OpenCart framework you will end up writing some of your own customizations, especially if you plan on extending the default installation. There is nothing worse than making a ton of customizations and not remembering where they are later on. In PHP there are a couple of ways to comment your code so it will be easily seen and “marked” if you will, allowing you to find it later. This is especially helpful with files that have a thousand + lines of code. Sometimes, if you aren’t used to looking at PHP it can all start the look the same. For this article we will comment some custom code within the following file: catalog/controller/product/product.php which is a control file.

Today we will simulate adding a couple variables to be echoed on to the product.tpl page. The product.tpl is a VIEW file and is better known as Opencart’s Product Details Page. In

catalog/controller/product/product.php find this code: $this->data['heading_title'] = $product_info['name'];

Now before that code let’s insert our new code like this:

$this->data['new_variable'] = "Hello World";

Now that we have our new code we need to comment the code to basically mark it. Above the line you just wrote insert some text to label the code beginning with a // or a # like this:

#This is our new code

$this->data['new_variable'] = "Hello World";

That will label the code and ensure that it is not visible to the PHP ENGINE. If you don’t comment with a // or # then it will throw an error normally.

Looking for quality OpenCart Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , | Posted under OpenCart | RSS 2.0

Author Spotlight

Joe Stenhouse

I am a web application developer that specializes in PHP, JAVASCRIPT, MYSQL, HTML, and CSS. We manifest exciting potentials within the world wide web through means of innovation.

Leave a Reply

Your email address will not be published. Required fields are marked *