A
A
ankfrv2015-10-21 13:45:31
opencart
ankfrv, 2015-10-21 13:45:31

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

4 answer(s)
O
Oleg Plotnikov, 2019-11-28
@oleg_plotnik

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.phpa 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 "";
  }
}

Change to catalog\controller\product\product.phpstring
on the
$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));
}

Next, we create a copy of product.tpl and call it, say, zakaz.tpl. The controller does NOT need to be copied.
In the admin panel, add the Zakaz layout, specify the path to the new product/zakaz template file (without tpl). We go to the product, change its design from Product to Zakaz.

V
Vladislav Byvshev, 2015-10-23
@glk92

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...

W
web-mechanic, 2015-10-28
@amfetamine

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

H
halfhope, 2015-10-29
@halfhope

I once wrote a " Personalized Templates " module

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question