Insert a Custom Field Image

  • Posts: 41
  • Thank you received: 0
8 years 7 months ago #237368

-- url of the page with the problem -- : www.mybodygraph.com
-- HikaShop version -- : 2.6.2
-- Joomla version -- : 3.4.8
-- PHP version -- : 5.5.33

I'm trying to get a image from a Ajax Image custom field. I did't find any documentation on this so I copied the code from show_block_img but I don't get it to work.

the file I'm working in is product/show_default.php, the image that gets displayed is from something totally different and it simply seem to ignore the path and filename, can you guys guide me how to do this in a correct way? Here is the code I'm using right now:

$variant_name = '';
$variant_main = '_main';
$height = (int)$this->config->get('product_image_y');
$width = (int)$this->config->get('product_image_x');

echo $this->image->display('/media/com_hikashop/upload/safe/', true, $this->element->product_display,'id="hikashop_main_image'.$variant_name.'" style="margin-top:10px;margin-bottom:10px;display:inline-block;vertical-align:middle"','id="hikashop_main_image_link"', $width,  $height);

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
8 years 7 months ago #237378

Hi,

That's not how you should do it at all.
You should load the custom field settings and then use the custom field class to display the field value. So supposing that it is a custom field of the table "product":

$fieldClass = hikashop_get('class.field');
$field = $fieldClass->getField('product_display', 'product');
echo $fieldClass->show($field,$this->element->product_display);

The following user(s) said Thank You: Jovian

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

  • Posts: 41
  • Thank you received: 0
8 years 7 months ago #237535

Thank you, that returns a thumbnail of the image! But we also need to set the size of the image in the PHP ourself depending on this and that, how can we do that?

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
8 years 7 months ago #237541

Hi,

In that case, you can do like that:

$fieldClass = hikashop_get('class.field');
$field = $fieldClass->getField('product_display', 'product');
echo str_replace(array('thumbnail_x=100','thumbnail_y=100'),array('thumbnail_x='.$width,'thumbnail_y='.$height),$fieldClass->show($field,$this->element->product_display));

The following user(s) said Thank You: Jovian

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

Time to create page: 0.060 seconds
Powered by Kunena Forum