0

I need someone to help me please to insert multiple products to cart, adding single one is working fine but I have one product which inserting with no issue and related products which have checkboxes where I need to add it but dont know how

enter image description here

ajax for adding product:

<script>
$(function(){ 
  $('.add_to_cart').on("click", function () { 
    var id = ($("#item_id").val());
    $.ajax({ 
      url: 'cart/' + id+'/edit', 
      type: "get", 
      success: function (data) { 

        $('#myModal').modal('hide'); 
        $('#cart_product').html(data); 
      } 
    }); 
  }); 
});
</script>

add in controller

public function edit(Request $request,$id)
{ 
  $quantity=$request->quantity;

  $product=Product::find($id);
  Cart::add($id,$product->product_title,$quantity,$product->product_price);
  $products = Cart::content();
  foreach($products as $Product){
    echo '<div class="OrderItem_root styles_base styles_spacing-base">
    <div class="OrderItem_quantity styles_just-right styles_base styles_spacing-base">'.$Product->qty.'</div>
    <div class="OrderItem_container">
    <div class="OrderItem_category"></div>
    <div class="OrderItem_itemHeader">
    <div id="cartprice" class="OrderItem_total">$'.$Product->price*$Product->qty.'</div>
    <input id="mycartprice" type="text" name="mycartprice" value="'.$Product->price.'"  hidden="">
    </div>
    <div>
    </div>
    <div>
    <button class="remove_item OrderItem_action Button_root" data-id="'.$Product->rowId.'" data-price="'.$Product->price*$Product->qty.'" data-qty="'.$Product->qty.'" type="submit">Remove</button>
    </div>
    </div>
    </div>';
  }
}

related items

foreach($products as $Product){ 

   echo '<div class="SuggestedItem_container">  
    <label>
    <input  id="ppleadd" type="checkbox" onchange = "AutoCalculateMandateOnChange(this)"> 

    <span id="related_item" class="SuggestedItem_name">'.$ProductDetails->product_title.'</span><span class="SuggestedItem_price styles_small styles_base styles_spacing-base">+$'.$ProductDetails->product_price.'</span></div></div> 

    </div> 
    </label>'; 
}
4

1 Answer 1

1

to solve this issue use this

  <input  id="ppleadd" type="checkbox" class="get_value" data-id="'.$ProductDetails->product_id.'" >


$(document).ready(function(){
$('.testbtn').on("click", function (){
 var insert=[];
$('.get_value').each(function(){
if($(this).is(":checked"))
{
insert.push($(this).attr('data-id'));
 }
 });

 insert=insert.toString();
 $.ajax({
url:"add-to-cart",
method:"get",
data:{insert:insert},
 success:function(data){
  } }); }); });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.