เห็นจากกระทู้
http://www.siamopencart.com/webboard/index.php/topic,995.0.htmlและผมก็ได้นำเสนอวิธีการสร้างเมนูให้แสดงสินค้าทั้งหมดแล้ว เลยจะเอามาใช้คู่กัน
1.ไปที่ \catalog\controller\module\category.php
หา
protected $path = array();และเพิ่มอันนี้ลงไปด้านล่าง
private $all = 0;จากนั้นหา
if ($results) {
$output .= '<ul>';
}แล้วเพิ่มโค้ดนี้ลงไปข้างล่าง $output .= '<ul>';
$this->all = $this->getAllProductRow();
$output .= '<li><a href="index.php?route=product/allproducts">'.$this->data['txt_allproduct'].'('.$this->all.')</a></li>';
2.หา
$this->data['heading_title'] = $this->language->get('heading_title');เพิ่มบรรทัดนี้ลงไปด้านล่าง
$this->data['txt_allproduct'] = $this->language->get('txt_allproduct');
3.จากนั้นให้ไปเพิ่มในไฟล์ภาษาที่
\catalog\language\thai\module\category.php
(\catalog\language\english\module\category.php)
เพิ่ม
$_['txt_allproduct'] = 'สินค้าทั้งหมด';4.จากนั้นเพิ่มโค้ดเพื่อเรียกจำนวนสินค้าทั้งหมด(sql) โดยเอาฟังก์ชั่นตัวนี้ไว้ก่อนบรรทัดที่อยู่ล่างสุด
}
?>
public function getAllProductRow(){
$query = $this->db->query("SELECT product_id FROM product WHERE status='1'");
$product_data = $query->num_rows;
return $product_data;
}เสร็จแล้วคับ แค่นี้ก็ได้หมวดหมู่อีก 1 หมวดหมู่ที่แสดงจำนวนและลิงค์ไปยังหน้าแสดงสินค้าทั้งหมดได้
สำหรับใครที่ไม่ได้ทำหน้าแสดงสินค้าทั้งหมดเอาไว้ก็อาจจะแสดงแค่จำนวนก็ได้โดยแก้ที่
$output .= '<li><a href="index.php?route=product/allproducts">'.$this->data['txt_allproduct'].'('.$this->all.')</a></li>';
เป็น
$output .= '<li>'.$this->data['txt_allproduct'].'('.$this->all.').'</li>';

โค้ดทั้งหมดที่สมบูรณแล้วใน \catalog\controller\module\category.php ก็อปปี้เอาไปวางทับเลยก็ได้
<?php
class ControllerModuleCategory extends Controller {
protected $category_id = 0;
protected $path = array();
private $all = 0;
protected function index() {
$this->language->load('module/category');
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['txt_allproduct'] = $this->language->get('txt_allproduct');
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$this->load->model('tool/seo_url');
if (isset($this->request->get['path'])) {
$this->path = explode('_', $this->request->get['path']);
$this->category_id = end($this->path);
}
$this->data['category'] = $this->getCategories(0);
$this->id = 'category';
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/category.tpl')) {
$this->template = $this->config->get('config_template') . '/template/module/category.tpl';
} else {
$this->template = 'default/template/module/category.tpl';
}
$this->render();
}
public function getAllProductRow(){
$query = $this->db->query("SELECT product_id FROM product WHERE status='1'");
$product_data = $query->num_rows;
return $product_data;
}
protected function getCategories($parent_id, $current_path = '') {
$category_id = array_shift($this->path);
$output = '';
$results = $this->model_catalog_category->getCategories($parent_id);
$this->all = $this->getAllProductRow();
if ($results) {
$output .= '<ul>';
}
$output .= '<li><a href="index.php?route=product/allproducts">'.$this->data['txt_allproduct'].'('.$this->all.')</a></li>';
foreach ($results as $result) {
if (!$current_path) {
$new_path = $result['category_id'];
} else {
$new_path = $current_path . '_' . $result['category_id'];
}
$output .= '<li>';
$children = '';
if ($category_id == $result['category_id']) {
$children = $this->getCategories($result['category_id'], $new_path);
}
/*
if ($this->category_id == $result['category_id']) {
$output .= '<a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $new_path) . '"><b>' . $result['name'] . '</b></a>';
} else {
$output .= '<a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $new_path) . '">' . $result['name'] . '</a>';
}*/
if ($this->category_id == $result['category_id']) {
$product_total = $this->model_catalog_product->getTotalProductsByCategoryId($result['category_id']);
$output .= '<a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $new_path) . '"><b>' . $result['name'] . '</b>('.$product_total.')</a>';
} else {
$product_total = $this->model_catalog_product->getTotalProductsByCategoryId($result['category_id']);
$output .= '<a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $new_path) . '">' . $result['name'] . ' ('.$product_total.')</a>';
}
$output .= $children;
$output .= '</li>';
}
if ($results) {
$output .= '</ul>';
}
return $output;
}
}
?>