0

i wrote this code to execute the "add to cart" with selecting product variations function. the function does the job and saves the record to the cart table when i use radio input or checkbox input to select the variations, but fails to save if using the select-option. can you help me to figure out where is the wron i did?

thanks

  `@if ($product->ProductVariations->count() > 0)
    @if ($product->ProductVariations)
       <label for="variation">Topping</label>
       <select wire:model="productvariationid" class="form-control">
       <option selected>Select Option</option>
    @foreach ($product->ProductVariations as $productvari)
       <option value="{{$productvari->id}}">  {{$productvari->variation->name}}
</option>


   {{-- <input type="checkbox"  value="{{$productvari->id}}"     wire:click="variselected({{$productvari->id}})">    {{$productvari->variation->name}} --}}
@endforeach
</select>

@error('productvariationid') <small class="text-danger">{{$message}}</small>@enderror
@endif
<div class="">
@if ($this->productvariationselectedquantity == 'outofstock')
<label for="vari" style="padding: 5px; border-radius:5px;color:beige;max-width:50%;" class="btn-sm py-1 mt-2 label-stock bg-danger ">Out of stock</label>
@elseif ($this->productvariationselectedquantity > 0)
<label for="vari" style="padding: 5px; border-radius:5px;color:beige;" class="btn-sm py-1 mt-2 label-stock bg-success max-width:50%;">In Stock {{$this->productvariationselectedquantity}} Pcs </label>
@endif
</div>
@else

@if ($product->quantity)
   <label for="vari" style="padding: 5px; border-  radius:5px;color:beige;" class="label-stock bg-success">In Stock {{$this->product->quantity}} Pcs</label>
@else
<label for="vari" style="padding: 5px; border-radius:5px;color:wheat;" class="label-stock bg-danger">Out of Stock</label>
@endif
@endif
</div >

<div class="mt-2" style="  border-radius:5px; color:rgb(8, 8, 8);max-width:50%; ">

@if ($product->sizevariations->count() > 0)
   @if ($product->sizevariations)
    <label for="size">Size & Shape</label>
    <select wire:model="sizevariationid" class="form-control">
     <option selected>--Select Option--</option>
   @foreach ($product->sizevariations as $sizevar)
    <option value="{{$sizevar->id}}"  style="background: rgb(223, 206, 206); font-size:14px;">{{ $sizevar->sizevariation->name }}-- {{$sizevar->sizevariation->shape}}
  </option>
{{-- <input type="checkbox" value="{{$sizevar->id}}" wire:click="sizeselected({{$sizevar->id}})">>{{ $sizevar->sizevariation->name }}-- {{$sizevar->sizevariation->shape}} --}}
@endforeach
</select>
@error('productsizeid') <small class="text-danger">{{$message}}</small>@enderror
@endif
@endif
</div >
<button type="submit" wire:click='addtocart({{$product->id}})' class="btn btn1"> <i class="fa fa-shopping-cart"></i> Add To Cart</button>`
Jamal
  • 11
  • 2

0 Answers0