企业级电子商务与供应链解决方案供应商.
联系我们

+86-13006619568

info@cnopencart.com

深圳,苏州,成都,上海,杭州

扫二维码加微信
wechat

深圳,苏州

+86-16606168892

Top

Opencart商城加速之去掉产品数量加载

Opencart商城加速之去掉产品数量加载

Since OpenCart is the best and most used system for online store creating, we decided to give you a few tips on how to increase the speed of OpenCart.

The speed of your online store depends on the amount of products and categories the system needs to calculate every time the site is loaded. To increase the speed of your online store you need to rewrite some of the files in OpenCart, so that the system does not calculate the products every time. Yes, you have the option to hide the number of categories and products from your site administrative page, but this action will in no way help you increase the speed.

Now that we have cleared this up, let’s get back to the action of optimization of the system.
The optimization can be done in two ways – manually or with a plug-in. While optimization with a plug-in may be easier, it is not the safest choice, because there is a chance of never changing back the information you once changed. That is why we highly recommend you to do the optimization manually. In this way you will know exactly which file you have rewritten and you could rewrite it back at any time.

We will lead you through the manual optimization step by step, but before we do that, we have to warn you that this type of optimization only works on OpenCart 1.5.6.4. It may also work on some older versions of the system.

Now let’s go back to the optimization process. The manual optimization is a simple rewriting of three files in OpenCart. These changes will prevent the system from calculating the categories and products on your site and the speed will increase.

Before starting the processes, you should go to your administration page and from there hide your products, then prepare to rewrite three files:

catalog/controller/product/category.php – The number of categories and products
catalog/controller/common/header.php – The number of products in the menu
catalog/controller/module/category.php – The number of products in menu on the left

In the first file – catalog/controller/product/category.php

Rewrite the code from:

$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)
);

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 is the one containing the function to calculate the amount of products on the site

Find this file and rewrite it from:

$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’])
);

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

From this file you can stop the calculating of the amount of categories and products on the left menu.

To do this, rewrite this file from:

$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’])
);

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’])
);

Most of the online stores that have done these optimizations report wonderful results and a significant loading speed increase.

If you find no difference before and after these changes, you can also use some other methods such as Memcached. Using the cache of Memcached, you can easily speed up your OpenCart. Every time you make a change in your code or add more extensions, make sure you have an up-to-date backup.