Skip to content

Commit

Permalink
Fix for checking out when multi day availability is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
afonic committed Nov 13, 2024
1 parent d58d9cd commit c5c3117
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Livewire/AvailabilityResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ public function getAvailability(): void

public function checkout(): void
{
if ($this->extraDays !== 0 && $this->availability->count() > 1) {
$this->availability = collect($this->availability->get(0));
}
try {
$this->validateAvailabilityAndPrice();
$this->createReservation();
Expand Down
46 changes: 46 additions & 0 deletions tests/Livewire/AvailabilityResultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,52 @@ public function test_creates_reservation_and_saves_custom_data_in_the_database()
);
}

// Test that it creates a reservation when multiple days results are enabled
public function test_checkout_works_for_multiple_days()
{
$entry = Entry::make()
->collection('pages')
->slug('checkout')
->data(['title' => 'Checkout']);

$entry->save();

Config::set('resrv-config.checkout_entry', $entry->id());

$component = Livewire::test(AvailabilityResults::class, ['entry' => $this->advancedEntries->first()->id(), 'extraDays' => 1, 'extraDaysOffset' => 1])
->dispatch('availability-search-updated',
[
'dates' => [
'date_start' => $this->date->toISOString(),
'date_end' => $this->date->copy()->add(2, 'day')->toISOString(),
],
'quantity' => 1,
'advanced' => 'test',
'customer' => [
'adults' => 2,
'children' => 1,
],
]
);

$availability = $component->viewData('availability');

$component->call('checkout');

$this->assertDatabaseHas('resrv_reservations',
[
'item_id' => $this->advancedEntries->first()->id(),
'date_start' => $this->date,
'date_end' => $this->date->copy()->add(2, 'day'),
'quantity' => 1,
'property' => 'test',
'payment' => data_get($availability[0], 'data.payment'),
'price' => data_get($availability[0], 'data.price'),
'customer' => json_encode(['adults' => 2, 'children' => 1]),
]
);
}

// Test that it return an error if the availability has changed after the results have been shown
public function test_does_not_create_reservation_if_availability_changed()
{
Expand Down

0 comments on commit c5c3117

Please sign in to comment.