Hi @Edison,
thank you for your replay.
Here my Code, (a little shortend).
public function init() {
$this->addHookAfter('Pages::saveReady', $this, 'doStuffBeforeOrderIsSaved');
$this->addHookAfter('Pages::saved', $this, 'doStuffAfterOrderIsSaved');
}
function doStuffBeforeOrderIsSaved($event) {
$page = $event->arguments('page');
if($page->template != "my_template") return;
if($page->isUnpublished()) return;
bd($page, "Datenübername");
if($this->session->get("email") != null) $this->addAdressAndName($page);
}
function addAdressAndName($page){
$page->of(false);
$page->email = $this->session->get("email");
// etc....
}
function doStuffAfterOrderIsSaved($event) {
$page = $event->arguments('page');
$changes = $event->arguments('changes');
if($page->template != "my_template") return;
if($page->isUnpublished()) return;
if(array_key_exists('customer_status',$changes)) {
$this->sendMail($this->message, $page);
}
}
public function sendMail($message,$page)
{
bd($page,"object from event");
bd(wire('pages')->find($page->id)[0],"object from find");
$mail = wireMail();
$hanna = wire('modules')->get('TextformatterHannaCode');
$hanna->page = $page;
$subject = $message->message_header;
$bcc = $message->message_bcc;
$from = $message->message_from;
$text = $hanna->render($message->message_text,$page);
$mail->to($page->email);
$mail->bcc($bcc);
$mail->from($from);
$mail->subject($subject);
$mail->bodyHTML($text);
$mail->body(strip_tags($text));
$mail->send();
}
In sendMail Hanna Code gets not the freshly Saved Object, but the old one, without the updatet Data.
Also $page->email is not the updated one. But in the Output from tracy the first page object seems to be right.
It Only apperes if the data is updatet via doStuffBeforeOrderIsSaved and then used in doStuffAfterOrderIsSaved.
Is this an caching Problem?
Can i get arround this by invalading the cache for this object, and how to do that?
Thanks a lot.