how to add the image from a custom field into the product detail view

  • Posts: 307
  • Thank you received: 22
3 weeks 2 days ago #368234

-- HikaShop version -- : 6.1.0
-- Joomla version -- : 5.3.3
-- PHP version -- : 8

Hi,
I'm trying to make an image visible on the product detail page that comes from a custom field (name is productheaderfoto) with the type product > image
Have uploaded a demo image but it's not showing up when I try to show it with this code:

      <?php if (!empty($this->element->productheaderfoto)) : ?>
<div class="productheaderfoto">
<img src="/images/com_hikashop/upload/safe/<?php echo htmlspecialchars($this->element->productheaderfoto, ENT_QUOTES, 'UTF-8'); ?>"
alt="<?php echo htmlspecialchars($this->element->product_name, ENT_QUOTES, 'UTF-8'); ?>" />
</div>
<?php endif; ?>

I'm no progammer so my borrowed code is probably not the way for this type of field?

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

  • Posts: 84304
  • Thank you received: 13698
  • MODERATOR
3 weeks 1 day ago #368235

Hi,

What is the type of the field ?
If it's "text" and you enter the filename of the image in the text input field, then your code will work.
However, if it's "AJAX image", then it cannot work like that. You need to ask HikaShop's class.field to show the img tag for you:
www.hikashop.com/forum/product-category-...t-layout.html#339434
So, for example:

      <?php if (!empty($this->element->productheaderfoto)) : ?>
<div class="productheaderfoto">
<?php
$fieldClass = hikashop_get('class.field');
$field = $fieldClass->getField('productheaderfoto', 'product');
echo $fieldClass->show($field,$this->element->productheaderfoto);
?>
</div>
<?php endif; ?>

The following user(s) said Thank You: nico.van.leeuwen

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

  • Posts: 307
  • Thank you received: 22
3 weeks 1 day ago #368236

Thank you, that works perfectly. Is was indeed the ajax version.

A small thing but it would be a nice addition if the images that you upload that way would have a max-width when you show the preview in the backend. Now it's going all over the place because this image is pretty big :-)

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

  • Posts: 84304
  • Thank you received: 13698
  • MODERATOR
2 weeks 6 days ago #368242

Hi,

Thanks for your feedback. However, why you use the "Thumbnails dimensions" setting of the custom field to restrict the size of the thumbnails there ?

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

  • Posts: 307
  • Thank you received: 22
2 weeks 6 days ago #368245

I'm not sure if we are talking about the same thing here.

I mean that when I have created a custom field of the type product > Image I can upload a photo (in my case 1200 pixels wide).

This results in a very big image when editing the product. 2 screenshots attached as example.

My suggestion is only to make the uploaded image (preview) ftt a bit nices in the backend when editing a product. Maybe I explained it a bit poorly ;-)

Attachments:

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

  • Posts: 84304
  • Thank you received: 13698
  • MODERATOR
2 weeks 6 days ago #368246

Hi,

Oh, ok.
I thought you were talking about a custom field of the type "AJAX image" since you said in a previous message here that we were indeed talking about a "AJAX Image" field. But on your new screenshot, it's the "Image" type, which is completely different.

I see what you mean now. Indeed, we could add a bit of CSS by default to avoid this. Thanks for your feedback. I'll do that for a future version of HikaShop.

Ideally, you just want to use the AJAX Image type, which is better in every way.

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

  • Posts: 307
  • Thank you received: 22
2 weeks 6 days ago #368249

Switched to the Ajax version. Thanks for the tip and sorry about the confusion.

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

Time to create page: 0.059 seconds
Powered by Kunena Forum