Answer the question
In order to leave comments, you need to log in
How to create a product page layout different from others?
I ask you not to throw rags - I'm not a programmer, I'm just collecting stores on Opencart.
So, the future store will have two types of order processing - traditional (buy → cart → checkout → payment → completion) and through a manager (order a call → checkout by phone). Accordingly, some products should not have a basket button, but a call order button, and they should differ in little things - some of the information is not needed there, it would be nice to remove it from the layout.
Next, I make a copy of product.tpl and call it, say, zakaz.tpl. I do the same with the controller: product.php → zakaz.php. I change all “product / product” in both files to “product / zakaz” (perhaps the error is already somewhere here).
I go to the admin panel, add the Zakaz layout (product/zakaz). I go to the product, change its design from Product to Zakaz.
I try to edit zakaz.tpl, for example, I remove the buy button - absolutely no effect.
Who the fool I already understood. How to solve layout problem?
Answer the question
In order to leave comments, you need to log in
Faced a similar problem. Solutions on the Internet did not suit. I made my own version, maybe it will be useful for someone.
Adding to catalog\model\catalog\product.php
a new function
// получение пути шаблона
public function getProductLayoutRoute($layout_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "layout_route WHERE layout_id = '" . (int)$layout_id . "'");
if ($query->num_rows) {
return $query->row['route'];
} else {
return "";
}
}
catalog\controller\product\product.php
string$layout_id = $this->model_catalog_product->getProductLayoutId($product_id);
if($layout_id) {
$route = $this->model_catalog_product->getProductLayoutRoute($layout_id);
// проверяем существование файла шаблона
$filepath = DIR_TEMPLATE . $this->config->get('config_theme') . '/template/' . $route . '.tpl';
if(file_exists($filepath)) {
$this->response->setOutput($this->load->view($route, $data));
} else {
$this->response->setOutput($this->load->view('product/product', $data));
}
} else {
$this->response->setOutput($this->load->view('product/product', $data));
}
Just cloning product.tpl will not do, you also need to clone controllers, models and language files, modify the common controller, screw some kind of crutch in the admin panel to display this or that template ...
You can make it easier.
Options:
1) Output styles by condition:
We create two different css style files,
In product.tpl we write the condition by which this or that style file will be displayed, possibly with reference to product_id
2) Output of the layout option by condition:
We write a condition, also with binding by product_id
And we make two layout options ... You can get confused so that the layout is in different files so as not to get confused in product.tpl
3) I haven’t tried it myself, I don’t know if this option is suitable for you, but it seems to be what you need
https://opencartforum.com/files/file/591-%D1%81%D0...
just create a column in the oc_product table that characterizes which of the 2 templates will be used, add a check in the admin panel, set a condition for the parameter from the database to select a template in the controller, clone the product.tpl template and make the necessary changes in the cloned template.
and that's it, no headaches
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question