linkable custom fields values

  • Posts: 54
  • Thank you received: 2
  • Hikashop Business
3 months 1 week ago #307349

-- HikaShop version -- : 4.1.0
-- Joomla version -- : 3.9.6
-- PHP version -- : 7.2.14

Hi, When I define Custom Field and select display on front-end as Yes, information about this Custom Field (label + value) is visible on Product Page in specification section. Is it possible to have linkable value of such custom field presented in Product specification on Product Page ? which will work as a filter and after clicking on this link to go to the Products Listing Page, where will be presented only products which have this given value of this custom field ?

Regards,
Greg

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

  • Posts: 66841
  • Thank you received: 9874
  • MODERATOR
3 months 1 week ago #307350

Hi,

Not ithout a bit of programming.
You would have to create a filter on that custom field in the Display>Filters menu. Then, turn on the "redirect POST mode" setting of the HikaShop configuration. When you use the filter on the products listing, you should see the URL change with the value of the custom field selected in the URL.
Then, you would have to modify a view file of the product page ( www.hikashop.com/support/documentation/1...-display.html#layout ). And in there, you would add your link with a bit of PHP:

<a href="XXX<?php echo $this->element->YYY; ?>ZZZ"><?php echo $this->element->YYY; ?></a>
where XXX is the beginning of the filtering URL up until the value, ZZZ the end of the filtering URL from the end of the value, and YYY the column name of the custom field.

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

  • Posts: 54
  • Thank you received: 2
  • Hikashop Business
3 months 1 week ago #307387

Hi Nicolas, thank you for the explanation – your proposal is ok, however if I have more than one custom field on Product Page Specification this link appear next to all values of all custom fields – what should I change to have different link for different custom fields ?

I have attached image how it looks at this moment (red "White" is a link generated by the code).



Please find also below php file with code added
<?php
/**
 * @package	HikaShop for Joomla!
 * @version	4.1.0
 * @author	hikashop.com
 * @copyright	(C) 2010-2019 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php
$this->fieldsClass->prefix = '';
$displayTitle = false;
ob_start();
foreach ($this->fields as $fieldName => $oneExtraField) {
	$value = '';
	if(empty($this->element->$fieldName) && !empty($this->element->main->$fieldName))
		$this->element->$fieldName = $this->element->main->$fieldName;
	if(isset($this->element->$fieldName))
		$value = trim($this->element->$fieldName);

	if(!empty($value) || $value === '0') {
		$displayTitle = true;
	?>
		<tr class="hikashop_product_custom_<?php echo $oneExtraField->field_namekey;?>_line">
			<td class="key">
				<span id="hikashop_product_custom_name_<?php echo $oneExtraField->field_id;?>" class="hikashop_product_custom_name">
					<?php echo $this->fieldsClass->getFieldName($oneExtraField);?>
				</span>
			</td>
			<td>
				<span id="hikashop_product_custom_value_<?php echo $oneExtraField->field_id;?>" class="hikashop_product_custom_value">
					<?php echo $this->fieldsClass->show($oneExtraField,$value); ?>
				</span>
<a href="/testa2/index.php/en/shop/products?&limitstart=0&filter_Format_1=none&filter_Color_2=<?php echo $this->element->color; ?>"><?php echo $this->element->color; ?></a>
                            
			</td>
		</tr>
	<?php
	}
}
$specifFields = ob_get_clean();
if($displayTitle){
?>

<div id="hikashop_product_custom_info_main" class="hikashop_product_custom_info_main">
	<h4><?php echo JText::_('SPECIFICATIONS');?></h4>
	<table class="hikashop_product_custom_info_main_table">
		<?php echo $specifFields; ?>
	</table>
</div>
<?php }

Regards,
Greg

Attachments:

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

  • Posts: 66841
  • Thank you received: 9874
  • MODERATOR
3 months 1 week ago #307389

Hi,

It's not my code doing that. It's the location where you added it which does that.
You should turn off the display of that custom field (in the settings of the custom field) and move my code at the end of the show_block_custom_item.php view file. You can prepend it with the label of the field.

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

  • Posts: 54
  • Thank you received: 2
  • Hikashop Business
3 months 1 week ago #307450

Hi Nicolas, When all custom fields are turned off blocks show_block_custom_main.php and show_block_custom_item.php does not show up at all
Regards,
Greg

Last edit: 3 months 1 week ago by Greg_C.

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

  • Posts: 66841
  • Thank you received: 9874
  • MODERATOR
3 months 1 week ago #307452

Hi,

Yes. If that's a problem for you, then you should move that code in the show_default (or show_tabular based on which layout you're using) view file, after the if around the call to the show_block_custom_item.php view file.

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

  • Posts: 54
  • Thank you received: 2
  • Hikashop Business
3 months 6 days ago #307547

Hi, ok, thank you
Regards,
Greg

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

Time to create page: 0.069 seconds
Powered by Kunena Forum