I want to set a custom field on shopping cart when I first retrieve it.
https://craftcms.com/docs/commerce/4.x/extend/events.html#modifycartinfo sounds appropriate so I tried doing this:
Event::on(
BaseFrontEndController::class,
BaseFrontEndController::EVENT_MODIFY_CART_INFO,
function(ModifyCartInfoEvent $e) {
$order = $e->cart;
$order->setFieldValue('customField', SOME_VALUE);
$e->cart = $order;
}
);
the event handler is executed, yet customField
is null
in the API response.
doing the same thing in an Adjuster
works. however that only runs on a cart update obviously.
edit: ok, this explains why it didn't work that way https://github.com/craftcms/commerce/blob/develop/src/events/ModifyCartInfoEvent.php#L28
What's the right way to set the field on carts?