2015-04-03 53 views
0

我有大約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

回答

0

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