Skip Navigation

Search

Service Category Translation is Missing in Names Object Array - Connect PHP
Answer ID 13134   |   Last Review Date 04/08/2026

Why is the Service Category translation missing in Connect for PHP names object array?

Environment:

Connect for PHP (CPHP) API
Oracle B2C Service

Issue:

Why does this code not work, when the relevant API documentation suggests it should?

$category = RNCPHP\ServiceCategory::fetch(10);

foreach($category->Names as $trans_name){
   echo "<br>-----------------------------------------<br>";
   print_r($trans_name->LabelText);
   echo "<br>";
   print_r($trans_name->Language->ID); echo "<br>";
   print_r($trans_name->Language->LookupName);
   //echo "<br>-----------------------------------------<br>";
}

Resolution:

The other public endpoints (SOAP and REST APIs) support this functionality, but CPHP does not and has behaved this way for many years.

As an alternative, Connect PHP supports this use case through ROQL queries. 

A CPHP ROQL invocation would look like:

$query = "SELECT " . "ServiceCategory.ID AS category_id, " . "ServiceCategory.Names.LabelList.LabelText AS label_text, " . "ServiceCategory.Names.LabelList.Language.ID AS lang_id, " . "ServiceCategory.Names.LabelList.Language.LookupName AS lang_name " . "FROM ServiceCategory " . "WHERE ServiceCategory.ID = 10"; 

$rowset = RNCPHP\ROQL::query($query)->next();

For a more complete code example:

$ids = array(7, 10, 11, 13, 8);
$idCsv = implode(',', $ids);

$query = "SELECT " .
        "ServiceCategory.ID AS category_id, " .
        "ServiceCategory.Names.LabelList.LabelText AS label_text, " .
        "ServiceCategory.Names.LabelList.Language.ID AS lang_id, " .
        "ServiceCategory.Names.LabelList.Language.LookupName AS lang_name " .
        "FROM ServiceCategory " .
        "WHERE ServiceCategory.ID IN ($idCsv) " .
        "ORDER BY ServiceCategory.ID, ServiceCategory.Names.LabelList.Language.ID";

try {
   $rowset = RNCPHP\ROQL::query($query)->next();

   $byCategory = array();
   while ($row = $rowset->next()) {
       $catId = isset($row['category_id']) ? intval($row['category_id']) : 0;
       if ($catId <= 0) {
           continue;
       }

       if (!isset($byCategory[$catId])) {
           $byCategory[$catId] = array();
       }

       $byCategory[$catId][] = array(
           'label'   => isset($row['label_text']) ? $row['label_text'] : '',
           'lang_id' => isset($row['lang_id']) ? $row['lang_id'] : '',
           'lang'    => isset($row['lang_name']) ? $row['lang_name'] : ''
       );
   }

   echo "<br>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>";
   foreach ($ids as $catId) {
       echo "\n=== Category $catId ===\n";
       if (!empty($byCategory[$catId])) {
           foreach ($byCategory[$catId] as $n) {
               echo "-----------------------------------------\n";
               echo $n['label'] . "\n";
               echo $n['lang_id'] . "\n";
               echo $n['lang'] . "\n";
           }
       } else {
           echo "No rows returned\n";
       }
   }
   echo "<br>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>";
   echo "DONE";
}
catch (Exception $e) {
   echo "ERROR: " . $e->getMessage();
}