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