Post by barkingkiwi » Thu Feb 26, 2015 5:26 am

My OpenCart version is 1.5.6.4.

I'm having an issue getting custom Layouts to apply to specific products. Here's a basic description of what I'm trying to do, how I'm doing it, and what's not working.

I essentially want a template product page without an "Add to Cart" option which can be applied to specific products.

Here's my method: I go into catalog\view\theme\default\template\product and make a copy of product.tpl and rename it no_cart_product.tpl. I edit the file and remove the "Add to Cart" features. (The template itself is fine - I tested the template by temporarily making this change to product.tpl itself and it does exactly what I need it to do.)

Then, I go into my admin panel, go to System>Design>Layouts, Insert, name it "No Cart Product", and under route I put product/no_cart_product.

Then, I go to Catalog>Product, edit on the product I want with the No Cart Template, go to the Design tab, and from the dropdown menu I select "No Cart Product."

Now, my logic tells me this should apply the no_cart_product.tpl file I created to this particular product, but it doesn't work. It simply loads the regular product.tpl file. I tested this by editing the product.tpl file itself and confirmed that, even though the product is set to the No Cart Product layout, it loads product.tpl.

Am I doing something wrong? Is there something I'm missing? Does OpenCart not work this way? Does it not support new .tpl files?


Additional info:
I know that OpenCart defaults to the default product page if there is no new template applied. I'm no programmer or coder, but I dug into the product controller file (\catalog\controller\product\product.php) and found this line of code, which I think is responsible for this function:
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 = 'default/template/product/product.tpl';

That particular product path colored red is what is being loaded no matter what. I know because I temporarily changed it to no_cart_product.tpl and it applied the template without the Add to Cart function to all of my products.

I would really appreciate any help!

Newbie

Posts

Joined
Fri Feb 13, 2015 3:59 am

Post by IP_CAM » Thu Feb 26, 2015 8:24 am

Before trying to reinvent the wheel, I would do it the 'option-reduced quick fix' way.
Set the Quantity available to ZERO for all Products without a Add to Cart Button. You may place an image, or Content, instead of an Add to Cart Button, some Mods already 'contains' such 'stuff', always editable by hand...:

http://www.opencart.com/index.php?route ... ock%20zero

It a very 'unprofessional' way,I know, but it will save you good Money, because I imagine, noone here would be able or willing to invest quite some houres of 'hard thinking' to get this 'DONE' in a really professional way, just for the Fun of it...

Just an Idea..., no offense!
Ernie
bigmax.ch/shop/

My Github OC Site: https://github.com/IP-CAM
5'600 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by barkingkiwi » Fri Feb 27, 2015 5:35 am

Hi IP_CAM, thanks for the input. I take it from your info that I am indeed wrong about how OpenCart handles the Layout/design/.tpl files. I assumed I was working within the intended functionality of OpenCart, not reinventing the wheel!

But, if this is the case, your suggestion will probably work better than anything else. I do appreciate it!

Newbie

Posts

Joined
Fri Feb 13, 2015 3:59 am

Post by IP_CAM » Fri Feb 27, 2015 7:52 am

unfortunately, it's not as easy, as it may look, you may remove or relocate, unaware of the consequences, one single 'line' in your OC Product Template, and it COULD have a severe impact on the whole page layout, especially, if you work with VqMod's, depending on 'using' certain 'markers/fixpoints/in Place of' Content within this file to do their job, modifying, adding, replacing, removing whatever, 'before/after/in Place of' this given 'marker /fixpoint/tag...or whatever you want to call it! :D

In addition to this, a Product template 'contains' a lot of Code, related to 'OC default' Options, i.E. User Comments or whatever, fully 'unneeded' if one does not use such 'options', but they still exist in the Code. So, if you 'move' something around, and possibly decide a 'activate' such a Mod at a later time, or add a new VqMod to do something on this Page, you could be very surprised to find certain Things not longer, where they are supposed to be and look, in the first Place. Or, even worse, your page produces nice Errors.

It's the Combination of it all, what makes it rather 'intransparent' for Non-Coders, with OC. And since just about every THING is placed as a socalled '$-variable', one has to find out first the 'Meaning' of Many of them, in order to find out, where to modify what. OC i's multi/multi/multi, and that's the price we pay for it.

On the other Side, one can remove a lot of 'things', so 'shrink' file-content, and, as a result, at best, get a little bit more performance. It all depends on what one requires and how much he/she does know about Coding...

However, it's a rather time-consuming way to do things..., compared with creating a 'regular' Webpage. With or without the Use of VqMod's, since OC does not use REGULAR HTML type Templates, containing a 'visually' recognizable and at least more famliliar looking/feeling HTML-type Source Layout.

PS: I did not even mention the upmost important Role, Stylesheets (+JS-type Coding) 'play' in OC.

Good Luck
Ernie
bigmax.ch/shop/

PS: We did not even talk about your Problem: >>custom template to specific products<<
that's even worse...
Last edited by IP_CAM on Fri Feb 27, 2015 9:21 am, edited 3 times in total.

My Github OC Site: https://github.com/IP-CAM
5'600 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by qahar » Fri Feb 27, 2015 8:22 am

I have two suggestion for this.

1. Long way road
- Create custom template input
- Add new "template" column to database. Or table if you need custom template for multi-store
- Edit OpenCart admin save page to save custom template
- Load custom template on front product controller
- Apply custom template

2. Hack Method
- Find unused input on product admin (lets asume 'location' input)
- Put and save custom template in product 'location' input
- Use it to check and load custom template

Code: Select all

$custom_tpl = $this->config->get('config_template') . '/template/product/' . $result['location'];
if (file_exists(DIR_TEMPLATE . $custom_tpl)) {
    $this->template = $custom_tpl;
}
If you make it for client, I suggest you to go for the first method.
If this is your own site, you can go with 2nd method. Rename Location in language file to Custom Template to not get confused on future

User avatar
Expert Member

Posts

Joined
Tue Jun 29, 2010 10:24 pm
Location - Indonesia

Post by anis99 » Tue Mar 24, 2015 8:13 am

qahar i have taken advantage from your knowledge from different many posts and i would like to thank you for that....please can you explain the first section that you said in response to this post.
"1. Long way road
- Create custom template input
- Add new "template" column to database. Or table if you need custom template for multi-store
- Edit OpenCart admin save page to save custom template
- Load custom template on front product controller
- Apply custom template"

Newbie

Posts

Joined
Tue Mar 24, 2015 8:01 am
Who is online

Users browsing this forum: No registered users and 5 guests