After a long period, I’m posting the solution to display premium items in random order for those who did not have a solution for this yet. In file main.php look for:
<?php View::newInstance()->_exportVariableToView('items', $default_items); ?>
Beneath that line, change code up to line:
<?php osc_run_hook('home_premium'); ?>
Copy / paste code:
<?php
$has_day_offer = 0;
if(eps_param('enable_day_offer') == 1 && eps_param('day_offer_id') > 0) {
$day_offer = Item::newInstance()->findByPrimaryKey(eps_param('day_offer_id'));
if($day_offer !== false && isset($day_offer['pk_i_id'])) {
$has_day_offer = 1;
}
}
// Fetch premium items
$premium_items = eps_premium_items(eps_param('premium_home_count') - $has_day_offer, @$day_offer['pk_i_id']);
// Shuffle premium items for random order on each page load
if($premium_items) {
shuffle($premium_items);
// Apply admin setting for the number of items to display
$premium_item_count = eps_param('premium_home_count') - $has_day_offer;
$premium_items = array_slice($premium_items, 0, $premium_item_count);
}
?>
<?php if(eps_param('premium_home') == 1 && count($premium_items) > 0) { ?>
<?php
$default_items = View::newInstance()->_get('items');
View::newInstance()->_exportVariableToView('items', $premium_items);
?>
<section class="home-premium">
<div class="container">
<div class="block">
<h2><?php _e('Today\'s premium selection', 'epsilon'); ?></h2>
<div class="nice-scroll-wrap">
<div class="nice-scroll-prev"><i class="fas fa-caret-left"></i></div>
<div id="premium-items" class="products grid nice-scroll no-visible-scroll">
<?php
$c = 1;
// Add the day offer first, if present
if($has_day_offer == 1) {
View::newInstance()->_exportVariableToView('item', $day_offer);
eps_draw_item($c, false, eps_param('premium_home_design'));
$c++;
}
// Add the shuffled and limited premium items
while(osc_has_items()) {
eps_draw_item($c, false, eps_param('premium_home_design'));
$c++;
}
?>
</div>
<div class="nice-scroll-next"><i class="fas fa-caret-right"></i></div>
</div>
</div>
</div>
</section>
<?php View::newInstance()->_exportVariableToView('items', $default_items); ?>
<?php } ?>
For those that want to use auto scroll left to right on premiums with random shuffle use code:
<?php
$has_day_offer = 0;
if(eps_param('enable_day_offer') == 1 && eps_param('day_offer_id') > 0) {
$day_offer = Item::newInstance()->findByPrimaryKey(eps_param('day_offer_id'));
if($day_offer !== false && isset($day_offer['pk_i_id'])) {
$has_day_offer = 1;
}
}
// Fetch premium items
$premium_items = eps_premium_items(eps_param('premium_home_count') - $has_day_offer, @$day_offer['pk_i_id']);
// Shuffle premium items for random order on each page load
if($premium_items) {
shuffle($premium_items);
// Apply admin setting for the number of items to display
$premium_item_count = eps_param('premium_home_count') - $has_day_offer;
$premium_items = array_slice($premium_items, 0, $premium_item_count);
}
?>
<?php if(eps_param('premium_home') == 1 && count($premium_items) > 0) { ?>
<?php
$default_items = View::newInstance()->_get('items');
View::newInstance()->_exportVariableToView('items', $premium_items);
?>
<section class="home-premium">
<div class="container">
<div class="block">
<h2><?php _e('Today\'s premium selection', 'epsilon'); ?></h2>
<div class="nice-scroll-wrap">
<div id="premium-items" class="products grid nice-scroll no-visible-scroll">
<?php
$c = 1;
// Add the day offer first, if present
if($has_day_offer == 1) {
View::newInstance()->_exportVariableToView('item', $day_offer);
eps_draw_item($c, false, eps_param('premium_home_design'));
$c++;
}
// Add the shuffled and limited premium items
while(osc_has_items()) {
eps_draw_item($c, false, eps_param('premium_home_design'));
$c++;
}
?>
</div>
</div>
</div>
</div>
</section>
<?php View::newInstance()->_exportVariableToView('items', $default_items); ?>
<?php } ?>
<script>
document.addEventListener("DOMContentLoaded", function() {
var premiumItems = document.getElementById('premium-items');
var scrollAmount = 1; // Adjust the scroll speed as desired
var scrollDirection = 1; // 1 for right, -1 for left
var scrollInterval = 30; // Time interval for scrolling, can be adjusted
var autoScrollTimeout;
function autoScroll() {
if (premiumItems) {
premiumItems.scrollLeft += scrollAmount * scrollDirection;
// If we reach the right side, change direction to left
if (premiumItems.scrollLeft + premiumItems.clientWidth >= premiumItems.scrollWidth) {
scrollDirection = -1;
}
// If we reach the left side, change direction to right
if (premiumItems.scrollLeft <= 0) {
scrollDirection = 1;
}
// Call this function again to continue scrolling
autoScrollTimeout = setTimeout(autoScroll, scrollInterval);
}
}
// Start the automatic scroll with a small delay to ensure the content is fully loaded
setTimeout(autoScroll, 100);
// Stop scrolling on mouseover
premiumItems.addEventListener('mouseover', function() {
clearTimeout(autoScrollTimeout);
});
// Restart scrolling on mouseout
premiumItems.addEventListener('mouseout', function() {
autoScroll();
});
});
</script>
<?php osc_run_hook('home_premium'); ?>
Cheers