diff --git a/src/XeroPHP/Application.php b/src/XeroPHP/Application.php index 7de38b78..2d2a72b2 100644 --- a/src/XeroPHP/Application.php +++ b/src/XeroPHP/Application.php @@ -242,14 +242,14 @@ private function savePropertiesDirectly(Object $object){ foreach($object::getProperties() as $property_name => $meta){ if($meta[Object::KEY_SAVE_DIRECTLY] && $object->isDirty($property_name)){ //Then actually save - $property = $object->$property_name; - $property_type = get_class(current($property)); + $property_objects = $object->$property_name; + $property_type = get_class(current($property_objects)); $url = new URL($this, sprintf('%s/%s/%s', $object::getResourceURI(), $object->getGUID(), $property_type::getResourceURI())); $request = new Request($this, $url, Request::METHOD_PUT); $property_array = array(); - foreach($property as $property_object){ + foreach($property_objects as $property_object){ $property_array[] = $property_object->toStringArray(); } @@ -258,6 +258,14 @@ private function savePropertiesDirectly(Object $object){ $request->send(); + $response = $request->getResponse(); + foreach($response->getElements() as $element_index => $element) { + if($response->getErrorsForElement($element_index) === null) { + $property_objects[$element_index]->fromStringArray($element); + $property_objects[$element_index]->setClean(); + } + } + //Set it clean so the following save might have nothing to do. $object->setClean($property_name); }