How to create several blocks of custom fields

  • Posts: 61
  • Thank you received: 5
  • Hikashop Business
2 weeks 1 day ago #366666

-- HikaShop version -- : 5.1.5
-- Joomla version -- : 5.2.6
-- PHP version -- : 8.4.5

I have some questions about custom fields for the product page.

1. is there a way to create multiple blocks or sections with custom fields? Let's say I want to create three sections. Each section should contain four to five text fields (read only). These sections should be displayed as ‘separate’ sections so that the customer can read them in a structured way. I'm talking about sections like ‘Technical Data’, ‘Ingredients’ and so on.

The big problem is that all custom product fields are listed as a long list one after the other - regardless of what kind of content I want to display. How can I create individual sections?

2. is there a way to use the Joomla core custom fields to display some information? That would make it massively easier. I'm only talking about text information here, i.e. nothing would need to be calculated with these types of custom fields.

3. Or - would it be possible to create a "characteristics" table - where I could note some technical information? I do not want to create variants but have the customer to inform about several product data (in a structured way).

4. How to display specific custom fields at a specific place? In my case, I created a field "bottle deposit". This field must be displayed right after the price. But in all display types of the product page (standard, table, reversed) all custom fields are in one html structure, like ul or table. I can not exclude one specific custom field value to display it on a specific location inside the product page. Or did I oversee something to achive this?

Btw. the "view builder" does not help because even there are no way to move several blocks of custom fields to different locations.

Last edit: 2 weeks 1 day ago by Rusty.

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

  • Posts: 83674
  • Thank you received: 13545
  • MODERATOR
2 weeks 1 day ago #366667

Hi,

1. One easy way to go about it is to create custom fields of the type "custom text" as group separators.

2. Using Joomla custom fields is not possible. First, it's really hard to integrate. And even if that was possible to integrate them, it wouldn't help you display static information. You're much better with using custom fields of the type "custom text", they are made for this purpose.

3. Characteristics won't help. It will be better to use custom product fields. They are made for this.

4. If you want to display a field somewhere else than the normal area of the product details page, you'll have to add custom code where you want the field to appear.
The code is quite simple:

<?php echo $this->element->XXX;?>
where XXX is to be replaced by the column name of the field. Then, you can display the display setting of the field so that it doesn't also appear in the fields area where all the other fields appear.

Last edit: 2 weeks 1 day ago by nicolas.
The following user(s) said Thank You: Rusty

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

  • Posts: 61
  • Thank you received: 5
  • Hikashop Business
2 weeks 1 day ago #366680

nicolas wrote: 4. If you want to display a field somewhere else than the normal area of the product details page, you'll have to add custom code where you want the field to appear.
The code is quite simple:
<?php echo $this->element->XXX;?>
where XXX is to be replaced by the column name of the field. Then, you can display the display setting of the field so that it doesn't also appear in the fields area where all the other fields appear.


Thank you! This helps a lot! :cheer:

Last edit: 2 weeks 1 day ago by Rusty.

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

  • Posts: 61
  • Thank you received: 5
  • Hikashop Business
1 week 1 day ago #366792

Hi @nicolas,

for the reason (discussed before) I created a new section in product / show_block_dimensions ... like this:

<!-- PFAND -->
<span id="pfand">zzgl. Pfand: <?php echo $this->element->pfand ?> &#x20AC;<br/></span>
<!-- EO PFAND -->

This works but has a problem: If the value (pfand) is empty, the text (zzgl. Pfand) is still displayed. Which is technically correct, I know! But I want to display the whole line only if it contains a value. So I tried the following:
<!-- PFAND -->
<?php
	if(!empty($this->element->pfand) { ?>
        <span id="pfand">zzgl. Pfand: <?php echo $this->element->pfand ?> &#x20AC;<br/></span>
	<?php
	}
?>
<!-- EO PFAND -->
But it doesn't work. I get the error:

ERROR 0 - syntax error, unexpected token "{" in /path_to_website/templates/astroid_template_two_ghc/html/com_hikashop/product/show_block_dimensions.php:44


This is line 44:
if(!empty($this->element->pfand) { ?>

What did I wrong?

Cheers
Rusty

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

  • Posts: 83674
  • Thank you received: 13545
  • MODERATOR
1 week 1 day ago #366793

Hi,

You're almost there.
A big rule of programming (and calculus in general) is that when you open something, you need to close it.
On this line, you have 2 open parenthesis but only 1 closing parenthesis.
That's why PHP gives you the error "unexpected token "{" ". It expects a closing parenthesis before the { and doesn't find it.
Add a second one right after the first one and it will work.

The following user(s) said Thank You: Rusty

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

  • Posts: 61
  • Thank you received: 5
  • Hikashop Business
1 week 1 day ago #366795

nicolas wrote: You're almost there.

I knew it! :-D
Thank you!

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

Time to create page: 0.064 seconds
Powered by Kunena Forum