Post by Wardy_118 » Thu May 12, 2011 10:59 pm

Hi,

I was wondering if it was possible to have two different product pages? On one of the pages I want it to be the normal Opencart product page but I want to build a custom product page which is used for just one of my products.

This page doesn't need to be edited inside the admin as it is always going to be the one same product all of the time.

I have tried copying the product.php/tpl files inside the catalog folder and renamed this but I can't quite seem to work out how to do it.

Can anyone help.

Thanks

New member

Posts

Joined
Tue Apr 13, 2010 5:50 pm

Post by jcsmithy » Fri May 13, 2011 4:13 am

Copy the product.tpl file and adjust to what you want.

Now presuming the product_id of this item is always going to be the same, what you can do is this...

In the controller\product\product.php file, find this:

Code: Select all

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';
}
and change it to something like this

Code: Select all

if($this->request->get['product_id'] == '123') {  // If ID matches this, use this new template
   if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product_new.tpl')) {
      $this->template = $this->config->get('config_template') . '/template/product/product_new.tpl';
   } else {
      $this->template = 'default/template/product/product.tpl';
   }
} else {  // If not, use standard
   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';
   }
}

Active Member

Posts

Joined
Fri Oct 01, 2010 9:54 pm

Post by Hildebrando » Sun May 15, 2011 12:09 am

Hi:

you have this free ext

Best,

Hilde

Commercial Contributions:Bulk Specials| Bulk Update Prices|Search Tyre Pro
Free Contributions: Youtube video (oc 1.5.x) | Search History Report (oc 1.5.x) | Product Filter by Category (oc 1.5.x)|Youtube Popup
More Free & commercial mods: www.fpress.com


User avatar
Active Member

Posts

Joined
Fri Mar 06, 2009 8:22 pm
Location - Spain

Post by fourgood » Wed Jun 01, 2011 2:07 am

hey, is there a way to have multiple id`s for the additional template?

something like this for example? (btw this is not working)

Code: Select all

if($this->request->get['product_id'] == '1' || '2')

Active Member

Posts

Joined
Wed Oct 20, 2010 9:49 pm

Post by fourgood » Wed Jun 01, 2011 2:16 am

in my case it was easy:

Code: Select all

    if($this->request->get['product_id'] < '3' )

Active Member

Posts

Joined
Wed Oct 20, 2010 9:49 pm

Post by Wardy_118 » Wed Jun 15, 2011 5:24 pm

Thanks jcsmithy,

The code you suggested worked perfectly.

However, I now require 4 different products to each have there own unique product template.

I have tried copying the code you suggested 4 times and changing the template used for each one but that only seemed to enable the last one to work and the other 3 kept the standard product template and not the unique one that I had assigned.

Any suggestions on what I need to do?

Cheers
jcsmithy wrote:Copy the product.tpl file and adjust to what you want.

Now presuming the product_id of this item is always going to be the same, what you can do is this...

In the controller\product\product.php file, find this:

Code: Select all

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';
}
and change it to something like this

Code: Select all

if($this->request->get['product_id'] == '123') {  // If ID matches this, use this new template
   if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product_new.tpl')) {
      $this->template = $this->config->get('config_template') . '/template/product/product_new.tpl';
   } else {
      $this->template = 'default/template/product/product.tpl';
   }
} else {  // If not, use standard
   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';
   }
}

New member

Posts

Joined
Tue Apr 13, 2010 5:50 pm

Post by jcsmithy » Thu Jun 16, 2011 2:04 am

If you follow the same logic, you can use an "else if" statement to apply a different template....

I've removed the code withing the statement, hopefully you can figure out what needs to be added, but you can use this instead:

Code: Select all

if($this->request->get['product_id'] == '1') {
    // show template 1
} else if($this->request->get['product_id'] == '2') {
    // show template 2
} else if($this->request->get['product_id'] == '3') {
    // show template 3
} else if($this->request->get['product_id'] == '4') {
    // show template 4
} else {
    // show default template
}


Now, if you follow that logic, each IF statement will be checked up to the point it evaluates true, if each one comes back false, then it will use the final "else" statement - always have the last statement in place!


See how that helps :)


btw - if you end up needing lots more different templates for different products, you may aswell make your life easier and put in a "template selection" from within the admin. this way, rather than trying to edit code yourself, you'll just have a dropdown to choose which to use. Let me know if you want this, and we'll see if we can work something out :)


Jcsmithy.

Active Member

Posts

Joined
Fri Oct 01, 2010 9:54 pm

Post by scanreg » Wed Aug 31, 2011 10:22 pm

Hildebrando wrote:Hi:

you have this free ext

Best,

Hilde
Thanks for the link, I hope this extension is updated for OC 1511 and beyond

Active Member

Posts

Joined
Thu May 06, 2010 12:15 am

Post by Hildebrando » Thu Sep 01, 2011 12:01 am

I think in 1.5.x it is not necesary. You have layouts!

Commercial Contributions:Bulk Specials| Bulk Update Prices|Search Tyre Pro
Free Contributions: Youtube video (oc 1.5.x) | Search History Report (oc 1.5.x) | Product Filter by Category (oc 1.5.x)|Youtube Popup
More Free & commercial mods: www.fpress.com


User avatar
Active Member

Posts

Joined
Fri Mar 06, 2009 8:22 pm
Location - Spain

Post by scanreg » Thu Sep 01, 2011 1:10 am

Hildebrando wrote:I think in 1.5.x it is not necesary. You have layouts!
Do you know if the layouts allow custom php too for particular items?

Active Member

Posts

Joined
Thu May 06, 2010 12:15 am

Post by Hildebrando » Thu Sep 01, 2011 5:33 pm

Yes, you can... :)

Commercial Contributions:Bulk Specials| Bulk Update Prices|Search Tyre Pro
Free Contributions: Youtube video (oc 1.5.x) | Search History Report (oc 1.5.x) | Product Filter by Category (oc 1.5.x)|Youtube Popup
More Free & commercial mods: www.fpress.com


User avatar
Active Member

Posts

Joined
Fri Mar 06, 2009 8:22 pm
Location - Spain

Post by scanreg » Thu Sep 01, 2011 11:25 pm

Hildebrando wrote:Yes, you can... :)
Wow, this might work!

BTW, can the custom layout be made to force SSL?

I'd need one or two product pages to always be in SSL

Active Member

Posts

Joined
Thu May 06, 2010 12:15 am

Post by sinbad » Sun Feb 19, 2012 1:09 pm

How would you apply this custom view to a whole category of products?

User avatar
New member

Posts

Joined
Sun Oct 23, 2011 12:52 pm

Post by sinbad » Mon Mar 19, 2012 12:00 pm

If I use this code in the category.php controller file I can set different view per category on category page.

Code: Select all

// starting my custom category view
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category.tpl')) {
if ($category_id == 81) { 
$this->template = $this->config->get('config_template') . '/template/product/category_download.tpl';
} else { //default
$this->template = $this->config->get('config_template') . '/template/product/category.tpl';
}
} else {
$this->template = 'default/template/product/category.tpl';
}
//end custom category design
So following same login I tried the same code modified on product.php controller but because category_id isn't defined i get veriable error. I've tried coping parts from category.php controller but I couldn't figure it out. the error pressist.

anyone mind sharing what needs to be added to product controller so I can use category id in it?
this way I should be able to have custome tpl per category x

User avatar
New member

Posts

Joined
Sun Oct 23, 2011 12:52 pm

Active Member

Posts

Joined
Fri Mar 12, 2010 6:31 am

Post by scanreg » Sun Sep 30, 2012 11:09 pm

Are both of your extensions (Multiple Prod/Cat templates and Css Override) compatible with both of the following performance extensions:

1. Increase Page Speed Minify Compress Cache Database Optimization (tcalp - Hunter)
http://www.opencart.com/index.php?route ... on_id=6204

2. Page Cache - Boost your site speed and Google ranking (JAY6390)
http://www.opencart.com/index.php?route ... on_id=3477

These are both excellent extensions

Active Member

Posts

Joined
Thu May 06, 2010 12:15 am

Post by lanceox » Sat Aug 17, 2013 8:52 pm

This helps alot. Is it possible to change that slighly.

I would like to have 2 product pages. Category 1 will have the current opencart product page and category 2 will a similar page.

All I want is that if a product is created in category 1 - product page 1 is loaded and if a product is created in category 2 is loaded - product page 2 is loaded.

Thanks :)

Newbie

Posts

Joined
Fri Jun 07, 2013 1:15 am

Post by dinan » Mon Nov 11, 2013 3:35 pm

jcsmithy wrote:Copy the product.tpl file and adjust to what you want.

Now presuming the product_id of this item is always going to be the same, what you can do is this...

In the controller\product\product.php file, find this:

Code: Select all

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';
}
and change it to something like this

Code: Select all

if($this->request->get['product_id'] == '123') {  // If ID matches this, use this new template
   if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product_new.tpl')) {
      $this->template = $this->config->get('config_template') . '/template/product/product_new.tpl';
   } else {
      $this->template = 'default/template/product/product.tpl';
   }
} else {  // If not, use standard
   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';
   }
}
I was try this:

Code: Select all

      if($category_id == 62 || $category_id == 88 || $category_id == 89 || $category_id == 90 || $category_id == 91 || $category_id == 92 || $category_id == 93 || $category_id == 94 || $category_id == 95 || $category_id == 96 || $category_id == 97 || $category_id == 98 || $category_id == 99 || $category_id == 113 || $category_id == 114 || $category_id == 115 || $category_id == 116 || $category_id == 117 || $category_id == 118 || $category_id == 119 || $category_id == 120 || $category_id == 121 || $category_id == 122 || $category_id == 123 || $category_id == 124 || $category_id == 125 || $category_id == 126 || $category_id == 127 || $category_id == 128 || $category_id == 129 || $category_id == 130 || $category_id == 131 || $category_id == 132 || $category_id == 133 || $category_id == 134){
            if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/adler.tpl')) {
                $this->template = $this->config->get('config_template') . '/template/product/adler.tpl';
            } else {
                $this->template = 'default/template/product/product.tpl';
            }
        }
        else{
            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';
            }
        }
All is ok, but if i use search and open product as search result ther is error :

Undefined variable: category_id in /data/web/virtuals/27798/virtual/www/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 489

Can anyone help me pls? Thanks!

Newbie

Posts

Joined
Tue Oct 26, 2010 2:35 am

Post by TECreasey » Wed Mar 19, 2014 11:33 pm

jcsmithy wrote:Copy the product.tpl file and adjust to what you want.

Now presuming the product_id of this item is always going to be the same, what you can do is this...

In the controller\product\product.php file, find this:

Code: Select all

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';
}
and change it to something like this

Code: Select all

if($this->request->get['product_id'] == '123') {  // If ID matches this, use this new template
   if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product_new.tpl')) {
      $this->template = $this->config->get('config_template') . '/template/product/product_new.tpl';
   } else {
      $this->template = 'default/template/product/product.tpl';
   }
} else {  // If not, use standard
   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';
   }
}
Can this be applied to a manufacturer code so that 1 particular manufacturer has a different product layout to the other product pages?

Thanks.

Newbie

Posts

Joined
Mon Mar 17, 2014 8:43 pm

Post by nfgkid » Thu Jul 03, 2014 9:55 pm

Can you please be more specific with the following? I'm trying to use three different product templates. But, I can't quite figure out the if else statements.

Thanks,
James

if($this->request->get['product_id'] == '1') {
// show template 1
} else if($this->request->get['product_id'] == '2') {
// show template 2
} else if($this->request->get['product_id'] == '3') {
// show template 3
} else if($this->request->get['product_id'] == '4') {
// show template 4
} else {
// show default template
}

Newbie

Posts

Joined
Thu Jul 03, 2014 3:12 am
Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 332 guests