Easy way to make custom fields product tabs (without show_tabular edit)

  • Posts: 86
  • Thank you received: 11
  • Hikashop Business
6 years 10 months ago #272100

-- HikaShop version -- : HikaShop Business 3.1.1 [1706141816]
-- Joomla version -- : 3.7.2

So I've added the following to product/show_tabular:

<li id="hikashop_show_tabular_sizechart_li" class="hikashop_tabs_li ui-corner-top">
    <a onclick="displayTab('hikashop_show_tabular_sizechart');" href="javascript:void(0);">
        <?php echo JText::_('sizechart');?>
    </a>
</li>

and
<div class="hikashop_tabs_content" id="hikashop_show_tabular_sizechart">
<?php echo $this->element->sizechart; ?>
</div>

I have several problems with this method:
A) It's a huge pain to manually enter in each new custom field to show - not something a non-php end user can do on their own and I'm trying to build an idiot proof setup
B) There's no way to hide the tab if there is no content
C) It still doesn't display properly - Ie. the tab I've built just shows the file name for the image custom field

There's got to be an easier way to mark a custom field as a tab and have it display as it does under the specifications tab. Please advise.

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

  • Posts: 26017
  • Thank you received: 4004
  • MODERATOR
6 years 10 months ago #272147

Hello,

A - By using some PHP, you can create a "loop" and display all your product custom fields.

B - By using some PHP, you can skip the empty fields during the loop.

C - By using the proper PHP code ; you'll use the HikaShop field class to display the field content.

You should take a look at the view which currently display the product custom fields in order to see how it is working.
Because what you want to do is almost the same kind of thing ; except that you don't want to display them in a list but as tabs.

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: 86
  • Thank you received: 11
  • Hikashop Business
6 years 10 months ago #272241

I'm sorry but I'm completely lost on what you are trying to tell me.
A - By using some PHP, you can create a "loop" and display all your product custom fields.
What PHP?
B - By using some PHP, you can skip the empty fields during the loop.
What PHP?
C - By using the proper PHP code ; you'll use the HikaShop field class to display the field content.
What PHP?
You should take a look at the view which currently display the product custom fields in order to see how it is working.
Because what you want to do is almost the same kind of thing ; except that you don't want to display them in a list but as tabs.
What view?

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

  • Posts: 81590
  • Thank you received: 13079
  • MODERATOR
6 years 10 months ago #272317

Hi

You want to look at the view file "show_block_custom_main" via the menu Display>Views.
There, you'll see the loop we use, which skips the empty fields, and use the field class to display the field content porperly.
So that's the code you want taken from there :

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>
			</td>
		</tr>
	<?php
	}
}

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

  • Posts: 86
  • Thank you received: 11
  • Hikashop Business
6 years 10 months ago #272331

Got it. This is how I feel the show_tabular file should come out to the box to make clients lives 1000% easier. Thank you for the help.

Sharing for anyone that wants to make tabs from custom fields automatically. Copy/paste over entire /product/show_tabular - custom view

<?php
/**
 * @package	HikaShop for Joomla!
 * @version	3.1.1
 * @author	hikashop.com
 * @copyright	(C) 2010-2017 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php

hikashop_loadJslib('jquery');
$js = '';
$params = null;
$this->params->set('vote_type','product');
if(isset($this->element->main)){
	$product_id = $this->element->main->product_id;
}else{
	$product_id = $this->element->product_id;
}
$this->params->set('vote_ref_id',$product_id);
$this->params->set('productlayout','show_tabular');
$layout_vote_mini = hikashop_getLayout('vote', 'mini', $this->params, $js);
$layout_vote_listing = hikashop_getLayout('vote', 'listing', $this->params, $js);
$layout_vote_form = hikashop_getLayout('vote', 'form', $this->params, $js);
$config =& hikashop_config();
$status_vote = $config->get('enable_status_vote');
$this->setLayout('show_block_dimensions');
$specif_tab_content = trim($this->loadTemplate());
if(!empty($this->fields)){
	$this->setLayout('show_block_custom_main');
	$specif_tab_content .= trim($this->loadTemplate());
}

?>
<div id="hikashop_product_top_part" class="hikashop_product_top_part">
<?php if(!empty($this->element->extraData->topBegin)) { echo implode("\r\n", $this->element->extraData->topBegin); } ?>
	<h1>
		<span id="hikashop_product_name_main" class="hikashop_product_name_main" itemprop="name"><?php
			if (hikashop_getCID('product_id')!=$this->element->product_id && isset ($this->element->main->product_name))
				echo $this->element->main->product_name;
			else
				echo $this->element->product_name;
		?></span>
<?php if ($this->config->get('show_code')) { ?>
		<span id="hikashop_product_code_main" class="hikashop_product_code_main" itemprop="sku">
			<span id="hikashop_product_code_main" class="hikashop_product_code_main"><?php
				echo $this->element->product_code;
			?></span>
		</span>
<?php } ?>
	</h1>
<?php if(!empty($this->element->extraData->topEnd)) { echo implode("\r\n", $this->element->extraData->topEnd); } ?>
<?php
	$this->setLayout('show_block_social');
	echo $this->loadTemplate();
?>
</div>
<div class="hk-row-fluid">
<div id="hikashop_product_left_part" class="hikashop_product_left_part hkc-md-6">
<?php
	if(!empty($this->element->extraData->leftBegin)) { echo implode("\r\n", $this->element->extraData->leftBegin); }

	$this->row =& $this->element;
	$this->setLayout('show_block_img');
	echo $this->loadTemplate();
?>
	<div id="hikashop_product_description_main_mini" class="hikashop_product_description_main_mini"><?php
		if(!empty($this->element->product_description)) {
			$resume = substr(strip_tags(preg_replace('#<hr *id="system-readmore" */>.*#is','',$this->element->product_description)),0,300);
			if (!empty($this->element->product_description) && strlen($this->element->product_description)>300)
				$resume .= " ...<a href='#hikashop_show_tabular_description'>".JText::_('READ_MORE')."</a>";
			echo JHTML::_('content.prepare',$resume);
		}
	?></div>
<?php
	if(!empty($this->element->extraData->leftEnd))
		echo implode("\r\n",$this->element->extraData->leftEnd);
?>
</div>
<div id="hikashop_product_right_part" class="hikashop_product_right_part hkc-md-6">
<?php
	if(!empty($this->element->extraData->rightBegin))
		echo implode("\r\n",$this->element->extraData->rightBegin);
?>
	<span id="hikashop_product_price_main" class="hikashop_product_price_main" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<?php
	if($this->params->get('show_price') && (empty($this->displayVariants['prices']) || $this->params->get('characteristic_display') != 'list')) {
		$this->row =& $this->element;
		$this->setLayout('listing_price');
		echo $this->loadTemplate();

?>
		<meta itemprop="availability" content="http://schema.org/<?php echo ($this->row->product_quantity != 0) ? 'InStock' : 'OutOfstock' ;?>" />
<?php
		$CurrId = hikashop_getCurrency();
		$null = null;
		$currency = $this->currencyHelper->getCurrencies($CurrId, $null);
		$CurrCode = $currency[$CurrId]->currency_code;
?>
		<meta itemprop="priceCurrency" content="<?php echo $CurrCode; ?>" />
<?php
	}
?>
	</span><br />
	<div id="hikashop_product_vote_mini" class="hikashop_product_vote_mini">
<?php
	if($this->params->get('show_vote_product') == '-1') {
		$this->params->set('show_vote_product', $config->get('show_vote_product'));
	}
	if($this->params->get('show_vote_product')) {
		echo $layout_vote_mini;
	}
?>
	</div>
<?php
	if($this->params->get('characteristic_display') != 'list') {
		$this->setLayout('show_block_characteristic');
		echo $this->loadTemplate();
?>
		<br />
<?php
	}

	$form = ',0';
	if(!$this->config->get('ajax_add_to_cart', 1)) {
		$form = ',\'hikashop_product_form\'';
	}
	if(hikashop_level(1) && !empty ($this->element->options)) {
?>
		<div id="hikashop_product_options" class="hikashop_product_options"><?php
			$this->setLayout('option');
			echo $this->loadTemplate();
		?></div>
		<br />
<?php
		$form = ',\'hikashop_product_form\'';
		if ($this->config->get('redirect_url_after_add_cart', 'stay_if_cart') == 'ask_user') {
?>
		<input type="hidden" name="popup" value="1"/>
<?php
		}
	}
	if (!$this->params->get('catalogue') && ($this->config->get('display_add_to_cart_for_free_products') ||  ($this->config->get('display_add_to_wishlist_for_free_products', 1) && hikashop_level(1) && $this->params->get('add_to_wishlist') && $config->get('enable_wishlist', 1)) || !empty ($this->element->prices))) {
		if (!empty ($this->itemFields)) {
			$form = ',\'hikashop_product_form\'';
			if ($this->config->get('redirect_url_after_add_cart', 'stay_if_cart') == 'ask_user') {
?>
		<input type="hidden" name="popup" value="1"/>
<?php
			}
			$this->setLayout('show_block_custom_item');
			echo $this->loadTemplate();
		}
	}
	$this->formName = $form;
	if($this->params->get('show_price')) {
?>
		<span id="hikashop_product_price_with_options_main" class="hikashop_product_price_with_options_main"></span>
<?php
	}
?>
	<div id="hikashop_product_contact_main" class="hikashop_product_contact_main">
<?php
	$contact = $this->config->get('product_contact', 0);
	if(hikashop_level(1) && ($contact == 2 || ($contact == 1 && !empty($this->element->product_contact)))) {
		$css_button = $this->config->get('css_button', 'hikabtn');
?>
			<a href="<?php echo hikashop_completeLink('product&task=contact&cid=' . (int)$this->element->product_id . $this->url_itemid); ?>" class="<?php echo $css_button; ?>"><?php
				echo JText::_('CONTACT_US_FOR_INFO');
			?></a>
<?php
	}
?>
	</div>
<?php
	if(!empty($this->element->extraData->rightMiddle))
		echo implode("\r\n",$this->element->extraData->rightMiddle);
?>
	<span id="hikashop_product_id_main" class="hikashop_product_id_main">
		<input type="hidden" name="product_id" value="<?php echo $this->element->product_id; ?>" />
	</span>
	<br />
<?php if(empty ($this->element->characteristics) || $this->params->get('characteristic_display') != 'list') { ?>
		<div id="hikashop_product_quantity_main" class="hikashop_product_quantity_main"><?php
			$this->row = & $this->element;
			$this->ajax = 'if(hikashopCheckChangeForm(\'item\',\'hikashop_product_form\')){ return hikashopModifyQuantity(\'' . $this->row->product_id . '\',field,1' . $form . ',\'cart\'); } else { return false; }';
			$this->setLayout('quantity');
			echo $this->loadTemplate();
		?></div>
<?php
	}

	$this->setLayout('show_block_product_files');
	echo $this->loadTemplate();

	if(HIKASHOP_J30) {
		$this->setLayout('show_block_tags');
		echo $this->loadTemplate();
	}

	if(!empty($this->element->extraData->rightEnd))
		echo implode("\r\n",$this->element->extraData->rightEnd);
?>
</div>
</div>
	<input type="hidden" name="cart_type" id="type" value="cart"/>
	<input type="hidden" name="add" value="1"/>
	<input type="hidden" name="ctrl" value="product"/>
	<input type="hidden" name="task" value="updatecart"/>
	<input type="hidden" name="return_url" value="<?php echo urlencode(base64_encode(urldecode($this->redirect_url)));?>"/>
</form>

<div id="hikashop_product_bottom_part" class="hikashop_product_bottom_part show_tabular">
	<div id="hikashop_tabs_div">
		<ul class="hikashop_tabs_ul">
			<li id="hikashop_show_tabular_description_li" class="hikashop_tabs_li ui-corner-top"><?php echo JText::_('PRODUCT_DESCRIPTION');?></li>
<?php if(!empty($specif_tab_content)) { ?>

<?php } ?>
          <?php 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;
	?>
          	<li id="hikashop_show_tabular_<?php echo $oneExtraField->field_namekey;?>_li" class="hikashop_tabs_li ui-corner-top"><?php echo $oneExtraField->field_realname;?></li>
          
                	<?php
	}
}
?>
<?php if(in_array($status_vote, array('comment', 'two', 'both'))) { ?>
			<li id="hikashop_show_tabular_comment_li" class="hikashop_tabs_li ui-corner-top"><?php echo JText::_('PRODUCT_COMMENT');?></li>
			<li id="hikashop_show_tabular_new_comment_li" class="hikashop_tabs_li ui-corner-top"><?php echo JText::_('PRODUCT_NEW_COMMENT');?></li>
<?php } ?>
		</ul>

<?php
		if(!empty($this->element->extraData->bottomBegin))
			echo implode("\r\n",$this->element->extraData->bottomBegin);
?>
		<div class="hikashop_tabs_content" id="hikashop_show_tabular_description">
			<div id="hikashop_product_description_main" class="hikashop_product_description_main" itemprop="description"><?php
				echo JHTML::_('content.prepare',preg_replace('#<hr *id="system-readmore" */>#i','',$this->element->product_description));
			?></div>
			<span id="hikashop_product_url_main" class="hikashop_product_url_main"><?php
				if (!empty ($this->element->product_url)) {
					echo JText :: sprintf('MANUFACTURER_URL', '<a href="' . $this->element->product_url . '" target="_blank">' . $this->element->product_url . '</a>');
				}
			?></span>
		</div>
		<?php if(!empty($specif_tab_content)) { ?>

                <?php 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;
	?>
	<div class="hikashop_tabs_content" id="hikashop_show_tabular_<?php echo $oneExtraField->field_namekey;?>">
      <div id="hikashop_product_custom_info_main" class="hikashop_product_custom_info_main">
      <?php echo $this->fieldsClass->show($oneExtraField,$value); ?>
      </div>
      </div>
                      	<?php
	}
}
?>
		<?php }
if($status_vote == "comment" || $status_vote == "two" || $status_vote == "both" ) { ?>
		<form action="<?php echo hikashop_currentURL() ?>" method="post" name="adminForm_hikashop_comment_form" id="hikashop_comment_form">
<?php
			if(!empty($this->element->extraData->bottomMiddle))
				echo implode("\r\n",$this->element->extraData->bottomMiddle);
?>
			<div class="hikashop_tabs_content" id="hikashop_show_tabular_comment">
				<div id="hikashop_vote_listing" data-votetype="product" class="hikashop_product_vote_listing"><?php
					echo $layout_vote_listing;
				?></div>
			</div>
			<div class="hikashop_tabs_content" id="hikashop_show_tabular_new_comment">
				<div id="hikashop_vote_form" data-votetype="product" class="hikashop_product_vote_form"><?php
					echo $layout_vote_form;
				?></div>
			</div>
		</form>
<?php } ?>
<input type="hidden" name="selected_tab" id="selected_tab" value="hikashop_show_tabular_description"/>
<?php
	if(!empty($this->element->extraData->bottomEnd))
		echo implode("\r\n",$this->element->extraData->bottomEnd);
?>
	</div>
</div>
<script type="text/javascript">
if(typeof(hkjQuery) == "undefined") window.hkjQuery = window.jQuery;
window.hikashop.ready(function(){
	var selectedTab = hkjQuery( "#selected_tab" ).val();
	hkjQuery("#hikashop_tabs_div").children("div").css("display","none");
	hkjQuery("#"+selectedTab+"_li").addClass("hikashop_tabs_li_selected");
	hkjQuery("#"+selectedTab).css("display","inherit");
	hkjQuery("#hikashop_tabs_div .hikashop_tabs_ul li").click(function(){
		var currentLi = hkjQuery(this).attr("id");
		var currentDiv = currentLi.replace("_li","");
		hkjQuery("#hikashop_tabs_div").children("div").css("display","none");
		hkjQuery("#hikashop_tabs_div").children("form").children("div").css("display","none");
		hkjQuery("#"+currentDiv).css("display","inherit");
		hkjQuery(".hikashop_tabs_li_selected" ).removeClass("hikashop_tabs_li_selected");
		hkjQuery("#"+currentLi).addClass("hikashop_tabs_li_selected");
	});
});
</script>

Last edit: 6 years 10 months ago by simplecms.

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

  • Posts: 81590
  • Thank you received: 13079
  • MODERATOR
6 years 10 months ago #272338

Hi,

Actually, most of the merchants want custom product fields in one tab, like it is by default with the tabular display.
Because you often want precise custom product fields information so that you can then use filters on them on the products listing in order to easily find what you're looking for. That's why it's not like that out of the box.

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

Time to create page: 0.068 seconds
Powered by Kunena Forum