Post by Antoni4 » Tue Sep 16, 2014 10:04 pm

I recently tried the Layout Override feature for Category and Product, and it does not seem to do anything.

Product Layout Override example:

1.
I created new controller + template file for a new product template.

2.
In System->Design->Layouts I added the new product layout.

3.
I attached the new product layout to a product through Design tab.

However when I click on the product with the new layout nothing seems to happen. The product still displayed with a standard product/product layout.

After some inspection I wasn't able to find any code that handles the layout overwrite logic for the product or the category (front end).

I added some logic manually for the product layout override feature (both files attached as examples).
For category layout override feature the logic is probably analogous.

File: controller/product/product.php

modified product controller

Code: Select all

$layout_route = $this->model_catalog_product->getProductLayout($this->request->get['product_id']);		

if(!empty($layout_route) && $layout_route != 'product/product')
{
    $this->redirect($this->url->link($layout_route, $url . '&product_id=' . $this->request->get['product_id']));
}
File: model/catalog/product.php

modified product model

Code: Select all

public function getProductLayout($product_id) 
{
    $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_layout INNER JOIN " . DB_PREFIX . "layout_route ON " .  DB_PREFIX . "product_to_layout.layout_id = " . DB_PREFIX . "layout_route.layout_id WHERE product_id = '" . (int)$product_id . "' AND " . DB_PREFIX . "product_to_layout.store_id = '" . (int)$this->config->get('config_store_id') . "'");
		
    if ($query->num_rows) {
        return $query->row['route'];
    } else {
        return  '';
    }

}
Now my question: is this feature incomplete in the OC 1.5.6, or did I misunderstand what it's for?

Thanks.

User avatar
New member

Posts

Joined
Sat Sep 29, 2012 7:03 am

Post by labeshops » Tue Sep 16, 2014 11:12 pm

You are using it wrong.

All layout override actually does is give you a different named layout to assign modules to. It DOES NOT change templates. So if your main product page say always has a bestsellers module in your right hand column, but you have a single product you do NOT want to show that module on for some reason.

You would go to layouts, create a new one called say "nobestsellers" with the same route as the product layout has and save.

Then when you add that product you don't want it on, you select layout override on the design table from edit > product and select "no bestsellers". And save.

So then the bestseller mod would show on every page that uses the standard product layout but NOT the product you selected the layout override on.

Naturally, you could target different modules, banners, whatever, on that product by editing the banners module and adding one to the "nobestsellers" layout, etc.

Layouts are actually pretty powerful once you wrap your head around how they work, but if you want totally different templates, it takes more work.

Running Opencart v2.2 with multi-stores from https://www.labeshops.com which has links to all my stores.

Image


User avatar
Expert Member

Posts

Joined
Thu Aug 04, 2011 4:41 am
Location - Florida, USA

Post by Antoni4 » Tue Sep 16, 2014 11:39 pm

Thanks for the explanation.

User avatar
New member

Posts

Joined
Sat Sep 29, 2012 7:03 am
Who is online

Users browsing this forum: No registered users and 12 guests