Ajax file custom field display

  • Posts: 349
  • Thank you received: 19
  • Hikashop Business
4 months 2 weeks ago #364749

-- HikaShop version -- : 5.1.2
-- Joomla version -- : 5.2
-- PHP version -- : 8.3.3

Im using product custom field Ajax file for audio mp3 file. Two problems:

1. If I enter in Format for each file field

<audio controls>
  <source src="images/audiosample/{value}" type="audio/mpeg" />
  Your browser does not support the audio tag.
</audio>
the "controls" audio tag is removed after saving the field.

2. How to show that field in template layout override for product?
If I use
<?php echo $this->row->mediafield; ?>
only the value is in html output.
Is there a way to show formated field?

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

  • Posts: 83603
  • Thank you received: 13533
  • MODERATOR
4 months 2 weeks ago #364753

Hi,

1. Thank you for your feedback. I've made a patch to better handle this. Download again the install package of HikaShop on our website and install it on yours to get the patch.

2. Yes. We've covered this here for example:
www.hikashop.com/forum/product-category-...t-layout.html#339434

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

  • Posts: 349
  • Thank you received: 19
  • Hikashop Business
4 months 2 weeks ago #364771

1. OK now.
2. So solution for audio player for ajax file custom field:
In view override place (where "audiotest" is custom field column name)

<?php
$fieldClass = hikashop_get('class.field');
$field = $fieldClass->getField('audiotest', 'product');
echo $fieldClass->show($field,$this->element->audiotest) ;
?>
In format for each file field place code like
<div class="media-preview"><p>Audio preview</p><audio controls>
  <source src="images/audiosample/{value}" type="audio/mpeg" />
  Your browser does not support the audio tag.
</audio></div>
Where images/audiosample is folder for your audio files.
And final result is


This is game changer for custom fields. Thank you Hikashop!

Attachments:
The following user(s) said Thank You: nicolas

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

  • Posts: 349
  • Thank you received: 19
  • Hikashop Business
2 weeks 2 days ago #366489

Nicolas, please help on this.
When viewing a product, I would like to allow customers to directly listen to audio files if they are logged in and have access. The file download works, but the stream does not.
This is the code I am using in the show_block_product_files.php override.

<div id="hikashop_product_files_main" class="hikashop_product_files_main">
<?php
if(!empty($this->element->files)) {
	$user = JFactory::getUser();
	$files = array();
	foreach($this->element->files as $file) {
		if(empty($file->download_link))
			continue;
		if(empty($file->file_name))
			$file->file_name = $file->file_path;
		$attributes = '';
		if(!empty($this->element->product_canonical) && strpos(hikashop_currentURL(),$this->element->product_canonical) && !empty($user->guest)) {
			$attributes .= ' rel="nofollow"';
		}
		$files[] = '<a'.$attributes.' class="hikashop_product_file_link d-none" href="' .  $file->download_link . '">' . $file->file_name . '</a><br/><audio controls><source src="' .  $file->download_link . '" type="audio/mpeg">Vaš brskalnik ne podpira predvajanja zvočnih datotek.</audio><br/><a href="' . $file->download_link . '" class="file-download-link" download>Prenesi datoteko</a>';
	}

	if(count($files)) {
?>
	<fieldset class="hikashop_product_files_fieldset">
		<legend><?php echo JText::_('DOWNLOADS'); ?></legend>
		<?php echo implode('<br/>', $files); ?>
	</fieldset>
<?php
	}
}
?>
</div>

I assume the mp3 preview plugin does not have this option?

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

  • Posts: 83603
  • Thank you received: 13533
  • MODERATOR
2 weeks 2 days ago #366492

Hi,

I don't see a problem with that. It could be a problem with your server setup.
Could you provide the URL of the page with the issue so that I can look deeper into it ?

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

  • Posts: 349
  • Thank you received: 19
  • Hikashop Business
2 weeks 2 days ago #366499

Here is the link, but you must login first to see the player.

This message contains confidential information

Here you can see working preview
This message contains confidential information

Last edit: 2 weeks 2 days ago by mojweb.

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

  • Posts: 83603
  • Thank you received: 13533
  • MODERATOR
2 weeks 2 days ago #366501

Hi,

So could you provide a test user account so that I could check it ?

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

  • Posts: 349
  • Thank you received: 19
  • Hikashop Business
2 weeks 1 day ago #366509

Sure

Last edit: 2 weeks 22 hours ago by mojweb.

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

  • Posts: 83603
  • Thank you received: 13533
  • MODERATOR
2 weeks 1 day ago #366510

It seems the MP3 file you're using on this product is corrupted.
Some players, like VLC can handle corrupted files up to a point. But the players of browsers are more sensitive.

You can use checkmate.gissen.nl/ to check your MP3 files.
If you do, you'll see that it detects that MP3 file as broken, but the MP3 file from your other link as valid.

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

  • Posts: 349
  • Thank you received: 19
  • Hikashop Business
2 weeks 22 hours ago #366523

Thanks. It looks like I have quite a few corrupted files. Apparently a result of copying from an old disk.

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

Time to create page: 0.078 seconds
Powered by Kunena Forum