根据产品ID加载产品模板

问题描述:

我有大约20个左右需要加载特定产品模板的产品,而所有其他产品都加载了默认产品。这是我迄今为止的代码。我无法弄清楚如何合并多个产品ID。任何帮助将不胜感激。根据产品ID加载产品模板

if ($this->request->get['product_id'] == 200000864) { 
    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/customproduct.tpl')) { 
     $this->template = $this->config->get('config_template') . '/template/product/customproduct.tpl'; 
    } else { 
     $this->template = '/template/product/customproduct.tpl'; 
    } 
} else { 
    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product.tpl')) { 
     $this->template = $this->config->get('config_template') . '/template/product/product.tpl'; 
    } else { 
     $this->template = '/template/product/customproduct.tpl'; 
    } 
} 
+0

硬编码这真的不是一个好主意。你会更好地使用[像这样的扩展](http://mos.so/8056) – 2015-04-03 15:35:42

+0

使用代码格式。 – JodyT 2015-04-03 16:16:28

+0

感谢您的建议,但我不想为延期支付50美元。有没有办法硬编码它正确? – nfgkid 2015-04-03 21:27:01

Opencart的2.0

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product.tpl')) { 
       $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/product.tpl', $data)); 
      } else { 
       $this->response->setOutput($this->load->view('default/template/product/product.tpl', $data)); 
      } 

switch ($this->request->get['product_id']) { 
    case 1: 
     $this->response->setOutput($this->load->view('default/template/product/product1.tpl', $data)); 
     break; 
    case 2: 
     $this->response->setOutput($this->load->view('default/template/product/product2.tpl', $data)); 
     break; 

     //... 
     //... 
     //... 
    case 200000864: 
     $this->response->setOutput($this->load->view('default/template/product/product200000864.tpl', $data)); 
     break; 
    default: 
     $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/product.tpl', $data)); 
    } 

你要这个或别的东西

+0

我对产品ID的去向有点困惑。我很抱歉。我对PHP不太熟悉。 – nfgkid 2015-04-16 14:27:36

+0

产品ID进入“案例:”并且自定义模板将在这种情况下声明告诉我,如果你不明白 – StackQA 2015-04-17 05:32:07