Page 1 of 1
Opencart 3.x category id in product page
Posted: Mon Jun 14, 2021 7:18 pm
by Emanuel.C
Hi,
I want to display on the product page the id of the category to which it belongs.
thank you
Re: Opencart 3.x category id in product page
Posted: Mon Jun 14, 2021 7:24 pm
by straightlight
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:
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.
Re: Opencart 3.x category id in product page
Posted: Tue Jun 15, 2021 4:44 pm
by paulfeakins
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?
Re: Opencart 3.x category id in product page
Posted: Tue Jun 15, 2021 5:35 pm
by xxvirusxx
I think want that on admin side...product_list
Re: Opencart 3.x category id in product page
Posted: Tue Jun 15, 2021 5:42 pm
by Emanuel.C
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
Re: Opencart 3.x category id in product page
Posted: Tue Jun 15, 2021 5:59 pm
by Emanuel.C
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:
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
Re: Opencart 3.x category id in product page
Posted: Tue Jun 15, 2021 7:10 pm
by straightlight
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:
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.
Re: Opencart 3.x category id in product page
Posted: Wed Jun 16, 2021 10:57 pm
by Emanuel.C
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:
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
Re: Opencart 3.x category id in product page
Posted: Thu Jun 17, 2021 1:28 am
by straightlight
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.