Example #1
0
 /**
  * Checks if a thirdparty exists in Dolibarr
  *
  * @param int $user_id Wordpress ID of an user
  *
  * @return int $result Array with the request results if it succeeds, null if there's an error
  */
 private function dolibarr_thirdparty_exists($user_id)
 {
     try {
         $soap_client = new SoapClient($this->ws_endpoint . self::THIRDPARTY_ENDPOINT . self::WSDL_MODE);
     } catch (SoapFault $exception) {
         $this->logger->add('doliwoo', $exception->getMessage());
         // Do nothing.
         return null;
     }
     $dol_id = get_user_meta($user_id, 'dolibarr_id', true);
     $dol_ref = get_user_meta($user_id, 'billing_company', true);
     // If the user has a Dolibarr ID, use it, else search his company name
     if ($dol_id) {
         $dol_ref = null;
     } else {
         $dol_id = '';
     }
     try {
         $result = $soap_client->getThirdParty($this->ws_auth, $dol_id, $dol_ref);
     } catch (SoapFault $exception) {
         $this->logger->add('doliwoo', 'getThirdParty request: ' . $exception->getMessage());
         // Do nothing.
         return null;
     }
     if (!('OK' == $result['result']->result_code)) {
         $this->logger->add('doliwoo', 'getThirdParty response: ' . $result['result']->result_code . ': ' . $result['result']->result_label);
         // Do nothing
         return null;
     }
     return $result;
 }