Hi Nicolas, thank you !
I am trying to add this code to the view product/show_block_custom_main.php using Hikshop – Configuration – Display - Views
Native code from Hikashop before changes is as following:
<?php
/**
* @package HikaShop for Joomla!
* @version 4.2.3
* @author hikashop.com
* @copyright (C) 2010-2020 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' || $oneExtraField->field_type == 'customtext') {
$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>
</td>
</tr>
<?php
}
}
$specifFields = ob_get_clean();
if($displayTitle){
?>
<div id="hikashop_product_custom_info_main" class="hikashop_product_custom_info_main">
<?php
if($this->productlayout != 'show_tabular') {
?>
<h4><?php echo JText::_('SPECIFICATIONS');?></h4>
<?php
}
?>
<table class="hikashop_product_custom_info_main_table">
<?php echo $specifFields; ?>
</table>
</div>
<?php }
Code after changes is as following:
<?php
/**
* @package HikaShop for Joomla!
* @version 4.2.3
* @author hikashop.com
* @copyright (C) 2010-2020 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' || $oneExtraField->field_type == 'customtext') {
$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>
</td>
</tr>
<?php
}
}
$specifFields = ob_get_clean();
if($displayTitle){
?>
<div class="g-grid">
<div class="g-block size-25">
<?php echo $this->fieldsClass->getFieldName($this->fields['color']);?>
<?php echo $this->fieldsClass->show($this->fields['color'],$this->element->color); ?>
</div>
<div class="g-block size-25">
<?php echo $this->fieldsClass->getFieldName($this->fields['format']);?>
<?php echo $this->fieldsClass->show($this->fields['format'],$this->element->format); ?>
</div>
<div class="g-block size-25">
<?php echo $this->fieldsClass->getFieldName($this->fields['width']);?>
<?php echo $this->fieldsClass->show($this->fields['width'],$this->element->width); ?>
</div>
<div class="g-block size-25">
<?php echo $this->fieldsClass->getFieldName($this->fields['size']);?>
<?php echo $this->fieldsClass->show($this->fields['size'],$this->element->size); ?>
</div>
</div>
<div id="hikashop_product_custom_info_main" class="hikashop_product_custom_info_main">
<?php
if($this->productlayout != 'show_tabular') {
?>
<h4><?php echo JText::_('SPECIFICATIONS');?></h4>
<?php
}
?>
<table class="hikashop_product_custom_info_main_table">
<?php echo $specifFields; ?>
</table>
</div>
<?php }
After I changed the code I recognize two problems:
a) names of custom fields are presented even if there is no values of custom fields (name shouldn’t be displayed if custom field has no value)
b) additionally when custom field is not a text field type – for example multiple dropdown or single dropdown usage of this code caused a white screen with error message “0 Call to undefined method hikashop::getFieldName()”
Could you help me with this issues ?
Regards,
Greg