2013-11-15 26 views
0
多个页面Opencart的拆分类

我试图实现以下目标:

类别为GROUP1,GROUP2类别,类别顶部菜单GROUP3

当选择类别GROUP1该组中所有的categorys将上市左栏。

所以左边栏是这样的:

类别GROUP1 category11

类别GROUP1 category12

类别GROUP1 category13

和选择产品的时候,仅此CATEGORY GROUP1应显示在左栏中,

当在顶部菜单选择类别GROUP2我想左侧栏只显示:

类别GROUP2 Category21

类别GROUP2 Category22

类别GROUP2 Category23

当从这个列表中选择一个产品时,我只希望CATEGORY GROUP2在左栏中可见

与类别组3

就无法弄清楚如何做到这一点,因为如果添加的类别模块布局“产品”同样的事情,它会每次都在产品的时候是可见的。

我已经尝试过分割分类并为每个分割添加不同的布局, 示例路由page1/page1,page2/page2,这适用于在不同页面上显示分类,但只要您选择产品,显示与产品页面对齐的所有模块。

这怎么办?

OpenCart 1.5.6

回答

0

我明白你想达到什么目的。我知道创建一个新问题更好。这可以在catalog/controller/module/category.php控制器中完成,其中为根目录检索类别并加载子项。代码改成这样:

class ControllerModuleCategory extends Controller { 
    protected function index($setting) { 
     $this->language->load('module/category'); 

     $this->data['heading_title'] = $this->language->get('heading_title'); 

     if (isset($this->request->get['path'])) { 
      $parts = explode('_', (string)$this->request->get['path']); 
     } else { 
      $parts = array(); 
     } 

     if (isset($parts[0])) { 
      $this->data['category_id'] = $parts[0]; 
     } else { 
      $this->data['category_id'] = 0; 
     } 

     $categories = $this->model_catalog_category->getCategories($this->data['category_id']); 

     if (isset($parts[1])) { 
      $this->data['child_id'] = $parts[1]; 
     } else { 
      $this->data['child_id'] = 0; 
     } 

     $this->load->model('catalog/category'); 

     $this->load->model('catalog/product'); 

     $this->data['categories'] = array(); 

     foreach ($categories as $category) { 
      $total = $this->model_catalog_product->getTotalProducts(array('filter_category_id' => $category['category_id'])); 

      $children_data = array(); 

      if (!$this->data['category_id']) { 
       $children = $this->model_catalog_category->getCategories($category['category_id']); 

       foreach ($children as $child) { 
        $data = array(
         'filter_category_id' => $child['category_id'], 
         'filter_sub_category' => true 
        ); 

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

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

     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(); 
    } 
} 

这应该按预期工作以及之前如果没有提供类别ID ...

+0

谢谢,但这只是拿走了左列的分类,并在topmenu中留下了脚趾?对不起,如果我不够清楚。如果我选择分类组1,则类别11,12,13显示在左侧栏中,并且在选择产品时,分类11,12,13仍然存在(图像1 + 2),则当选择分类组2时,分类21 ,22,23显示在左栏中,而选择产品时只有那些类别存在。 (image3 + 4)这样让产品页面能够继承前面的地方,希望它能让你感觉到它? –

+0

好吧,我用CSS解决了这个问题,通过向基于路线的body添加不同的类,并简单地显示/隐藏我不想要的东西。不是最终的溶剂,但工作。我应该在这里发布答案还是太肮脏的解决方法? –

+0

恕我直言,这是一个解决方法,但如果它的工作,OFC张贴在这里,并接受它,以便有人可能在未来使用它;-) – shadyyx