I want to add the products from two tables, one is from items or another as sub item. But when I try to add a sub item from the relevant parent item. The parent item is itself become added in cart. And quantity becomes double. The conflict is that... Lets suppose there are products in parent with id = 1,2,3,... And in the child table there are products too with the same id's = 1,2,3,... And when I try to add a product from id =1. It takes it as a parent item and add the same parent product with quantity double. I don't know how to come over this issue. I'm really going through some frustration about it. Please take a look at the code below. Method from the sub items is below!
public function show($s)
{
$sId = Item::find($s);
Cart::add($sId->id,$sId->sub_title,1,$sId->sub_price);
return back();
}
Method from the Parent Items is below:
public function edit($mealId)
{
$getId = Menu::find($mealId);
Cart::add($getId->id,$getId->title,1,$getId->price);
return back();
}
And on cart index page:
@extends('layouts.app')
@section('title', 'Cart')
<style media="screen">
a.cross-btn:link{
text-decoration: none;
}
div.cart-section{
width: 100%;
height: auto;
padding: 40px 25px;
}
</style>
@section('body')
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="cart-section">
<div class="table-responsive">
<table class="table table-hover">
<tr>
<th>Item Name</th>
<th>Qty</th>
<th>Total Price</th>
<th>Remove Item</th>
</tr>
@foreach($cartItems as $cartItem)
<tr>
<td></td>
<td></td>
<td> $</td>
<td>
<form action="" method="post">
<input type="submit" name="submit" value="✖" class="btn btn-danger"/>
</form>
</td>
</tr>
@endforeach
@if(Cart::subtotal() != 0)
<tr>
<td><strong>Sub Total</strong></td>
<td> $</td>
@if (Auth::guest())
<td><a href="" type="button" class="btn btn-default">Login</a> OR Order as Guest
<form action="" method="get">
<legend>Payment Method</legend>
COD: <input type="radio" name="payment_method" value="Cash On Delivery" checked required />
Braintree: <input type="radio" name="payment_method" value="Braintree" required />
<input type="submit" name="submit" class="btn btn-success" value="Order as Guest" />
</form>
">Order as Guest</a>--}}
</td>
@else
<td>
<form action="#" method="post">
<legend>Payment Method</legend>
COD: <input type="radio" name="payment_method" value="Cash On Delivery" checked required />
Braintree: <input type="radio" name="payment_method" value="Braintree" required />
<input type="submit" name="submit" class="btn btn-success" value="Proceed to Checkout" />
</form>
</td>
@endif
</tr>
@else
<tr>
<td><a href="" type="button" class="btn btn-danger">Continue Shopping</a></td>
</tr>
@endif
</table>
</div>
</div>
</div>
</div>
</div>
@endsection
For Reference I'm using this laravel package -> http://ift.tt/1kui2nw
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire