就我們經驗,如客人有使用 OpenCart 及累積了一定數量產品 (products) 及商品分類 (category) ,OpenCart 就會比較越行越慢。
從數據庫看,它把每個商品分類都去計算分類裡的產品數目。
所以,當客人 OpenCart 有商品分類,OpenCart 就會把每個分類計算一次,所以 OpenCart 就會越行越慢。
解決方法:停止計算產品數目
OpenCart 2.x:
在 OpenCart 管理平台裡,
Settings -> select your store -> Option ->
change “Category Product Count” from Yes to No
OpenCart 1.5:
#1 需要手動修改 catalog/controller/common/header.php , 尋找
$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']) );
改作
//$product_total = $this->model_catalog_product->getTotalProducts($data); $product_total = 0; $children_data[] = array( //'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']) );
—
#2 及手動修改 catalog/controller/module/category.php , 尋找
$categories = $this->model_catalog_category->getCategories(0); foreach ($categories as $category) { $total = $this->model_catalog_product->getTotalProducts(array('filter_category_id' => $category['category_id']));
改作
$categories = $this->model_catalog_category->getCategories(0); foreach ($categories as $category) { if ($this->config->get('config_product_count')) { $total = $this->model_catalog_product->getTotalProducts(array('filter_category_id' => $category['category_id'])); } else { $total = 0; }
—
#3 及手動修改 catalog/controller/module/category.php , 尋找
$data = array( 'filter_category_id' => $child['category_id'], 'filter_sub_category' => true ); $product_total = $this->model_catalog_product->getTotalProducts($data); $total += $product_total;
改作
$data = array( 'filter_category_id' => $child['category_id'], 'filter_sub_category' => true ); if ($this->config->get('config_product_count')) { $product_total = $this->model_catalog_product->getTotalProducts($data); } else { $product_total = 0; } $total += $product_total;
ref.:
http://www.yourhowto.net/fix-opencart-loading-very-slow/
https://www.quora.com/How-can-I-speed-up-an-opencart-site-that-has-50-000-products