Skip to content

Commit

Permalink
Refactor entityParams in Order.Create API so it is easier to understa…
Browse files Browse the repository at this point in the history
…nd/modify
  • Loading branch information
mattwire committed Oct 19, 2020
1 parent 776662b commit bd94f95
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions api/v3/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,30 @@ function civicrm_api3_order_create($params) {
$item = reset($lineItems['line_item']);
$entity = str_replace('civicrm_', '', $item['entity_table']);
}

if ($entityParams) {
if (in_array($entity, ['participant', 'membership'])) {
$entityParams['skipLineItem'] = TRUE;
$entityParams['status_id'] = ($entity === 'participant' ? 'Pending from incomplete transaction' : 'Pending');
$entityResult = civicrm_api3($entity, 'create', $entityParams);
$params['contribution_mode'] = $entity;
$entityIds[] = $params[$entity . '_id'] = $entityResult['id'];
foreach ($lineItems['line_item'] as &$items) {
$items['entity_id'] = $entityResult['id'];
}
switch ($entity) {
case 'participant':
$entityParams['status_id'] = 'Pending from incomplete transaction';
break;

case 'membership':
$entityParams['status_id'] = 'Pending';
break;

default:
// Don't create any related entities. We might want to support eg. Pledge one day?
break 2;
}
else {
// pledge payment
$entityParams['skipLineItem'] = TRUE;
$entityResult = civicrm_api3($entity, 'create', $entityParams);
$params['contribution_mode'] = $entity;
$entityIds[] = $params[$entity . '_id'] = $entityResult['id'];
foreach ($lineItems['line_item'] as &$items) {
$items['entity_id'] = $entityResult['id'];
}
}

if (empty($priceSetID)) {
$item = reset($lineItems['line_item']);
$priceSetID = (int) civicrm_api3('PriceField', 'getvalue', [
Expand Down

0 comments on commit bd94f95

Please sign in to comment.