xero-php icon indicating copy to clipboard operation
xero-php copied to clipboard

Cannot load Xero response over top of invoice object without shenanigans

Open gurubobnz opened this issue 4 years ago • 1 comments

Hi there,

My use case:

  1. Instantiate a new Contact with only the GUID from my local system
  2. Instantiate a new Invoice, set the contact (via setContact())
  3. Configure invoice, add lines etc.
  4. Call save() on the invoice
  5. Try to fetch the full contact via invoice->getContact() so that I can use getName() 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.

gurubobnz avatar Aug 18 '20 01:08 gurubobnz

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.

Healyhatman avatar Apr 28 '22 10:04 Healyhatman