Appreciate I may be asking for a lot here - I have an existing module that I use to fire events when a stripe order is completed.
I would like to iterate through some User matrix blocks and update a dropdown field value (I have the IDs of the blocks from the stripe order)
This is far as I have got I'm afraid.. happy to look at some docs or be pointed in the right direction. I have other code in the module that does similar to entries, i just cannot work out how to find the matrix blocks by user + ID, and then update the dropdown field.
thanks
Event::on(Orders::class, Orders::EVENT_AFTER_ORDER_COMPLETE, function(OrderCompleteEvent $e) {
// get the order
$order = $e->order;
//get the fields from the order
$fields= $order->getFormFields();
// TROPHY ORDERS
if (!empty($fields['Trophies'])) {
//create array of ids from Trophies field in the order
$blockIds = explode(',', $fields['Trophies']);
// Get the user from the order
$user = Craft::$app->getUsers()->getUserByUsernameOrEmail($order->email);
///do something here to find matrix blocks with the above ID's and then update a dropdown in each one to "paid"
// save
return Craft::$app->getElements()->saveElement($user, false);
}
});