Skip to main content

Error patch for Rewards page

This error is cause if you don't have points setup up

you will see error 

Fatal error: Uncaught DivisionByZeroError: Division by zero in /var/www/vhosts/

Solution

Open Look for  content/themes/default/templates/badges/rewards.tpl

{print_money(((1/$system['points_per_currency'])*$user->_data['user_points'])|number_format:2)}

and replace with 

{if isset($system['points_per_currency']) && $system['points_per_currency'] > 0}
    {print_money(((1/$system['points_per_currency'])*$user->_data['user_points'])|number_format:2)}
{else}
    {__("Conversion unavailable")}
{/if}

 

Open badges/cron_badges.php and look for 

 // Check if user already has this badge
        $check = $db->query("SELECT * FROM users_badges WHERE user_id = $user_id AND badge_id = $badge_id");
        if ($check->num_rows == 0) {
            // Assign badge
            $db->query("INSERT INTO users_badges (user_id, badge_id, awarded_at) VALUES ($user_id, $badge_id, NOW())");
        }

 

and replace with 

// Check if user already has this badge
$check = $db->query("SELECT COUNT(*) as count FROM users_badges WHERE user_id = $user_id AND badge_id = $badge_id");
$check_result = $check->fetch_assoc();

if ($check_result['count'] == 0) {
    // Assign badge (preventing duplicate entries)
    $db->query("INSERT IGNORE INTO users_badges (user_id, badge_id, awarded_at) VALUES ($user_id, $badge_id, NOW())");
}