- Posts: 141
- Thank you received: 3
custom fields presentation
6 years 6 months ago #317502
by Greg_C
custom fields presentation was created by Greg_C
-- HikaShop version -- : 4.2.3
-- Joomla version -- : 3.9.16
-- PHP version -- : 7.3.1
Hi, I have many custom fields and all of them are presented in description section under the product image in the product page - one custom field under another custom field. So the list is long and presentation it is not ergonomic. I would like to split description section in the product page view for 4 columns and indicate which custom field should be presented in which column.
Now it looks like that:
Product Image
Custom Field 1 name: value
Custom Field 2 name: value
Custom Field 3 name: value
Custom Field 4 name: value
Custom Field 5 name: value
Custom Field 6 name: value
Custom Field 7 name: value
Custom Field 8 name: value
I am looking for a solution to display custom fields like that:
Product Image
Custom Field 1 name: value Custom Field 2 name: value Custom Field 3 name: value Custom Field 4 name: value
Custom Field 5 name: value Custom Field 6 name: value Custom Field 7 name: value Custom Field 8 name: value
I think I can use g-grid in the view code for example:
However all Custom Fields are included in the present Product Page View in these lines:
Because all custom fields are included in the present code without division for particular custom fields I don’t have idea how assign particular custom fields to selected columns. If you can give me a hint how to do it would be a massive help for me.
Regards,
Greg
-- Joomla version -- : 3.9.16
-- PHP version -- : 7.3.1
Hi, I have many custom fields and all of them are presented in description section under the product image in the product page - one custom field under another custom field. So the list is long and presentation it is not ergonomic. I would like to split description section in the product page view for 4 columns and indicate which custom field should be presented in which column.
Now it looks like that:
Product Image
Custom Field 1 name: value
Custom Field 2 name: value
Custom Field 3 name: value
Custom Field 4 name: value
Custom Field 5 name: value
Custom Field 6 name: value
Custom Field 7 name: value
Custom Field 8 name: value
I am looking for a solution to display custom fields like that:
Product Image
Custom Field 1 name: value Custom Field 2 name: value Custom Field 3 name: value Custom Field 4 name: value
Custom Field 5 name: value Custom Field 6 name: value Custom Field 7 name: value Custom Field 8 name: value
I think I can use g-grid in the view code for example:
Code:
<div class="g-grid">
<div class="g-block size-25">
<!—First Published Custom Field -->
<!—Fifth Published Custom Field -->
</div>
<div class="g-block size-25">
<!—Second Published Custom Field -->
<!—Sixth Published Custom Field -->
</div>
<div class="g-block size-25">
<!—Third Published Custom Field -->
<!—Seventh Published Custom Field -->
</div>
<div class="g-block size-25">
<!—Fourth Published Custom Field -->
<!—Eight Published Custom Field -->
</div>
</div>
However all Custom Fields are included in the present Product Page View in these lines:
Code:
<?php echo $this->fieldsClass->getFieldName($oneExtraField);?>
<?php echo $this->fieldsClass->show($oneExtraField,$value); ?>
Because all custom fields are included in the present code without division for particular custom fields I don’t have idea how assign particular custom fields to selected columns. If you can give me a hint how to do it would be a massive help for me.
Regards,
Greg
Please Log in or Create an account to join the conversation.
6 years 6 months ago #317520
by nicolas
Replied by nicolas on topic custom fields presentation
Hi,
I'll give you an example for the first column:
where XXX is the column name for the first custom field you want in the first column, and YYY is the column name for the second custom field you want in the first column.
I'll give you an example for the first column:
Code:
<div class="g-grid">
<div class="g-block size-25">
<?php echo $this->fieldsClass->getFieldName($this->fields['XXX']);?>
<?php echo $this->fieldsClass->show($this->fields['XXX'],$this->element->XXX); ?>
<?php echo $this->fieldsClass->getFieldName($this->fields['YYY']);?>
<?php echo $this->fieldsClass->show($this->fields['YYY'],$this->element->YYY); ?>
</div>
<div class="g-block size-25">
<!—Second Published Custom Field -->
<!—Sixth Published Custom Field -->
</div>
<div class="g-block size-25">
<!—Third Published Custom Field -->
<!—Seventh Published Custom Field -->
</div>
<div class="g-block size-25">
<!—Fourth Published Custom Field -->
<!—Eight Published Custom Field -->
</div>
</div>
Please Log in or Create an account to join the conversation.
6 years 6 months ago #317552
by Greg_C
Replied by Greg_C on topic custom fields presentation
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:
Code after changes is as following:
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
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:
Code:
<?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:
Code:
<?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
Please Log in or Create an account to join the conversation.
6 years 6 months ago #317554
by nicolas
Replied by nicolas on topic custom fields presentation
Hi,
a. Well, you need to adapt the code in order to check if the field is empty. For example:
b. I don't see why the type of the custom field would create that error. And the code you posted doesn't look like it could generate that error either.
I would say that there is probably an error somewhere. The first thing to do is to activate the "error reporting" and "debug mode" settings of the Joomla configuration. That way, you'll get more information on that error, including the line number where the error is happening. That will help you understand where is the problem.
a. Well, you need to adapt the code in order to check if the field is empty. For example:
Code:
<?php
if(!empty($this->element->color) {
echo $this->fieldsClass->getFieldName($this->fields['color']);
echo $this->fieldsClass->show($this->fields['color'],$this->element->color);
}
?>
I would say that there is probably an error somewhere. The first thing to do is to activate the "error reporting" and "debug mode" settings of the Joomla configuration. That way, you'll get more information on that error, including the line number where the error is happening. That will help you understand where is the problem.
Please Log in or Create an account to join the conversation.
6 years 6 months ago #317576
by Greg_C
Replied by Greg_C on topic custom fields presentation
Hi Nicolas,
a. after adding code:
I got a white screen with error message: 0 syntax error, unexpected '{'
please find enclosed information from debug mode - Image 1 for this error message - the line 56 in show_block_custom_main.php is
ad. b - please find enclosed information from debug mode - Image 2 for error message “ 0 Call to undefined method hikashop::getFieldName() ”
the line 58 in show_block_custom_main.php is
Regards,
Greg
a. after adding code:
<?php
if(!empty($this->element->test) {
echo $this->fieldsClass->getFieldName($this->fields);
echo $this->fieldsClass->show($this->fields,$this->element->test);
}
?>
I got a white screen with error message: 0 syntax error, unexpected '{'
please find enclosed information from debug mode - Image 1 for this error message - the line 56 in show_block_custom_main.php is
Code:
if(!empty($this->element->test) {
ad. b - please find enclosed information from debug mode - Image 2 for error message “ 0 Call to undefined method hikashop::getFieldName() ”
the line 58 in show_block_custom_main.php is
Code:
<?php echo $this->fieldsClass->getFieldName($this->fields['color']);?>
Regards,
Greg
Please Log in or Create an account to join the conversation.
6 years 6 months ago #317585
by nicolas
Replied by nicolas on topic custom fields presentation
Hi,
a. Ah, yes the line:
if(!empty($this->element->test) {
shold be:
if(!empty($this->element->test)) {
My bad.
b. This indicates that you don't have a custom field with the column name 'color'.
Please double check.
a. Ah, yes the line:
if(!empty($this->element->test) {
shold be:
if(!empty($this->element->test)) {
My bad.
b. This indicates that you don't have a custom field with the column name 'color'.
Please double check.
The following user(s) said Thank You: Greg_C
Please Log in or Create an account to join the conversation.
6 years 6 months ago #317589
by Greg_C
Replied by Greg_C on topic custom fields presentation
Hi Nicolas,
a. ok, it works !
b. you right - the problem was related with custom fields with status unpublished in Front end
thank you for great support !
Regards,
Greg
a. ok, it works !
b. you right - the problem was related with custom fields with status unpublished in Front end
thank you for great support !
Regards,
Greg
Please Log in or Create an account to join the conversation.
Time to create page: 0.160 seconds