xero-php
xero-php copied to clipboard
Cannot load Xero response over top of invoice object without shenanigans
Hi there,
My use case:
- Instantiate a new
Contact
with only the GUID from my local system - Instantiate a new
Invoice
, set the contact (viasetContact()
) - Configure invoice, add lines etc.
- Call
save()
on the invoice - Try to fetch the full contact via
invoice->getContact()
so that I can usegetName()
on it, but it's only the empty instantiated one from the first step.
I instantiate a new contact locally to avoid either a) maintaining a full copy of the contact locally and b) having to ask Xero for the contact first (and hence using a precious API call).
I noticed that the Application
object has a save()
method which takes an optional boolean for $replace_data
, but save()
on the model doesn't have this option. If I add $replace_data
as an optional parameter to Model::save()
then it works just nicely.
My workaround for now is to:
$result = $invoice->save(); // create in xero
// Load the full invoice from the response - as we provided a hydrated contact we don't have all the details to hand
$invoice->fromStringArray($result->getElements()[0], true);
But it would be nice to be able to just:
$invoice->save(true);
Is there something I'm missing? Happy to do a PR for this.
You can simply do $application->save($invoice_object, true). Otherwise you could probably make a pull request, Calcinai is really good with reviewing and merging them.