Welcome on board Julien and thanks for using Merx and buying a license. Your shop, as you describe it, sounds very promising. I’m looking forward to seeing it live in action. I am pleased to hear that Merx’s intended flexibility seems to work for you (calculate shipping based on weight of goods).
Regarding your question: Maybe you don’t need the ww.merx.cart
hook.
For merx.wagnerwagner.de/buy I update the cart via a merx-api/update-cart
route when the country changes (Germans have to pay 19 % Vat). This country dropdown could be your pick up at the shop checkbox. So your cart-hook could be like this (untested):
'method' => 'post',
'pattern' => 'custom-api/update-cart',
'action' => function() {
$cart = cart();
if ((string)$_POST['pickup'] === 'on') {
$cart->remove('shipping');
} else {
// … calculate shipping costs based on weight and/or $_POST['country']
$shippingCosts = 12.99;
$cart->add([
'id' => 'shipping',
'price' => $shippingCosts,
]);
}
}
If you need the same functionality in the ww.merx.cart
hook and in your update-cart
route adding a method to your OrderPage
class could be an option but I think it’s not the ideal solution. You can create a global function at config.php
which should be available in the hook and the route.
I hope this helps a little. If you want, I can take a closer look at the code and your implementation.