At checkout completion, for each rooms booking line item in the order a booking is created.

But if I delete the order, or a line item, nothing happens on related bookings (they are not affected!). This leads to a dangerous inconsistency beetwen order ad bookings.

I try to mantain consistency throw rules, but it seems not working (or at least I am ot able to make it working).

This is the rule.

{ "rules_order_cancellation" : {
"LABEL" : "Order Cancellation",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "commerce", "rooms_booking_manager", "entity" ],
"ON" : [ "commerce_order_delete" ],
"IF" : [
{ "entity_exists" : {
"type" : "rooms_booking",
"property" : "order_id",
"value" : [ "commerce-order:order-id" ]
}
}
],
"DO" : [
{ "rooms_booking_cancel_order" : { "commerce_order" : [ "commerce-order" ] } }
]
}
}

Thanks a lot for the help

Grazio

Comments

ronald_istos’s picture

Right now Rooms does not try to be consistent with the Orders, the thinking being that we are not at the point to act as the single point of reference for that aspect. Hotels may have other systems where they track these issues.

Having said that, the best way to maintain consistency is to act via a hook_entity_delelte on the deletion of a booking and delete or change the state of the corresponding order.

grazio.panico@gmail.com’s picture

Thanks for your reply. I understand.

By the way, I am traying to containt the problem, limiting functionalities or enhancing some.
For example, I have coded the already forseen function rooms_booking_cancel_order_booking, and now using a rule, if one deletes an order, all related booking will be deleted.

If someone care, here is the code
--------------------------------------------------------------------------------
function rooms_booking_cancel_order_booking($order=NULL) {
if (isset($order)) {
//retrive all bookings related to this order
$bookings = rooms_booking_load_multiple(FALSE, array('order_id' => $order->order_number), TRUE);

//cycle to delete
foreach ($bookings as $booking) {
//Check if the booking had a unit associated with it and if so update the availability calendar
if (isset($booking->unit_id) && isset($booking->start_date) && isset($booking->end_date)) {
$uc = new UnitCalendar($booking->unit_id);
// Create an event representing the event to remove
$be = new BookingEvent($booking->unit_id,
rooms_availability_assign_id($booking->booking_id),
new DateTime($booking->start_date),
new DateTime($booking->end_date));
$uc->removeEvents(array($be));
}

rooms_booking_delete($booking);

drupal_set_message(t('The booking %name has been deleted.', array('%name' => $booking->name)));
watchdog('rooms', 'Deleted booking %name.', array('%name' => $booking->name));
}

}
}

Thanks,
Grazio

ropic’s picture

Issue summary: View changes

Thank you !