Page 1 of 1

[SOLVED] How to insert Hyperlink in product attribute?

Posted: Mon Nov 28, 2011 4:33 pm
by salehjoon
Is there a way to put a clickable link in product attributes? I tried to put a link to an image in the attribute but the result is a text displaying the html code.

Enable html formating in atributes

Posted: Mon Nov 28, 2011 6:32 pm
by wolfsteritory
v 1.5.1

i want to enable html formatting for different product attributes

what do i have to modify & where ?

Re: How to insert Hyperlink in product attribute?

Posted: Tue Nov 29, 2011 12:14 am
by uksitebuilder
edit: admin/model/catalog/product.php

find 2 X occurrences of

Code: Select all

foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) {
add after both occurrences

Code: Select all

$product_attribute_description['text'] = html_entity_decode($product_attribute_description['text'], ENT_QUOTES, 'UTF-8');

Re: How to insert Hyperlink in product attribute?

Posted: Tue Nov 29, 2011 3:29 am
by salehjoon
I did what you said but it didn't work.

first occurrence

Code: Select all

		if (isset($data['product_attribute'])) {
			foreach ($data['product_attribute'] as $product_attribute) {
				if ($product_attribute['attribute_id']) {
					$this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "'");
					
					foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) {				
//added the following line to enable html in product attribute description	
					$product_attribute_description['text'] = html_entity_decode($product_attribute_description['text'], ENT_QUOTES, 'UTF-8');		
//end of the code for adding html text.
						$this->db->query("INSERT INTO " . DB_PREFIX . "product_attribute SET product_id = '" . (int)$product_id . "', attribute_id = '" . (int)$product_attribute['attribute_id'] . "', language_id = '" . (int)$language_id . "', text = '" .  $this->db->escape($product_attribute_description['text']) . "'");
					}
				}
			}
		}
second occurrence:

Code: Select all

		if (!empty($data['product_attribute'])) {
			foreach ($data['product_attribute'] as $product_attribute) {
				if ($product_attribute['attribute_id']) {
					$this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "'");
					
					foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) {	
//added the following line to enable html in product attribute description	
					$product_attribute_description['text'] = html_entity_decode($product_attribute_description['text'], ENT_QUOTES, 'UTF-8');		
//end of the code for adding html text.						
						$this->db->query("INSERT INTO " . DB_PREFIX . "product_attribute SET product_id = '" . (int)$product_id . "', attribute_id = '" . (int)$product_attribute['attribute_id'] . "', language_id = '" . (int)$language_id . "', text = '" .  $this->db->escape($product_attribute_description['text']) . "'");
					}
				}
			}
		}

Re: How to insert Hyperlink in product attribute?

Posted: Tue Nov 29, 2011 3:55 am
by dony_b
uksitebuilder wrote:edit: admin/model/catalog/product.php

find 2 X occurrences of

Code: Select all

foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) {
add after both occurrences

Code: Select all

$product_attribute_description['text'] = html_entity_decode($product_attribute_description['text'], ENT_QUOTES, 'UTF-8');
Oh thats cool to add a unique link for each product ....

Re: How to insert Hyperlink in product attribute?

Posted: Tue Nov 29, 2011 6:52 am
by uksitebuilder
it should work salejoon

I tested it before posting (something I very rarely do lol)

Your code looks correct too, so not sure what else to suggest.

Maybe you have vqmod installed with useCache set to True.

If so, clear your vqmod/vqcache folder

Re: How to insert Hyperlink in product attribute?

Posted: Tue Nov 29, 2011 7:19 am
by dony_b
Works for me

Re: How to insert Hyperlink in product attribute?

Posted: Tue Nov 29, 2011 1:08 pm
by salehjoon
Okay it worked. I'm not sure what went wrong there. I think I had two different product.php files open and uploaded the wrong one. Thank you very much!

Re: [SOLVED] How to insert Hyperlink in product attribute?

Posted: Thu Jan 26, 2012 4:04 pm
by PlusCybernet
@ uksitebuilder ... Thanks for this information.

Re: [SOLVED] How to insert Hyperlink in product attribute?

Posted: Mon Mar 05, 2012 4:38 am
by thehumancpu
I think 1.5.2 broke this mod. I had it working, updated to 1.5.2, then re-did mod to the file and does not function.

Re: How to insert Hyperlink in product attribute?

Posted: Sun Nov 25, 2012 8:47 pm
by Phil_L
uksitebuilder wrote:edit: admin/model/catalog/product.php

find 2 X occurrences of

Code: Select all

foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) {
add after both occurrences

Code: Select all

$product_attribute_description['text'] = html_entity_decode($product_attribute_description['text'], ENT_QUOTES, 'UTF-8');

would be wicked if this was some sort of Vqmod or even in the next iteration of the core. :-))

Re: How to insert Hyperlink in product attribute?

Posted: Tue Jan 21, 2014 7:06 am
by rwalker
uksitebuilder wrote:edit: admin/model/catalog/product.php

find 2 X occurrences of

Code: Select all

foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) {
add after both occurrences

Code: Select all

$product_attribute_description['text'] = html_entity_decode($product_attribute_description['text'], ENT_QUOTES, 'UTF-8');
Thanks for this works well on 1.5.1!

I'm attempting to show the attribute next to the price following this thread: http://forum.opencart.com/viewtopic.php?f=139&t=50476 this is what I've got:

Code: Select all

<!-- Start Additional Info -->
  <?php if ($attribute_groups) { ?>
    <?php foreach ($attribute_groups as $attribute_group) { ?>
      <?php if ($attribute_group['name'] == 'Product Info') { ?>
        <?php foreach ($attribute_group['attribute'] as $attribute) { ?>
          <span><?php echo $attribute['name']; ?></span> <?php echo html_entity_decode($attribute['text'], ENT_QUOTES, 'UTF-8'); ?><br />
        <?php } ?>
      <?php } ?>
    <?php } ?>
  <?php } ?>
  <!-- End Additional Info -->
It doesn't want to show. Am I missing something?

Thanks,

Rian

Re: [SOLVED] How to insert Hyperlink in product attribute?

Posted: Thu Jan 21, 2016 6:54 pm
by masterbeta
for reference on 2.1.0.1 for options descriptions to make links the code in 2 places on options.php is this:

Code: Select all

$option_value_description['name'] = html_entity_decode($option_value_description['name'], ENT_QUOTES, 'UTF-8');
edit***

i've also added it in a 3rd place under the edit function...

however, when going to edit the option, i cannot edit the html code - so i have to delete the entire option (and remove from product first) and re-add a new one with code.... a bit tedious, unless someone else has an idea?

thanks in advance

Re: How to insert Hyperlink in product attribute?

Posted: Fri Aug 23, 2019 7:51 pm
by sedra
uksitebuilder wrote:
Tue Nov 29, 2011 12:14 am
edit: admin/model/catalog/product.php

find 2 X occurrences of

Code: Select all

foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) {
add after both occurrences

Code: Select all

$product_attribute_description['text'] = html_entity_decode($product_attribute_description['text'], ENT_QUOTES, 'UTF-8');
thank you.
it works beatifully on OC 3.0.2.0