Post by sonico67 » Thu Jun 20, 2013 10:47 pm

Hi,

I'd like to show a certain text if the user is in a specified category in the Product page.

Any help is appreciated.

I'm using OC 1.5.5.1.
Last edited by sonico67 on Wed Jul 03, 2013 4:23 am, edited 1 time in total.

New member

Posts

Joined
Wed Apr 13, 2011 9:58 pm

Post by Qphoria » Fri Jun 21, 2013 1:25 am

(1.5.5.1)

1. EDIT: catalog/controller/product/product.php

2. FIND:

Code: Select all

$category_id = (int)array_pop($parts);
3. AFTER, ADD:

Code: Select all

$this->data['category_id'] = $category_id;
4. EDIT: catalog/view/theme/YOURTHEME/template/product/product.tpl

5. Wherever you want the message, use:

Code: Select all

<?php if (isset($category_id) && $category_id = '999')) { ?>
Some Text here
<?php } ?>

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by sonico67 » Fri Jun 21, 2013 3:12 am

The text appears regardless of the category I'm in.

Note: I removed one parenthesis from the code above.

New member

Posts

Joined
Wed Apr 13, 2011 9:58 pm

Post by SelfMan » Fri Jun 21, 2013 9:44 am

I think a small bug is in the code:

Code: Select all

<?php if (isset($category_id) && $category_id == '999')) { ?>
Some Text here
<?php } ?>

New member

Posts

Joined
Thu Dec 01, 2011 8:01 am

Post by sonico67 » Fri Jun 21, 2013 10:06 pm

It works, Thanks. There is however an undefined variable notice at the top of the page unless you're in a category. So say if I go to the product directly from the home page, I would see that error. xD

The code I used for the tpl is:

Code: Select all

<?php if (isset($category_id) && $category_id == '999') { ?>
Yes
<?php } else { ?>
No
<?php } ?>

New member

Posts

Joined
Wed Apr 13, 2011 9:58 pm

Post by sonico67 » Tue Jul 02, 2013 10:06 pm

I solved it by using product_id instead of category_id, and so far it's working great. My main purpose was to modify products in a certain category but doing it this way works regardless of the URL so I don't mind specifying each product I want changed.

One file needs to be modified: product.tpl

Code: Select all

<?php if ($product_id == '74' || $product_id == '73' || $product_id == '65') { ?>
Yes
<?php } else { ?>
No
<?php } ?>
Thanks to Qphoria and SelfMan for your support!

New member

Posts

Joined
Wed Apr 13, 2011 9:58 pm

Post by SelfMan » Wed Jul 03, 2013 7:31 am

How about:

Code: Select all

<?php if (in_array($product_id ,array(74,73,65), true)) { ?>
Yes
<?php } else { ?>
No
<?php } ?>

New member

Posts

Joined
Thu Dec 01, 2011 8:01 am

Post by sonico67 » Wed Jul 03, 2013 10:04 pm

I did a little digging based on your answer SelfMan, certainly is better with arrays. Thanks again :)

Code: Select all

<?php if (in_array($this->request->get['product_id'], array (74,73,65))) { ?>
Yes
<?php } else { ?>
No
<?php } ?>

New member

Posts

Joined
Wed Apr 13, 2011 9:58 pm

Post by Osobase » Thu Mar 13, 2014 10:37 pm

For those who will find this helpful, try this:

Step 1: Open the file /catalog/controller/product/product.php

Search for:

Code: Select all

$product_info = $this->model_catalog_product->getProduct($product_id);
...and immediately below that line, add this:

Code: Select all

$categories = $this->model_catalog_product->getCategories($product_info['product_id']);
if ($categories){
	$categories_info = $this->model_catalog_category->getCategory($categories[0]['category_id']);
	$this->data['category_id'] = $categories_info['category_id'];
}
Step 2: Open the file /catalog/view/theme/YOUR-THEME/template/product/product.tpl

...and insert the following code where you want it:

Code: Select all

<?php if (isset($category_id) && $category_id == '999') { ?>
Put whatever you fancy here...
<?php } ?>

Newbie

Posts

Joined
Thu Mar 13, 2014 6:34 pm


Post by Publican » Sun Jul 13, 2014 1:45 am

I am looking to list the children of certain category's on my product page, for example.

=========
Grape > Merlot
Country > Chilli
=========

So it would list Merlot & Chilli on the product page?

Image
Buy Wine Online


New member

Posts

Joined
Wed Sep 04, 2013 2:20 pm

Post by Cue4cheap » Sun Dec 27, 2015 9:08 am

I know this is old but what if you want to do the same for a specific parent category? That would show something no matter what the child category is just so long as the parent is category 1?

Thank you,

Mike

cue4cheap not cheap quality


Active Member

Posts

Joined
Fri Sep 20, 2013 4:45 am
Who is online

Users browsing this forum: No registered users and 40 guests