Page 1 of 1
Adding HTML to the Product Attributes OC 3.x Guide
Posted: Fri Apr 05, 2019 6:23 pm
by cssninjah
Greetings everyone,
here is my short guide to solving a common problem with the lack of support for outputting html content in product custom attributes.
Advantages of my approach are:
- No headache
- No plugins
So all we need is just a single file that located
/catalog/model/catalog/product.php. Find this code around line 319:
Code: Select all
foreach ($product_attribute_query->rows as $product_attribute) {
$product_attribute_data[] = array(
'attribute_id' => $product_attribute['attribute_id'],
'name' => $product_attribute['name'],
'text' => $product_attribute['text']
);
}
and replace last key => value like this:
Code: Select all
'text' => html_entity_decode($product_attribute['text'], ENT_QUOTES, 'UTF-8')
Voila. Now you able to put your HTML in custom product attribute field from admin area and get correct output that you can easily beautify via css
Re: Adding HTML to the Product Attributes OC 3.x Guide
Posted: Mon Apr 08, 2019 8:22 am
by straightlight
/catalog/model/catalog/products.php
Except that this PHP file does not exist from the controller or model folders originally. The singular filename does.
Re: Adding HTML to the Product Attributes OC 3.x Guide
Posted: Tue Apr 09, 2019 8:27 pm
by cssninjah
straightlight wrote: ↑Mon Apr 08, 2019 8:22 am
/catalog/model/catalog/products.php
Except that this PHP file does not exist from the controller or model folders originally. The singular filename does.
um, I accidentally made a typo and already fixed it. soz.
incorrect path is
/catalog/model/catalog/products.php
and correct path is almost the same as above, but without "s" in filename
/catalog/model/catalog/product.php
image below is clickable.
Re: Adding HTML to the Product Attributes OC 3.x Guide
Posted: Thu Nov 07, 2019 12:23 pm
by adifyz
can you use the twig editor in 3.0.3.2 is so where do I find, in not where do I find php ?
Best regards
Re: Adding HTML to the Product Attributes OC 3.x Guide
Posted: Thu Nov 07, 2019 3:17 pm
by OSWorX
adifyz wrote: ↑Thu Nov 07, 2019 12:23 pm
can you use the twig editor in 3.0.3.2 is so where do I find, in not where do I find php ?
Beside the fact that what you are posting is not understandable, why should someone use a twig editor when you have to edit a php file?
Re: Adding HTML to the Product Attributes OC 3.x Guide
Posted: Sun Nov 24, 2019 2:43 am
by adifyz
OSWorX wrote: ↑Thu Nov 07, 2019 3:17 pm
adifyz wrote: ↑Thu Nov 07, 2019 12:23 pm
can you use the twig editor in 3.0.3.2 is so where do I find, in not where do I find php ?
Beside the fact that what you are posting is not understandable, why should someone use a twig editor when you have to edit a php file?
I was asking if you could edit the twig file to enter "Adding HTML to the Product Attributes OC 3.x," instead of the php file., and if so where ? (using the twig editor I thought was a easier way just from within admin area)
if Not ....does it have to be in the php file.
Best Regards
Re: Adding HTML to the Product Attributes OC 3.x Guide
Posted: Sun Nov 24, 2019 4:22 am
by OSWorX
1. do still not know what do you understand as "twig editor" .. ?
Guess you mean the template editor in the backend.
2. whenever possible try to avoid to edit template files (as of OpenCart 3.x the template engine is twig, therefore these files end with .twig)
What if you change once the template?
Therefore the solution above is the correct one.
(beside this, editing the code inside the .twig file will cost you much more effort - but can be done).
Re: Adding HTML to the Product Attributes OC 3.x Guide
Posted: Fri Dec 13, 2019 2:27 pm
by Andrei_kve
Thank you, cssninjah! The code works fine and is very helpful!
Thumbs up!
Re: Adding HTML to the Product Attributes OC 3.x Guide
Posted: Sat Jul 18, 2020 10:35 pm
by harap
'text' => html_entity_decode($product_attribute['text'], ENT_QUOTES, 'UTF-8')
Tested the code is also working for OC 2.2.0 in line 309.
Thank you!
Re: Adding HTML to the Product Attributes OC 3.x Guide
Posted: Mon Oct 30, 2023 6:28 am
by katalin
cssninjah wrote: ↑Fri Apr 05, 2019 6:23 pm
Greetings everyone,
here is my short guide to solving a common problem with the lack of support for outputting html content in product custom attributes.
Advantages of my approach are:
- No headache
- No plugins
So all we need is just a single file that located
/catalog/model/catalog/product.php. Find this code around line 319:
Code: Select all
foreach ($product_attribute_query->rows as $product_attribute) {
$product_attribute_data[] = array(
'attribute_id' => $product_attribute['attribute_id'],
'name' => $product_attribute['name'],
'text' => $product_attribute['text']
);
}
and replace last key => value like this:
Code: Select all
'text' => html_entity_decode($product_attribute['text'], ENT_QUOTES, 'UTF-8')
Voila. Now you able to put your HTML in custom product attribute field from admin area and get correct output that you can easily beautify via css
Thanks for the info. How about for Journal3 theme, what file do we need to modify because I can't seem to figure it out.