Post by cssninjah » 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 ;)
Last edited by cssninjah on Tue Apr 09, 2019 8:16 pm, edited 1 time in total.

User avatar
Newbie

Posts

Joined
Fri Mar 29, 2019 7:59 pm

Post by straightlight » 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.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by cssninjah » Tue Apr 09, 2019 8:27 pm

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.
Image

User avatar
Newbie

Posts

Joined
Fri Mar 29, 2019 7:59 pm

Post by adifyz » 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 ?
Best regards

Newbie

Posts

Joined
Wed Oct 02, 2019 9:57 am

Post by OSWorX » 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?

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator
Online

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by adifyz » Sun Nov 24, 2019 2:43 am

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

Newbie

Posts

Joined
Wed Oct 02, 2019 9:57 am

Post by OSWorX » Sun Nov 24, 2019 4:22 am

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).

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator
Online

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by Andrei_kve » Fri Dec 13, 2019 2:27 pm

Thank you, cssninjah! The code works fine and is very helpful!
Thumbs up! ;)

Newbie

Posts

Joined
Thu Oct 19, 2017 5:51 pm

Post by harap » Sat Jul 18, 2020 10:35 pm

'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!

Active Member

Posts

Joined
Wed Sep 16, 2015 12:34 am
Location - United States

Post by katalin » Mon Oct 30, 2023 6:28 am

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.

Active Member

Posts

Joined
Wed May 05, 2010 2:28 am
Who is online

Users browsing this forum: No registered users and 1 guest