Skip to content
Open
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
5 changes: 5 additions & 0 deletions resources/views/includes/cartbox/item-options.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class="btn btn-link"
@include('igniter-orange::includes.cartbox.item-options-'.$menuOption->display_type)
@endif
</div>

<x-igniter-orange::forms.error
field="menuOptions.{{ $menuOption->menu_option_id }}"
class="text-danger mt-2"
/>
@endif
</div>
</div>
Expand Down
29 changes: 28 additions & 1 deletion src/Livewire/CartItemModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ public function boot(): void

public function onSave(): void
{
$this->validateMenuOptions();

try {
$cartItem = $this->cartManager->addOrUpdateCartItem([
'menuId' => $this->menuId,
Expand All @@ -140,7 +142,7 @@ public function onSave(): void

$this->dispatch('hideModal');
} catch (Exception $exception) {
throw ValidationException::withMessages(['menuOptions' => $exception->getMessage()]);
throw ValidationException::withMessages(['menuOptions' => strip_tags($exception->getMessage())]);
}
}

Expand All @@ -165,6 +167,31 @@ public function getOptionQuantityTypeValue($menuOptionValueId)
return $value;
}

protected function validateMenuOptions(): void
{
$errors = [];
$selectedOptions = collect($this->menuOptions);

foreach ($this->getMenuItemData()->getOptions() as $menuOption) {
$selectedOption = $selectedOptions->get($menuOption->getKey());
$selectedValues = array_filter((array)array_get($selectedOption, 'option_values', []));

if (!in_array($menuOption->option->display_type, ['quantity', 'checkbox'])) {
$selectedValues = array_filter($selectedValues, is_numeric(...));
}

try {
$this->cartManager->validateMenuItemOption($menuOption, $selectedValues);
} catch (Exception $exception) {
$errors['menuOptions.'.$menuOption->getKey()] = strip_tags($exception->getMessage());
}
}

if ($errors !== []) {
throw ValidationException::withMessages($errors);
}
}

protected function getCartItem(): ?CartItem
{
if (!is_null($this->cartItem)) {
Expand Down
Loading