Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions resources/views/includes/checkout/field-partial.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@include($field->path, [
'field' => $field,
'orderModel' => $orderModel,
])
21 changes: 21 additions & 0 deletions resources/views/includes/checkout/field-select.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div @class(['form-floating', 'is-invalid' => has_form_error($field->getName())])>
<select
wire:model="{{ $field->getName() }}"
data-checkout-control="{{ $field->fieldName }}"
id="{{ $field->getId() }}"
@class(['form-select', 'is-invalid' => has_form_error($field->getName())])
aria-describedby="{{ $field->getId() }}-feedback"
{!! $field->getAttributes() !!}
>
<option value="">@lang('igniter::admin.text_please_select')</option>
@foreach ($field->options() as $value => $label)
<option value="{{ $value }}">{{ $label }}</option>
@endforeach
</select>
<label for="{{ $field->getId() }}">@lang($field->label)</label>
</div>
<x-igniter-orange::forms.error
field="{{ $field->getName() }}"
id="{{ $field->getId() }}-feedback"
class="text-danger"
/>
32 changes: 22 additions & 10 deletions src/Livewire/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,13 @@ public function onChoosePayment($code): void
$this->checkoutForm->getField('payment')->value = $code;
$this->orderManager->applyCurrentPaymentFee($payment->code);

if ($this->order->payment !== $code) {
$this->order->updateQuietly(['payment' => $code]);
$cartTotal = $this->cartManager->getCart()->total();

if ($this->order->payment !== $code || $this->order->order_total !== $cartTotal) {
$this->order->updateQuietly([
'payment' => $code,
'order_total' => $cartTotal,
]);
}

$this->order = null;
Expand Down Expand Up @@ -376,14 +381,21 @@ protected function validateCheckout(Order $order)

$this->withValidator(function($validator) use ($order): void {
$validator->after(function($validator) use ($order): void {
if ($order->isDeliveryType() && Location::requiresUserPosition()) {
rescue(function(): void {
$this->orderManager->validateDeliveryAddress(array_only($this->fields, [
'address_1', 'city', 'state', 'postcode', 'country',
]));
}, function(Throwable $ex) use ($validator): void {
$validator->errors()->add('delivery_address', $ex->getMessage());
});
if ($order->isDeliveryType()) {
if (Location::requiresUserPosition()) {
rescue(function(): void {
$this->orderManager->validateDeliveryAddress(array_only($this->fields, [
'address_1', 'city', 'state', 'postcode', 'country',
]));
}, function(Throwable $ex) use ($validator): void {
$validator->errors()->add('delivery_address', $ex->getMessage());
});
} elseif (blank(array_get($this->fields, 'address_1'))) {
// The delivery area restriction is disabled, so the address is
// deliberately not geocoded or area-checked. It must still exist:
// a delivery order without a street address cannot be delivered.
$validator->errors()->add('delivery_address', lang('igniter.local::default.alert_missing_street_address'));
}
}

if ($this->fields['payment'] && !$this->orderManager->getPayment($this->fields['payment'])) {
Expand Down
2 changes: 1 addition & 1 deletion src/Livewire/Concerns/SearchesNearby.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ protected function geocodeSearchPoint($searchPoint)

$userLocation = $this->handleGeocodeResponse($collection);

$this->searchQuery = $userLocation->format();
$this->searchQuery = $userLocation->getFormattedAddress();

return $userLocation;
}
Expand Down
4 changes: 2 additions & 2 deletions src/View/Components/AccountDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ final class AccountDashboard extends Component

public ?int $defaultAddressId;

public string $formattedAddress = '';
public string $formattedAddress;

public string $customerName = '';
public string $customerName;

public function __construct()
{
Expand Down
33 changes: 33 additions & 0 deletions tests/Livewire/CheckoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,39 @@ function setupCheckout()
->assertHasErrors(['delivery_address' => [lang('igniter.local::default.alert_missing_street_address')]]);
});

it('onValidate requires a delivery address when the delivery area restriction is disabled', function(): void {
setting()->set(['location_order' => '0']);
setupCheckout();

// No usable position, so no address is prepared onto the order
LocationFacade::updateUserPosition(new GeoliteLocation('test'));

$order = resolve(OrderManager::class)->getOrder();
$order->order_type = Location::DELIVERY;
$order->save();
LocationFacade::updateOrderType(Location::DELIVERY);

Livewire::test(Checkout::class)
->dispatch('checkout::validate')
->assertHasErrors(['delivery_address' => [lang('igniter.local::default.alert_missing_street_address')]]);
});

it('onValidate does not geocode the delivery address when the delivery area restriction is disabled', function(): void {
setting()->set(['location_order' => '0']);
setupCheckout();

$order = resolve(OrderManager::class)->getOrder();
$order->order_type = Location::DELIVERY;
$order->save();
LocationFacade::updateOrderType(Location::DELIVERY);

Geocoder::shouldReceive('geocode')->never();

Livewire::test(Checkout::class)
->dispatch('checkout::validate')
->assertHasNoErrors('delivery_address');
});

it('onValidate dispatches an event on success', function(): void {
Event::fake(['igniter.orange.validateCheckout']);
setupCheckout();
Expand Down
3 changes: 2 additions & 1 deletion tests/Livewire/LocalSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,13 @@
'streetName' => 'Main St',
'latitude' => 51.50987615,
'longitude' => -0.1446716,
'formattedAddress' => '123 Main St',
]),
]));

Livewire::test(LocalSearch::class)
->call('onUserPositionUpdated', [51.50987615, -0.1446716])
->assertSet('searchQuery', '123 Main St ');
->assertSet('searchQuery', '123 Main St');
});

it('onUpdateSearchQuery errors when no search query or point', function(): void {
Expand Down
Loading