Skip to content

Commit

Permalink
CIVIQBO-105 fix contact fetching for AccountSync API4
Browse files Browse the repository at this point in the history
  • Loading branch information
agileware-fj committed Oct 16, 2023
1 parent 189e6c3 commit c8716fc
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions CRM/Civiquickbooks/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ public function pull($params) {
*/
public function push($params) {
$abort_loop = FALSE;
$params['limit'] = $params['limit'] ?? PHP_INT_MAX;

try {
$accountContacts = AccountContact::get(FALSE)
Expand All @@ -189,14 +188,19 @@ public function push($params) {
// If we specified a CiviCRM contact ID just push that contact.
if (!empty($params['contact_id'])) {
$accountContacts
->addWhere('contact_id', '=', $params['contact_id'])
->addWhere('accounts_needs_update', '=', FALSE);
->addWhere('contact_id', '=', $params['contact_id']);
}
else {
$accountContacts
->addWhere('contact_id', 'IS NOT NULL')
->addWhere('accounts_needs_update', '=', TRUE);
}

if(!empty($params['limit'])) {
$accountContacts
->setLimit($params['limit']);
}

$records = $accountContacts->execute()->getArrayCopy();
$errors = [];

Expand All @@ -209,7 +213,7 @@ public function push($params) {
throw new CRM_Core_Exception('Could not get DataService Object: ' . $e->getMessage());
}

foreach (array_slice($records, 0, $params['limit']) as $account_contact) {
foreach ($records as $account_contact) {
if($abort_loop)
break;

Expand All @@ -222,7 +226,7 @@ public function push($params) {

// NOTE if we store the json string in the response directly using Accountsync API, it will serialized it for us automatically.
// And when we get it out using api, it will deserialize automatically for us.
$accounts_data = isset($account_contact['accounts_contact_id']) ? $account_contact['accounts_data'] : NULL;
$accounts_data = isset($account_contact['accounts_data']) ? json_decode($account_contact['accounts_data'], TRUE) : [];

$QBOContact = $this->mapToCustomer(
civicrm_api3('contact', 'getsingle', [ 'id' => $account_contact['contact_id'] ]),
Expand Down

0 comments on commit c8716fc

Please sign in to comment.