- Posts: 15
- Thank you received: 3
Get Text of Custom Field in Product Layout
- coolcatcreations
-
Topic Author
- Offline
Less
More
4 years 7 months ago #339428
by coolcatcreations
Get Text of Custom Field in Product Layout was created by coolcatcreations
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:
How can I solve this?
thanks!
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:
Code:
<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.
4 years 7 months ago - 4 years 7 months ago #339434
by nicolas
Replied by nicolas on topic Get Text of Custom Field in Product Layout
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:
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:
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:
Code:
<?php
$fieldClass = hikashop_get('class.field');
$field = $fieldClass->getField('xxx', 'product');
echo $fieldClass->show($field,$this->element->xxx);
?>
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:
Code:
<?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: 4 years 7 months ago by nicolas.
Please Log in or Create an account to join the conversation.
- coolcatcreations
-
Topic Author
- Offline
Less
More
- Posts: 15
- Thank you received: 3
4 years 7 months ago #339438
by coolcatcreations
Replied by coolcatcreations on topic Get Text of Custom Field in Product Layout
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>
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.
4 years 7 months ago #339440
by nicolas
Replied by nicolas on topic Get Text of Custom Field in Product Layout
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).
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.
- coolcatcreations
-
Topic Author
- Offline
Less
More
- Posts: 15
- Thank you received: 3
4 years 7 months ago #339448
by coolcatcreations
Replied by coolcatcreations on topic Get Text of Custom Field in Product Layout
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.185 seconds