Post by wroesner » Sat May 28, 2022 3:51 am

Hi,
I am reading in your documentation:
http://docs.opencart.com/en-gb/catalog/product/design/
It says, I could override the default layout for any product by creating a new layout and assign any product to this new layout if desired.
I did so. I created a modified product template and set it up in a new layout and selected this layout in the product data which creates an entry in table oc_product_to_layout assigning the product_id to the selected layout_id.
However, any modification of this kind does NOT show up in the shopping cart's product page. It continues to use the default layout.
This is because in controller/product/product.php you write:

Code: Select all

$this->response->setOutput($this->load->view('product/product', $data));
means, you do not check whether a product specific template be defined but always load the default template. Of course, I can modify this line and have the script load a product specific template but his is not an elegant solution. As it is coded right now, the definition of specific templates in the product data sheet doesn't have any use.
Can you suggest a modification of the code in controller/product/product.php to the effect of loading the specific product template (if defined)?
Best regards
Wolfgang

Newbie

Posts

Joined
Sat May 28, 2022 3:28 am

Post by halfhope » Sat May 28, 2022 5:50 pm

Hi!

You can use hard-coded solution - check layout_id and load template, e.g. product_extended.twig.

Code: Select all

$this->load->model('catalog/product');
    $layout_id = $this->model_catalog_product->getProductLayoutId($this->request->get['product_id']);
if ($layout_id == 12) {
    $this->response->setOutput($this->load->view('product/product_extended', $data));
} else {
    $this->response->setOutput($this->load->view('product/product', $data));
}
Also, need to fix all modifications that change "product.twig" to changing also "product_extended.twig" too.

I am not fully understand what you need, so recommend you use one of my extensions:
Last edited by halfhope on Tue Jul 12, 2022 1:22 pm, edited 1 time in total.

My extensions in marketplace. [ security | flexibility | speedup ]


User avatar
Active Member

Posts

Joined
Tue Dec 10, 2013 9:44 pm
Location - San Diego

Post by wroesner » Sat May 28, 2022 9:07 pm

Hi Halfhope,
great, thanks. I saw that model/catalog/product.php offers this function getProductLayoutId().
Your proposed code will certainly work though it is not elegant to modify the code - as you already say.

The extension offered by you "Custom templates Pro" allows to select product specific product-templates
without hardcoding, right?
The example installation at https://ctp.shth.ru/admin/ does not open in my browser.
What I want to accomplish is:
I want to create a template product2.twig (a modified product.twig) and assign this to certain products in
our store which I want to be displayed with this modified template.
Will your extension allow me to accomplish this without hard-coding anything in the model- or controller-files?
Wolfgang (with friendly greetings to Russia)

Newbie

Posts

Joined
Sat May 28, 2022 3:28 am

Post by halfhope » Sun May 29, 2022 3:33 am

The example installation at https://ctp.shth.ru/admin/ does not open in my browser.
Fixed.
Will your extension allow me to accomplish this without hard-coding anything in the model- or controller-files?
Yes. Here is a description of the process.

If you just need to show some text or HTML for selected products see here.

My extensions in marketplace. [ security | flexibility | speedup ]


User avatar
Active Member

Posts

Joined
Tue Dec 10, 2013 9:44 pm
Location - San Diego
Who is online

Users browsing this forum: No registered users and 108 guests