Post by Emanuel.C » Mon Jun 14, 2021 7:18 pm

Hi,
I want to display on the product page the id of the category to which it belongs.

thank you

New member

Posts

Joined
Mon Mar 25, 2019 5:26 pm

Post by straightlight » Mon Jun 14, 2021 7:24 pm

Emanuel.C wrote:
Mon Jun 14, 2021 7:18 pm
Hi,
I want to display on the product page the id of the category to which it belongs.

thank you
OC version.

The category ID is already included in the breadcrumb menu. However, if you want to display the number (which would not have much value to the page itself nor customers), in your catalog/controller/product/product.php file,

find:

Code: Select all

if ($category_info) {
				$url = '';
add below:

Code: Select all

$data['category_id'] = $category_id;
to display your main category ID in your product.twig file. I would suggest to add a TWIG condition in the mean time to ensure the category ID can indeed be displayed based on the URL.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by paulfeakins » Tue Jun 15, 2021 4:44 pm

Emanuel.C wrote:
Mon Jun 14, 2021 7:18 pm
I want to display on the product page the id of the category to which it belongs.
Just the number? Surely that's not going to be great for customers?

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Guru Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by xxvirusxx » Tue Jun 15, 2021 5:35 pm

I think want that on admin side...product_list

My converted modules | Buy me a beer | Opencart upgrade service


User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România

Post by Emanuel.C » Tue Jun 15, 2021 5:42 pm

paulfeakins wrote:
Tue Jun 15, 2021 4:44 pm
Emanuel.C wrote:
Mon Jun 14, 2021 7:18 pm
I want to display on the product page the id of the category to which it belongs.
Just the number? Surely that's not going to be great for customers?
I don't want customers to see the category ID on the product page.
I need to display the category ID on the product page, because I only want to display text for a few categories.
And I thought that if I display the category ID on the product page, I can add a css for the products where I need to display the text

New member

Posts

Joined
Mon Mar 25, 2019 5:26 pm

Post by Emanuel.C » Tue Jun 15, 2021 5:59 pm

straightlight wrote:
Mon Jun 14, 2021 7:24 pm
Emanuel.C wrote:
Mon Jun 14, 2021 7:18 pm
Hi,
I want to display on the product page the id of the category to which it belongs.

thank you
OC version.

The category ID is already included in the breadcrumb menu. However, if you want to display the number (which would not have much value to the page itself nor customers), in your catalog/controller/product/product.php file,

find:

Code: Select all

if ($category_info) {
				$url = '';
add below:

Code: Select all

$data['category_id'] = $category_id;
to display your main category ID in your product.twig file. I would suggest to add a TWIG condition in the mean time to ensure the category ID can indeed be displayed based on the URL.

I started as you said yes it did not display in the product page the category id.
I want to display the category id in the product page so that I can add custom css depending on which category the product belongs to


I started doing that:

{% if (categories) %}
{% for category in categories %}
{% if category.category_id %}
<a>{{category.name}}:{{category.category_id}}<a><br>
{% endif %}
{% endfor %}
{% endif %}


if there are products and subcategory, double my box.
displays the correct ID category, but doubles for each subcategory they appear

New member

Posts

Joined
Mon Mar 25, 2019 5:26 pm

Post by straightlight » Tue Jun 15, 2021 7:10 pm

Emanuel.C wrote:
Tue Jun 15, 2021 5:59 pm
straightlight wrote:
Mon Jun 14, 2021 7:24 pm
Emanuel.C wrote:
Mon Jun 14, 2021 7:18 pm
Hi,
I want to display on the product page the id of the category to which it belongs.

thank you
OC version.

The category ID is already included in the breadcrumb menu. However, if you want to display the number (which would not have much value to the page itself nor customers), in your catalog/controller/product/product.php file,

find:

Code: Select all

if ($category_info) {
				$url = '';
add below:

Code: Select all

$data['category_id'] = $category_id;
to display your main category ID in your product.twig file. I would suggest to add a TWIG condition in the mean time to ensure the category ID can indeed be displayed based on the URL.

I started as you said yes it did not display in the product page the category id.
I want to display the category id in the product page so that I can add custom css depending on which category the product belongs to


I started doing that:

{% if (categories) %}
{% for category in categories %}
{% if category.category_id %}
<a>{{category.name}}:{{category.category_id}}<a><br>
{% endif %}
{% endfor %}
{% endif %}


if there are products and subcategory, double my box.
displays the correct ID category, but doubles for each subcategory they appear
Simply use an extension for that: https://www.opencart.com/index.php?rout ... n_id=10979 and convert it.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Emanuel.C » Wed Jun 16, 2021 10:57 pm

straightlight wrote:
Tue Jun 15, 2021 7:10 pm
Emanuel.C wrote:
Tue Jun 15, 2021 5:59 pm
straightlight wrote:
Mon Jun 14, 2021 7:24 pm


OC version.

The category ID is already included in the breadcrumb menu. However, if you want to display the number (which would not have much value to the page itself nor customers), in your catalog/controller/product/product.php file,

find:

Code: Select all

if ($category_info) {
				$url = '';
add below:

Code: Select all

$data['category_id'] = $category_id;
to display your main category ID in your product.twig file. I would suggest to add a TWIG condition in the mean time to ensure the category ID can indeed be displayed based on the URL.

I started as you said yes it did not display in the product page the category id.
I want to display the category id in the product page so that I can add custom css depending on which category the product belongs to


I started doing that:

{% if (categories) %}
{% for category in categories %}
{% if category.category_id %}
<a>{{category.name}}:{{category.category_id}}<a><br>
{% endif %}
{% endfor %}
{% endif %}


if there are products and subcategory, double my box.
displays the correct ID category, but doubles for each subcategory they appear
Simply use an extension for that: https://www.opencart.com/index.php?rout ... n_id=10979 and convert it.
The module you say is compatible with the opencart version less than 2

This module is not compatible with my version of opencart.
My opencart version is 3.0.2.0

New member

Posts

Joined
Mon Mar 25, 2019 5:26 pm

Post by straightlight » Thu Jun 17, 2021 1:28 am

Emanuel.C wrote:
Wed Jun 16, 2021 10:57 pm
straightlight wrote:
Tue Jun 15, 2021 7:10 pm
Emanuel.C wrote:
Tue Jun 15, 2021 5:59 pm



I started as you said yes it did not display in the product page the category id.
I want to display the category id in the product page so that I can add custom css depending on which category the product belongs to


I started doing that:

{% if (categories) %}
{% for category in categories %}
{% if category.category_id %}
<a>{{category.name}}:{{category.category_id}}<a><br>
{% endif %}
{% endfor %}
{% endif %}


if there are products and subcategory, double my box.
displays the correct ID category, but doubles for each subcategory they appear
Simply use an extension for that: https://www.opencart.com/index.php?rout ... n_id=10979 and convert it.
The module you say is compatible with the opencart version less than 2

This module is not compatible with my version of opencart.
My opencart version is 3.0.2.0
There are three words right before the end of the sentence on the instructions. Please read them.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 17 guests