根据产品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';
}
}
答
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));
}
你要这个或别的东西
硬编码这真的不是一个好主意。你会更好地使用[像这样的扩展](http://mos.so/8056) – 2015-04-03 15:35:42
使用代码格式。 – JodyT 2015-04-03 16:16:28
感谢您的建议,但我不想为延期支付50美元。有没有办法硬编码它正确? – nfgkid 2015-04-03 21:27:01