You are here

public function FeatureContext::createBookings in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

@Given /^"(?P<type>[^"]*)" bookings:$/

File

test/features/bootstrap/FeatureContext.php, line 514

Class

FeatureContext
Features context.

Code

public function createBookings($type, TableNode $nodesTable) {
  foreach ($nodesTable
    ->getHash() as $nodeHash) {
    $profile_id = $this->customerProfiles[$nodeHash['profile_id']];
    $profile = commerce_customer_profile_load($profile_id);
    $client_name = isset($profile->commerce_customer_address[LANGUAGE_NONE][0]['name_line']) ? $profile->commerce_customer_address[LANGUAGE_NONE][0]['name_line'] : $nodeHash['profile_id'];

    // Save customer in rooms_customers table.
    db_merge('rooms_customers')
      ->key(array(
      'name' => $client_name,
    ))
      ->fields(array(
      'name' => $client_name,
      'commerce_customer_id' => $profile_id,
    ))
      ->execute();

    // Get customer id from rooms_customers table.
    $client_id = db_select('rooms_customers')
      ->fields('rooms_customers', array(
      'id',
    ))
      ->condition('name', $client_name, '=')
      ->execute()
      ->fetchField();
    $unit_id = $this
      ->findBookableUnitByName($nodeHash['unit']);
    $unit = rooms_unit_load($unit_id);
    $unit_type = $unit->type;
    $data = array(
      'type' => $type,
      'name' => $client_name,
      'customer_id' => $client_id,
      'unit_id' => $unit_id,
      'unit_type' => $unit_type,
      'start_date' => $nodeHash['start_date'],
      'end_date' => $nodeHash['end_date'],
      'booking_status' => $nodeHash['status'],
      'data' => array(
        'group_size' => $nodeHash['guests'],
        'group_size_children' => $nodeHash['children'],
      ),
    );
    $booking = rooms_booking_create($data);
    $booking
      ->save();
    $this->bookings[] = $booking->booking_id;
  }
}