Display Custom Fields in Product Listing

  • Posts: 95
  • Thank you received: 1
  • Hikashop Business
9 years 8 months ago #164980

Hi,

I was trying to find how to display the custom fields of the products , not only inside the product, but in the product listing menu. In the configuration and in the content menu I have enabled the custom fields but they only appear inside the product. Do we have any option for this?

Thanks in advance

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

  • Posts: 13201
  • Thank you received: 2322
9 years 8 months ago #164986

Hi,

Do you mean custom fields of the table "product" ?
If it is, you can edit the view "product / listing_img_title" and add the code:

<?php echo $this->row->CUSTOMFILED_NAME; ?>
At the desired place and the value of the custom field will be displayed on the listing.

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

  • Posts: 30
  • Thank you received: 0
8 years 6 months ago #216127

Hello! Could you please help me? What should I add
1) to display the name of the field
2) to display all the fields automatically, if it's possible

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

  • Posts: 81509
  • Thank you received: 13064
  • MODERATOR
8 years 6 months ago #216134

Hi,

In that case you can do like that:

<?php
$fieldClass = hikashop_get('class.field');
$productFields = $fieldClass->getFields('frontcomp', $this->row, 'product', 'checkout&task=state');
foreach ($productFields as $fieldName => $oneExtraField) {
 $value = '';
 if(isset($this->row->$fieldName))
  $value = trim($this->row->$fieldName);
 if(!empty($value) || $value === '0') {
  echo $fieldClass->getFieldName($oneExtraField);
  echo $fieldClass->show($oneExtraField,$value);
 }
}
?>

Last edit: 8 years 6 months ago by nicolas. Reason: fixed typo

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

  • Posts: 30
  • Thank you received: 0
8 years 6 months ago #217197

Hi, nicolas! Sorry for the late answer. Thank you for the support, but there is an error somewhere in your code. After this hack product page looks like this: joxi.ru/brREnYPUKEb8A1
Without it: joxi.ru/Dr8W9NJTw5bEA6

If i modify the last string like this:

echo $fieldClass->show($oneExtraField,$value);
, it works, but it prints only the first field.

Last edit: 8 years 6 months ago by withram.

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

  • Posts: 81509
  • Thank you received: 13064
  • MODERATOR
8 years 6 months ago #217203

Hi,

Yes, there was a typo. Sorry for that.
I however, don't see why only the first field would display. Are you sure that the others are activated to be displayed on the frontend?

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

  • Posts: 30
  • Thank you received: 0
8 years 6 months ago #217286

Yes, other fields are displayed at the product page.

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

  • Posts: 81509
  • Thank you received: 13064
  • MODERATOR
8 years 6 months ago #217318

Hi,

Can you provide some screenshot of the settings of these custom fields ?

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

  • Posts: 30
  • Thank you received: 0
8 years 5 months ago #219595

Hi! I continue Hikashop customizing, so this feature is still actual.
Now it seems that your code have some mistake in
" if(!empty($value) || $value === '0')"
If i remove this string, I can see customfields names. But values are still unavailable. Maybe the mistake is in "$value"?
Where can I find the list of Hikashop methods and variables?

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

  • Posts: 26000
  • Thank you received: 4004
  • MODERATOR
8 years 5 months ago #219598

Hi,

I checked the Nicolas code and I looks good ; there is no issue with the line you mentionned. On the contrary, the line is required.

www.hikashop.com/support/support/documen...r-documentation.html

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 30
  • Thank you received: 0
8 years 5 months ago #219899

Ok, thanks, guys. I thinks this is our issue.

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

Time to create page: 0.090 seconds
Powered by Kunena Forum