Here it is:
$modx->addPackage('tariffs', '/usr/home/mydomain/public_html/core/components/tariffs/model/tariffs');
$propertyId = $hook->getValue('property-id');
$modx->loadClass('calendar', '/usr/home/mydomain/public_html/core/components/tariffs/model/tariffs', true, true);
$property = $modx->getObject('Cottage', $propertyId);
// add booking
$modx->loadClass('Booking', '/usr/home/mydomain/public_html/core/components/tariffs/model/tariffs', true, false);
$booking = $modx->newObject('Booking');
$booking->set('title', $hook->getValue('title'));
$booking->set('name', $hook->getValue('lastname'));
$booking->set('firstname', $hook->getValue('firstname'));
$booking->set('email', $hook->getValue('email'));
$booking->set('phone', $hook->getValue('phone'));
$booking->set('country', $hook->getValue('country'));
$booking->set('cottage', $propertyId);
$booking->set('arrival_date', $hook->getValue('arrival'));
$booking->set('departure_date', $hook->getValue('departure'));
$booking->set('tariff', $hook->getValue('tariff'));
$booking->set('adults', $hook->getValue('adults'));
$booking->set('children', $hook->getValue('children'));
$booking->set('dogs', $hook->getValue('dogs'));
$booking->set('guest_comments', $hook->getValue('comments'));
$booking->calculateDeposit();
$booking->set('deposit_paid', 'N');
$booking->set('balance_paid', 'N');
$booking->set('confirmed', 'N');
$booking->set('booking_date', date('Y-m-d', strtotime('now')));
$booking->save();
// update calendar
$calendar = new Calendar($property, $modx);
$calendar->markOccupied($booking->get('arrival_date'), $booking->get('departure_date'));
return true;
For the loadClass first parameter I wasn’t sure whether to use the filename or the class name. I tried both but it doesn’t seem to make a difference.