Get Text of Custom Field in Product Layout

  • Posts: 15
  • Thank you received: 3
2 years 2 months ago #339428

Hi everyone!
Some weeks ago I contacted Hika Shop because my filter was not working correctly on some items. Apparently, the issue was, that the values contained special Charakters like ö,ü,ß,ä and spaces. So I rewrote the select dropdown like this:

Value:
niederoestereich
Text:
Niederösterreich

But the problem now is, that on the product detail page the value is shown instead of the text.
So in database and for the filters I need the value to be used, for the Product display I need to show the text.

I need the same for selecting related articles in the product were I have a selection like
value = url and label = Regionname and I want to put it on the product datailpage somewhat like that:

<a href="<?php echo $this->row->region->value; ?>"><?php echo $this->row->region->text; ?></a>

How can I solve this?

thanks!

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

  • Posts: 81540
  • Thank you received: 13070
  • MODERATOR
2 years 2 months ago #339434

Hi,

It would have been great if you could have provided a screenshot of the settings of the custom field.

Supposing that your custom field is of one of the type "single dropdown", "multiple dropdown", "radio" or "checkbox", to get the titles of the values on the product details page, and supposing that the product doesn't have variants, you can use such code:

<?php
$fieldClass = hikashop_get('class.field');
$field = $fieldClass->getField('xxx', 'product');
echo $fieldClass->show($field,$this->element->xxx);
?>
where xxx is the column name of the custom field.

So, if I understand correctly, you have a URL for the value, and the label of the link as title.
In that case, the code will probably look like this:
<?php
$fieldClass = hikashop_get('class.field');
$field = $fieldClass->getField('xxx', 'product');
?>
<a href="<?php echo $this->element->xxx; ?>"><?php echo $fieldClass->show($field,$this->element->xxx); ?></a>

Last edit: 2 years 2 months ago by nicolas.

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

  • Posts: 15
  • Thank you received: 3
2 years 2 months ago #339438

Thank you, Nicolas!
I tried with your code but it did not work and gave me a php error.
Call to a member function getField() on null

However, I managed to make it work like that - do you think my solution is ok?

$myField = $this->element->winery;
$field = $this->fields->field_value[$myField]->value;

<a href="/winery/<?php echo $myField; ?>" title="More about <?php echo $field; ?>"><?php echo $field; ?></a>

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

  • Posts: 81540
  • Thank you received: 13070
  • MODERATOR
2 years 2 months ago #339440

Hi,

That error indicates that you made a typo while writting the code.
Anyways, yes you can do it like that too.
My method is just a bit cleaner as it handles more things (like translations of the titles).

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

  • Posts: 15
  • Thank you received: 3
2 years 2 months ago #339448

Thank you Nicolas, much appreciated! Maybe it was the double semicolon in the example. But great that we have two examples now for others to find how to do it :-)

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

Time to create page: 0.056 seconds
Powered by Kunena Forum