function commerce_registration_set_state in Commerce Registration 7.3
Same name and namespace in other branches
- 7.2 commerce_registration.rules.inc \commerce_registration_set_state()
Action callback.
Sets all registrations on a line item to a given state.
Parameters
$line_item: Commerce Line Item to check the product for registration capacity.
$registration_state: The registration state to set all registrations to on this line item.
Related topics
File
- ./
commerce_registration.rules.inc, line 305 - Commerce Registration rules file.
Code
function commerce_registration_set_state($line_item, $registration_state) {
// Make sure the line item even has a registration product before continuing.
if (!commerce_registration_line_item_is_registration($line_item)) {
return;
}
$line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
$registrations = $line_item_wrapper->registrations
->value();
if (!is_array($registrations)) {
$registrations = unserialize($registrations);
}
foreach ($registrations as $key => $registration) {
$state_key = array_keys($registration_state);
$registration->state = $registration_state[$state_key[0]];
registration_save($registration);
$registrations[$key] = $registration;
}
$line_item_wrapper->registrations = $registrations;
$line_item_wrapper
->save();
}