Orders count of product in Opencart

While developing e-commerce website I came across adding a feature to display total orders count of product in OpenCart on product’s page. This way visitors will be able to know about how much orders of a specific product have been given (my client’s perspective). Since OpenCart follows MVC architecture, therefore the developer experienced with MVC architecture and especially with Codeigniter can easily understand and follow the modifications described below.

  1. We are required to add a function in the product’s Model for fetching orders count of a product.
  2. Gather the required info from Model into Controller
  3. Display the info on view page of product

Code for displaying Orders count of product in Opencart

In Model folder, find product.php file and add the following function/code. This code contains required query for getting orders count of product.

I found required file in > (catalog/model/catalog/product.php)

In Controller folder, find product.php file and add following statement in its index() function.

I found required file  in(catalog/controller/product/product.php)

We are now done with backend code and left with front-end for display of counter. Open your theme folder and find product template file(product.tpl).

product.tpl (catalog/view/theme/your_theme/template/product/product.tpl)

Its now all about HTML for displaying required info according to your template.

So this is it, all done. These were three simple steps for a web developer to add a functionality for displaying orders count of product in OpenCart.

Read More

setTimeout function jQuery

If you are thinking to perform some operation(s) after some specified interval of time, then jquery setTimeout function is ready to do the job for you.

setTimeout function

setTimeout() accepts two arguments.

  1. The function that you want to execute after specified delay.
  2. The duration of delay in milliseconds

In the above example code, myFunction is the one which I wanted to execute after 2 seconds.

In another way, one can also use anonymous function(if not want to define the function separately) and define login in setTimeout as follows:

setTimeout() is a basic JavaScript function, actually. Do not confuse setTimeout() with setInterval() function. The difference between the two is that setTimeout() executes once after specified time, while setInterval() repeats the execution of function.

Read More