'id' => $id,
]);
// First look for new-style template contribution with is_template=1
- $templateContributions = \Civi\Api4\Contribution::get()
- ->setCheckPermissions(FALSE)
+ $templateContributions = \Civi\Api4\Contribution::get(FALSE)
->addWhere('contribution_recur_id', '=', $id)
->addWhere('is_template', '=', 1)
->addWhere('is_test', '=', $is_test)
->execute();
if (!$templateContributions->count()) {
// Fall back to old style template contributions
- $templateContributions = \Civi\Api4\Contribution::get()
- ->setCheckPermissions(FALSE)
+ $templateContributions = \Civi\Api4\Contribution::get(FALSE)
->addWhere('contribution_recur_id', '=', $id)
->addWhere('is_test', '=', $is_test)
->addOrderBy('id', 'DESC')
}
if ($templateContributions->count()) {
$templateContribution = $templateContributions->first();
- $result = array_merge($templateContribution, $overrides);
$lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($templateContribution['id']);
+ // We only permit the financial type to be overridden for single line items.
+ // Otherwise we need to figure out a whole lot of extra complexity.
+ // It's not UI-possible to alter financial_type_id for recurring contributions
+ // with more than one line item.
+ if (count($lineItems) > 1 && isset($overrides['financial_type_id'])) {
+ unset($overrides['financial_type_id']);
+ }
+ $result = array_merge($templateContribution, $overrides);
$result['line_item'] = self::reformatLineItemsForRepeatContribution($result['total_amount'], $result['financial_type_id'], $lineItems, (array) $templateContribution);
return $result;
}
/**
* Copy custom data of the initial contribution into its recurring contributions.
*
+ * @deprecated
+ *
* @param int $recurId
* @param int $targetContributionId
*/