Не сохраняются изменения в при изменении объектов MODX
$state = $modx->getObject('StorageState', array('slot' => $move->slot_a->name, 'good_uuid' => $good->uuid));
if($state) {
$state_A_New_Count = $state->good_count - $move->count;
if($state_A_New_Count >= 0) {
$state->set('good_count', $state_A_New_Count);
} else {
$state->set('good_count', $state_A_New_Count);
}
$state->save();
} else {
// Источник не определён, Сохраняем дефицит
$state = $modx->newObject('StorageState');
$state->fromArray([
'slot' => $move->slot_a->name,
'good_uuid' => $good->uuid,
'good_count' => -$move->count
]);
$state->save();
}
Как исправить ?