I’m adding an item to the Merx plugin cart with the following route:
[
'pattern' => 'add',
'method' => 'post|get',
'action' => function () {
$id = get('id');
$quantity = get('quantity');
try {
cart()->add([
'id' => $id,
'quantity' => $quantity,
]);
go($id);
} catch (Exception $ex) {
return $ex->getMessage();
}
},
],
go($id)
refreshes the page. I’d like to show the user that something was added to the cart after this. What would be the best way of doing this? The answer is probably AJAX, but can I do it with my current setup?
I tried using a route:after
hook but I can’t figure out how to detect the specific route:
'hooks' => [
'route:after' => function ($route, $path, $method, $result) {
var_dump($route->pattern());
return $result;
}
]
This dumps string(4) "(.*)"
even when the 'add'
route is triggered.