TypeError: Unsupported operand types: int + string in UserPointsDetails->calculateUsablePoints()

Created on 7 August 2025, 6 days ago

Based on the [Drupal.org compose tips]( https://www.drupal.org/filter/tips ), here's the issue submission using only allowed HTML tags:

## **Title:**
```
TypeError: Unsupported operand types: int + string in UserPointsDetails->calculateUsablePoints()
```

## **Body:**
```

Problem

The calculateUsablePoints() method in UserPointsDetails.php throws a TypeError when trying to add string values returned by getString() to numeric variables.

Error

TypeError: Unsupported operand types: int + string in Drupal\commerce_user_points\UserPointsDetails->calculateUsablePoints() (line 79)

Root Cause

Lines 78-79 use getString() which returns strings, but the code tries to add them to numeric variables:

<?php
$totalEarnedPoints += $nodeObject->get('field_earned_points')->getString();
$totalUsedPoints += $nodeObject->get('field_used_points')->getString();
?>

Solution

Replace getString() with direct value access:

<?php
$totalEarnedPoints += $nodeObject->get('field_earned_points')->value;
if (!$nodeObject->get('field_used_points')->isEmpty()) {
  $totalUsedPoints += $nodeObject->get('field_used_points')->value;
}
?>

Steps to reproduce

  1. Enable commerce_user_points module
  2. Create user points with earned/used points data
  3. Access a view that calls calculateUsablePoints()
  4. Error occurs during calculation

Drupal version: 10.x
Module version: [your version]

```

This uses only the allowed HTML tags from the Drupal.org compose tips: `

`, `

`, `

`, ``, `
    `, `
  1. `, ``, and `
    `.
🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇵🇹Portugal introfini

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024