This hook is fine :
'page.update:after' => function ($newPage, $oldPage) {
if($newPage->pourcentage()->isNotEmpty()) {
$p = $newPage->pourcentage()->toFloat();
$items = site()->index()->filterBy('template', 'product');
$log = $newPage->log();
foreach($items as $item) {
$prix = $item->prix()->toFloat();
$prix = $prix+($prix*$p/100);
try {
$item->update([
'prix' => $prix
]);
}
catch(Exception $e) { echo $e->getMessage(); }
}
$log = $log."\n".date('Y-m-d H:i')." : +".$p."%";
try {
$newPage->update([
'pourcentage' => '',
'log' => $log
]);
}
catch(Exception $e) { echo $e->getMessage(); }
}
}
I need to try the same operation with ‘page.update:before’ … but I don’t understand how it works.
'hooks' => [
'page.update:before' => function ($page, $values, $strings) {
$p = $values['pourcentage'];
... ???
}
]
How can i update the fields ? and then the page ?
Thanks