From 3a5e99748d32fb92fd5fb805b5abb00251c27f9f Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Mon, 31 Jul 2023 16:53:10 +0100 Subject: [PATCH] test --- src/WebformCivicrmPostProcess.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/WebformCivicrmPostProcess.php b/src/WebformCivicrmPostProcess.php index f584350eb..64e4193b2 100644 --- a/src/WebformCivicrmPostProcess.php +++ b/src/WebformCivicrmPostProcess.php @@ -2344,22 +2344,24 @@ private function processContribution() { // Membership if (!empty($item['membership_id'])) { $item['entity_id'] = $item['membership_id']; - $lineItemArray = $this->utils->wf_civicrm_api('LineItem', 'get', [ - 'entity_table' => "civicrm_membership", - 'entity_id' => $item['entity_id'], - ]); - if ($lineItemArray['count'] != 0) { - // We only require first membership (signup) entry to make this work. - $firstLineItem = array_shift($lineItemArray['values']); - + // We only require first membership (signup) entry to make this work. + $firstMembershipLineItem = $this->utils->wf_civicrm_api4('LineItem', 'get', [ + 'where' => [ + ['entity_table', '=', 'civicrm_membership'], + ['entity_id', '=', $item['entity_id']], + ], + ], + 0, + ); + if (!empty($firstMembershipLineItem)) { // Membership signup line item entry. // Line Item record is already present for membership by this stage. // Just need to upgrade contribution_id column in the record. - if (!isset($firstLineItem['contribution_id'])) { - $item['id'] = $firstLineItem['id']; + if (!isset($firstMembershipLineItem['contribution_id'])) { + $item['id'] = $firstMembershipLineItem['id']; } - $item['price_field_id'] = $firstLineItem['price_field_id']; - $item['price_field_value_id'] = $firstLineItem['price_field_value_id']; + $item['price_field_id'] = $firstMembershipLineItem['price_field_id']; + $item['price_field_value_id'] = $firstMembershipLineItem['price_field_value_id']; } } if (!isset($item['price_field_id'])) { @@ -2373,6 +2375,7 @@ private function processContribution() { } // Save the line_item + var_dump($item); $line_result = $this->utils->wf_civicrm_api('line_item', 'create', $item); $item['id'] = $line_result['id'];