Custom fields placement in category listing.

  • Posts: 6
  • Thank you received: 1
  • Hikashop Business
2 years 2 months ago #347768

-- HikaShop version -- : 4.7.0
-- Joomla version -- : 4
-- PHP version -- : 8.1
-- Browser(s) name and version -- : firefox latest

Hi,

I'm using business version and on the category listing for products I have a number of custom fields.

I found the file associated with the view (listing_img_title) and in it is the code (see bottom of posting)
which calls the custom fields.

However it puts them in a block and I'd like to be able to split them up. So I looking for a way to keep the backend options for displaying the fields (ie "Display in listing etc) but be able to put individual fields elswhere in the layout.

I've done this on the product page but can't work out the code changes needed for the listing.

Thanks for any help

Denis


<!-- CUSTOM PRODUCT FIELDS -->
<?php
if(!empty($this->productFields)) {
	foreach($this->productFields as $fieldName => $oneExtraField) {
		if(empty($this->row->$fieldName) && (!isset($this->row->$fieldName) || $this->row->$fieldName !== '0'))
			continue;

		if(!empty($oneExtraField->field_products)) {
			$field_products = is_string($oneExtraField->field_products) ? explode(',', trim($oneExtraField->field_products, ',')) : $oneExtraField->field_products;
			if(!in_array($this->row->product_id, $field_products))
				continue;
		}
?>
	<dl class="hikashop_product_custom_<?php echo $oneExtraField->field_namekey;?>_line">
		<dt class="hikashop_product_custom_name">
			<?php echo $this->fieldsClass->getFieldName($oneExtraField);?>
		</dt>
		<dd class="hikashop_product_custom_value">
			<?php echo $this->fieldsClass->show($oneExtraField,$this->row->$fieldName); ?>
		</dd>
	</dl>
<?php
	}
}
?>
<!-- EO CUSTOM PRODUCT FIELDS -->

Last edit: 2 years 2 months ago by nicolas.

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

  • Posts: 83338
  • Thank you received: 13476
  • MODERATOR
2 years 2 months ago #347770

Hi,

You can copy/paste that code in different places in the layout.
Then, after the line:

foreach($this->productFields as $fieldName => $oneExtraField) {
you can add the code:
if(!in_array($fieldName, array('XXX','YYY','ZZZ'))) continue;
where XXX, YYY and ZZZ are the column name of three fields you want to display in the current location.

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

  • Posts: 6
  • Thank you received: 1
  • Hikashop Business
2 years 2 months ago #347785

Thank you so much Nicolas.

Worked like a charm.

Happy Holidays.

Denis

The following user(s) said Thank You: nicolas

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

Time to create page: 0.038 seconds
Powered by Kunena Forum