Extra field Link Option

  • Posts: 147
  • Thank you received: 6
8 years 10 months ago #226619

-- HikaShop version -- : 2.6.1

I need to create a link to samples in the product display.
I am using the extra fields' link plugin field - however the url link display is too long - is their a link field or a different field type that can be used to shorten the link url? I have tried an <a href in the link field to generate a text display, but, that does not work.

Example:
< a href="http:// ... ">Display Field < / a >

thanks

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
8 years 10 months ago #226639

Hi,

The idea would be to update the HikaShop link field (in the classes/field.php file).
With a code like

	$link = $value;
	$text = $value;
	 if(preg_match('#"([^"]+)":(.*)#iU', $value, $m)) {
		$link = $m[2];
		$text = $m[1];
	}
	return '<a'.$target.' href="'.$this->trans($link).'">'.$this->trans($text).'</a>';
It would support special format for the links

"Display field":http://website/link.html
"Display field":/link.html


Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 147
  • Thank you received: 6
8 years 10 months ago #227015

Hello Jerome, thanks for your help,

I have attempted to add the script you suggested.

I dont believe i have added to the correct class

$fieldtype->load($field->field_table);

		if(!empty($fieldtype->externalOptions) && isset($fieldtype->allValues[$field->field_type])) {

			$linkedOptions = $fieldtype->allValues[$field->field_type]['options'];

			foreach($fieldtype->externalOptions as $key => $extraOption) {

				if(in_array($key, $linkedOptions)) {

					$o = is_array($extraOption) ? $extraOption['obj'] : $extraOption->obj;

					if(is_string($o))

						$o = new $o();



					if(method_exists($o, 'save'))

						$o->save($fieldOptions);
						
//wrina add //
	$link = $value;
	$text = $value;
	 if(preg_match('#"([^"]+)":(.*)#iU', $value, $m)) {
		$link = $m[2];
		$text = $m[1];
	}
	return '<a'.$target.' href="'.$this->trans($link).'">'.$this->trans($text).'</a>';
//end add//
						
						

				}

			}

		}
Q. Where should the statement be placed? I dont believe the additional has affected the view, as it looks similar to the output that was rendered prior.
The script links to the external url, but the display text is doubled and displays a symbol. see image.

Thanks,
Wrina
Wrina
Thanks

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 10 months ago #227046

Hi,

I think that Jerome meant that you should improve the link type class:

class hikashopLink extends hikashopText {
	function show(&$field,$value) {
		$target = '';
		if(isset($field->field_options['target_blank']) && $field->field_options['target_blank'] == '1')
			$target = ' target="_blank"';
		return '<a'.$target.' href="'.$this->trans($value).'">'.$this->trans($value).'</a>';
	}
}
So that it would be more adapted to your needs.

Please Log in or Create an account to join the conversation.

Time to create page: 0.056 seconds
Powered by Kunena Forum