How To Speed Up Your OpenCart Store? (Part 1)

OpenCart is one of the most commonly used online store systems by our customers and comprises 6.3% of all installed CMS platforms). As we receive many inquiries about speed optimization we decided to give you a few tips on how to speed up your OpenCart store.

Numerous checks carried out on this issue combined with our expertise gave us grounds to specify the most common reasons for slow loading. The OpenCart system’s code calculates the number of products in each category. Every time a page is loaded, the calculation is performed again. This represents actually an SQL query to the database for each category. The more categories and products you have in your store, the more slowly it will load.

Although, you can disable the number of displayed products from the website’s administration, this does not stop the constant execution of SQL queries.

The optimization is a solution for stores with a large number of categories and products.

Killing two birds with one stone!
By stopping the execution of SQL queries the website not only starts loading faster, but the CPU time of the hosting account is also reduced.

The optimization can be done in two ways: by adding plugins to OpenCart or with manual settings.We highly recommend the second option: manual optimization of OpenCart. The plugins are changing the OpenCart database and some of the system files. What exactly and where is changed by the plugin might not be described in its help section, so sometimes the initial settings of the store cannot be restored. By optimizing OpenCart manually you will know exactly which file is edited and you can undo the changes, if necessary. You will perform the optimization step by step and if something goes wrong you can immediately undo the changes of the edited file.The described manual optimization is performed on OpenCart version 1.5.6.4, but it applies also to 1.5.х older versions.

Optimization with additional OpenCart plugin

You can find online different free and paid plugins that will help you optimize your store. For example: Opencart Turbo.

Another plugin that stops displaying and calculating the number of products in the categories is Product Count True Disabling / Speed Up.

Tip:
If you choose to test your store optimization with such plugins, plase backup your website (database and files).
Manual optimization

The optimization requires editing of three OpenCart files. By replacing a few lines in those files you will stop the constant execution of SQL queries.

Note:: Once you have edited the files, the number of products in categories will no longer be displayed. If you insist on the products’ number visibility, do not optimize your store in this way. In the next article for OpenCart optimization we will tell you more about how to optimize so that the number of products is displayed, but the website does not load so slowly.

Another very important thing is to make a copy of every file before editing it. In this way you will be able to restore it without the changes you have made.

Before manually editing the system files you need to deactivate the visibility of product numbers in the Open Cart admin panel -> System -> Settings -> General (Showing the number of products in a category – select No).

Then get ready for a little editing of three system files:

catalog/controller/product/category.php – the number of products for main categories and subcategories
catalog/controller/common/header.php – the number of products in the main menu (website header)
catalog/controller/module/category.php – the number of products in the menu on the left

• /catalog/controller/product/category.php

In the first system file you need to find the following lines:

$product_total = $this->model_catalog_product->getTotalProducts($data);

$this->data['categories'][] = array(
'name'  => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
);

and change them to:

//$product_total = $this->model_catalog_product->getTotalProducts($data);
$product_total = 0;
$this->data['categories'][] = array(
//'name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
'name' => $result['name'],
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
);

• /catalog/controller/common/header.php

This file contains functionality for calculating the number of products shown in categories on the website main menu.

In this file you need to find the following lines:

$product_total = $this->model_catalog_product->getTotalProducts($data);

$children_data[] = array(
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);

and change them to:

//$product_total = $this->model_catalog_product->getTotalProducts($data);

$children_data[] = array(
  'name'  => $child['name'],
  'href'  => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']) 
);

• /catalog/controller/module/category.php

Disabling of the categories calculation for the website menu of the left.

Find the following lines:

$product_total = $this->model_catalog_product->getTotalProducts($data);

$total += $product_total;

$children_data[] = array(
'category_id' => $child['category_id'],
'name'        => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])	
);

and change them to:

//$product_total = $this->model_catalog_product->getTotalProducts($data);
//$total += $product_total;
$total = 0;
$product_total = 0;

$children_data[] = array(
'category_id' => $child['category_id'],
//'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
'name' => $child['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);

The number of the main categories can be removed in the same file.

Change the following lines from:

$this->data['categories'][] = array(
'category_id' => $category['category_id'],
'name'        => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $total . ')' : ''),
'children'    => $children_data,
'href'        => $this->url->link('product/category', 'path=' . $category['category_id'])
);

to:

$this->data['categories'][] = array(
'category_id' => $category['category_id'],
//'name' => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $total . ')' : ''),
'name' => $category['name'],
'children' => $children_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);

We have optimized many stores in this way and with most of them the result was great as the loading speeds up a lot. If this optimization does not affect the website loading time, there are many other ways to accelerate it.

Memecached is a good example for this. Dynamic Content Caching with  Memcached improves the site loading speed. This is another way to optimize and through it loading a store is considerably accelerated.

The changes made in the system files should not lead to difficulties in the website’s normal operation. However, we strongly recommend to make a backup in advance.

Tip from the support
Since OpenCart offers a great diversity of settings and installation options the optimization process described above might not work for every store. If there is not a visible result from the optimization, the reason for slow loading might be somewhere else (e.g. something that has been additionally installed on the store – a complicated template, additional functionality, a plugin, etc). In this case you should look more carefully for a problem. Make a test by activating another website template or disabling the plugins one by one so that you can detect what is causing the slow loading.
Madlena Metodieva
Madlena Metodieva
Madlena is our super-support-guru. Madlena's SuperPower is that she can explain even the most complicated technologies in plain language.
0 0 votes
.
Subscribe
Notify of
guest

2 Comments
Inline Feedbacks
View all comments