Pragmatism in code

This tutorial shows you how to add a drop down custom field to your products that links to other content. This is useful if you want to include links to common content such as warrantee or license details.

When creating the content you simply select the relevant custom field value from the drop down. However, when the product is displayed, instead of simply showing the custom field text a link is displayed.

It is not possible to insert a link when creating the custom field via the admin panel as the input is sanitized so the information needs to be inserted via an SQL manager such as phpMyAdmin.

To insert the information first create your custom drop down as normal via the 'Display > Custom Fields' menu item in the admin panel. Note that you will need to insert some arbitrary text in the title field we will change this later.

Next open up phpMyAdmin or whatever your favourite flavour of SQL editor is and browse to the #__hikashop_field table.

Next search or browse and locate the custom field you just created. HINT: The field_realname field will contain the title.

Open the field in the editor.

You will notice that the field_value field contains all of the value from the drop down that you entered in the admin panel - like this

MIT::MIT license::0

The part you need to change is the part in the centre, in this case the part that says 'MIT license'. Simply change this for a full HTML link, for example <a target="_blank" href="">MIT license

Now it should read

MIT::<a target="_blank" href="">MIT license::0

Save your edits and then go and test. When you visit the product listing in the front end the custombfield should now display as a link.

NOTE: There is one caveat with this method. If you edit the custom field in the administration panel the modification will be overwritten as the content will be automatically sanitized.