Display Custom Field

  • Posts: 28
  • Thank you received: 4
2 months 1 hour ago #337323

-- HikaShop version -- : 4.4.4
-- Joomla version -- : 3.10.3
-- PHP version -- : 7.4
-- Browser(s) name and version -- : Chome

Hi.
For some reason, I want to manually display my categories Ajax image extrafield.

My extrafield name is "img2"
and I used an image named "tree.jpg" for example

when I put the code
$this->element->img2;

I the file name correctly but I need the full path of image to as the src of my img tag.

how can I get the extrafield with correct tag and not plain file name ??

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

  • Posts: 74595
  • Thank you received: 11508
  • MODERATOR
1 month 4 weeks ago #337329

Hi,

Supposing we're talking about a custom field of the table "category", you need code like that:

<?php
	$fieldClass = hikashop_get('class.field');
	$field = $fieldClass->getField('img2', 'category');
	echo $fieldClass->show($field,$this->element->img2);
?>

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

  • Posts: 28
  • Thank you received: 4
1 month 4 weeks ago #337331

Thank you.

I put this code in "listing_img_title.php" file and got the following error :

0 - Call to undefined method hikashop::show()

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

  • Posts: 74595
  • Thank you received: 11508
  • MODERATOR
1 month 4 weeks ago #337332

Hi,

I don't see how the code I gave can generate that error message.
Either you made a typo, or the error comes from somewhere else.
Please double check.
And if you don't see the problem, please activate the debug system setting of the Joomla configuration and try again. You'll get an error with more information on what's going on. In that case, please also provide a screenshot of the modification you've made.

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

  • Posts: 28
  • Thank you received: 4
1 month 4 weeks ago #337356

I checked the code multi times.

the error refers to the third line of the code :
echo $fieldClass->show($field,$this->element->img2);

when I comment this code, error message disappears

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

  • Posts: 28
  • Thank you received: 4
1 month 4 weeks ago #337357

I turned on debug system and atached the screenshot :

Attachments:

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

  • Posts: 28
  • Thank you received: 4
1 month 4 weeks ago #337358

That was a kiddy mistake by me ... the code worked perfect. thank you.

my last question is can i use this code for product page as well by replacing the field name and changing 'category' to 'product' ?

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

  • Posts: 74595
  • Thank you received: 11508
  • MODERATOR
1 month 4 weeks ago #337362

Hi,

Well, it depends what you mean.
If you want to display the value of a custom field of the table "category" for the category of the current product, it's possible but you need to leave "category" in that code. Instead you want to change

$this->element
by
$this->categories[0]
If you want to display the value of a custom field of the table "product" for the current product, it's possible and you indeed need to change "category" to "product". However, if your product has variants, $this->element will point to the default variant of the product and $this->element->main will point to the main product. So you might need to change that, or make it dynamically use main or not based on weither it's there or not.

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

  • Posts: 28
  • Thank you received: 4
1 month 4 weeks ago #337364

Thanks alot.

Everything is solved

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

Time to create page: 0.070 seconds
Powered by Kunena Forum