Enable carousel in the Category and Product list view

  • Posts: 85
  • Thank you received: 9
3 years 8 months ago #322666

-- HikaShop version -- : 4.3.0
-- Joomla version -- : 3.9.20
-- PHP version -- : 7.2.26

Hello,

is it possible to enable the carousel view modality for the category and product list view?

Because I saw that there is a carousel file in the Hikashop files and that there is a Module for this, but me I need to enable it in the View Component if is possible.

I need this function because I want to see all the images uploaded of a category or of a product with the carousel effect.

If is not possible I try to add this function with the code


Thank you for your support

Last edit: 3 years 5 months ago by pagemaster.

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

  • Posts: 81504
  • Thank you received: 13063
  • MODERATOR
3 years 8 months ago #322670

Hi,

There is no option to do that.
However, it's possible by editing the product / listing_div.php and category / listing_div.php view files via the menu Display>Views and changing a bit the code.
There, you'll find this line:

$enableCarousel = (int)$this->params->get('enable_carousel', 0) && $this->module;
This will activate the carousel if the "enable carousel" option of the menu item / module is activated and the listing is displayed by a module.
If you change it to :
$enableCarousel = true;
it will activate the carousel for all the listings.
But then, you need to set the different parameters manually.
For example, you'll need such line:
$this->params->set('item_by_slide', XX)
where XX is the number of items per slide of the carousel. So if the listing is set to display 20 items per page of the pagination, then you want that XX number to be smaller than 20. For example 4, so that it displays 4 items per slide of the carousel.
You can check the different parameters necessary in product / carousel.php

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

  • Posts: 85
  • Thank you received: 9
3 years 5 months ago #325471

This is the final custom code of the view (it works until 3 images) HikaShop - product / listing_img_title.php:

<?php
	
	// Get a db connection.
	$db = JFactory::getDbo();
	
	// Create a new query object.
	$query = $db->getQuery(true);
	
	$query->select('file_path');
	$query->from($db->quoteName('tbuonapp_hikashop_file'));
	$query->where('file_ref_id = ' . '"' . $this->row->category_id . '"');

	// Reset the query using our newly populated query object.
	$db->setQuery($query);
	$foto_1 = $db->loadResult();
	
	
	// Get a db connection.
	$db = JFactory::getDbo();
	
	// Create a new query object.
	$query = $db->getQuery(true);
	
	$query->select('foto_2');
	$query->from($db->quoteName('tbuonapp_hikashop_category'));
	$query->where('category_id = ' . '"' . $this->row->category_id . '"');

	// Reset the query using our newly populated query object.
	$db->setQuery($query);
	$foto_2 = $db->loadResult();
	
	
	// Get a db connection.
	$db = JFactory::getDbo();
	
	// Create a new query object.
	$query = $db->getQuery(true);
	
	$query->select('foto_3');
	$query->from($db->quoteName('tbuonapp_hikashop_category'));
	$query->where('category_id = ' . '"' . $this->row->category_id . '"');

	// Reset the query using our newly populated query object.
	$db->setQuery($query);
	$foto_3 = $db->loadResult();
	
	$categoryImages[$this->row->category_id] .= $foto_1 . ",";
	
	if($foto_2){
		$categoryImages[$this->row->category_id] .= $foto_2 . ",";
	}
	if($foto_3){
		$categoryImages[$this->row->category_id] .= $foto_3;
	}
?>

<div class="hikashop_category_image">
	<a href="<?php echo $this->row->link;?>" title="<?php echo $this->escape($this->row->category_name); ?>">
		<?php
		$image_options = array('default' => true,'forcesize'=>$this->config->get('image_force_size',true),'scale'=>$this->config->get('image_scale_mode','inside'));
		$img = $this->image->getThumbnail(@$this->row->file_path, array('width' => $this->image->main_thumbnail_x, 'height' => $this->image->main_thumbnail_y), $image_options);
		if($img->success) {
			$html = '<img class="hikashop_product_listing_image" id="pics_' .  $this->row->category_id . '" title="'.$this->escape(@$this->row->file_description).'" alt="'.$this->escape(@$this->row->file_name).'" src="'.$img->url.'"/>';
			if($this->config->get('add_webp_images', 1) && function_exists('imagewebp') && !empty($img->webpurl)) {
				$html = '
				<picture>
					<source srcset="'.$img->webpurl.'" type="image/webp">
					<source srcset="'.$img->url.'" type="image/'.$img->ext.'">
					'.$html.'
				</picture>
				';
			}
			echo $html;
		}
		?>
	</a>
	
	<?php if($foto_2 OR $foto_3){ ?>
		<img src="/images/back.png" id="backbtn<?php echo $this->row->category_id ?>" class="btnBack" onclick="prevImage('<?php echo $this->row->category_id ?>', '<?php echo $categoryImages[$this->row->category_id] ?>')" width="30px" /><img src="/images/next.png" class="btnNext" id="nextbtn<?php echo $this->row->category_id ?>" onclick="nextImage( '<?php echo $this->row->category_id ?>', '<?php echo $categoryImages[$this->row->category_id] ?>')" width="30px" />
	<?php } ?>
</div>

<script>
	
	var index = 0;
	
	function nextImage(category_id_image, category_images) {
		
		var arrayImages = category_images.split(",");
		
		if(index < arrayImages.length - 1){
			
			index += 1;
			
			console.log(arrayImages[index]);
			
			document.getElementById('pics_' + category_id_image).src = "/media/com_hikashop/upload/safe/"  + arrayImages[index];
			
			if(index == arrayImages.length - 1){
				document.getElementById("nextbtn" + category_id_image).style.display = "none";
				document.getElementById("backbtn" + category_id_image).style.display = "block";
			}else{
				document.getElementById("nextbtn" + category_id_image).style.display = "block";
				document.getElementById("backbtn" + category_id_image).style.display = "block";
			}
			
		}
	}
	
	function prevImage(category_id_image, category_images) {
		
		var arrayImages = category_images.split(",");
		
		if(index > 0){
			index -= 1;
			
			if(index == 0){
				document.getElementById('pics_' + category_id_image).src = "/images/com_hikashop/upload/thumbnails/174x310fsO/"  + arrayImages[index];
			}else{
				document.getElementById('pics_' + category_id_image).src = "/media/com_hikashop/upload/safe/"  + arrayImages[index];
			}
			
			if(index == 0){
				document.getElementById("backbtn" + category_id_image).style.display = "none";
				document.getElementById("nextbtn" + category_id_image).style.display = "block";
			}else{
				document.getElementById("backbtn" + category_id_image).style.display = "block";
				document.getElementById("nextbtn" + category_id_image).style.display = "block";
			}
			
		}
	}
</script>

Last edit: 3 years 5 months ago by pagemaster.
The following user(s) said Thank You: nicolas

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

Time to create page: 0.059 seconds
Powered by Kunena Forum