}
}
}
+ // If the base entity has a field named 'currency', fall back on that.
+ if ($this->getField('currency')) {
+ return 'currency';
+ }
+ // Finally, if there's a FK field to civicrm_contribution, we can use an implicit join
+ // E.G. the LineItem entity has no `currency` field of its own & uses that of the contribution record
+ if ($entityDao) {
+ foreach ($entityDao::getSupportedFields() as $fieldName => $field) {
+ if (($field['FKClassName'] ?? NULL) === 'CRM_Contribute_DAO_Contribution') {
+ return $prefix . $fieldName . '.currency';
+ }
+ }
+ }
return NULL;
}
$this->assertEquals('JPY', $result[2]['data']['currency']);
$this->assertEquals('¥ 500.00', $result[2]['columns'][0]['val']);
+
+ // Now do a search for the contribution line-items
+ $params['savedSearch'] = [
+ 'api_entity' => 'LineItem',
+ 'api_params' => [
+ 'version' => 4,
+ 'select' => ['line_total'],
+ 'where' => [['contribution_id', 'IN', $contributions->column('id')]],
+ ],
+ ];
+
+ $result = civicrm_api4('SearchDisplay', 'run', $params);
+ $this->assertCount(3, $result);
+
+ // An automatic join should have been added to fetch the contribution currency
+ $this->assertEquals('GBP', $result[0]['data']['contribution_id.currency']);
+ $this->assertEquals('£ 100.00', $result[0]['columns'][0]['val']);
+
+ $this->assertEquals('USD', $result[1]['data']['contribution_id.currency']);
+ $this->assertEquals('$ 200.00', $result[1]['columns'][0]['val']);
+
+ $this->assertEquals('JPY', $result[2]['data']['contribution_id.currency']);
+ $this->assertEquals('¥ 500.00', $result[2]['columns'][0]['val']);
}
}