Commit 0bfb296e authored by Artem's avatar Artem

bug fix in cart index method, disable delete product option

parent 02165d9e
......@@ -3,6 +3,8 @@
namespace App;
//use Illuminate\Database\Eloquent\Model;
use App\Product;
use DB;
class Cart /*extends Model*/
{
......@@ -67,4 +69,12 @@ class Cart /*extends Model*/
$this->updateTotalQty();
$this->updateTotalPrice();
}
public function updateCurrentItems()
{
foreach ($this->items as $id => $item) {
$this->items[$id]['item'] = Product::where('id', $id)->first();
}
$this->updateTotalPrice();
}
}
......@@ -17,6 +17,8 @@ class CartController extends Controller
}
$cart = Session::get('cart');
// need to take products from database because product data may change
$cart->updateCurrentItems();
$products = $cart->items;
return view('cart', compact('cart', 'products'));
......
......@@ -127,11 +127,11 @@ class ProductController extends Controller
* @param \App\Product $product
* @return \Illuminate\Http\Response
*/
public function destroy(Product $product)
{
$product->delete();
return redirect('/');
}
// public function destroy(Product $product)
// {
// $product->delete();
// return redirect('/');
// }
public function validateProduct()
{
......
......@@ -5,6 +5,7 @@ namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Artisan;
class User extends Authenticatable
{
......@@ -36,4 +37,9 @@ class User extends Authenticatable
protected $casts = [
'email_verified_at' => 'datetime',
];
public function orders()
{
return $this->hasMany(Order::class);
}
}
......@@ -11,7 +11,7 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
// $this->call(UserSeeder::class);
$this->call(UserSeeder::class);
factory(App\Product::class, 20)->create();
}
}
......@@ -61,7 +61,12 @@
>Update quantity</button>
</td>
<td class="hidden-xs text-center"><strong>Total € {{ $cart->total_price }}</strong></td>
<td><button class="btn btn-success btn-block">Checkout</button></td>
<td>
<form action="{{ route('order.sendOrder') }}" method="POST">
@csrf
<button class="btn btn-success btn-block">Send order</button>
</form>
</td>
</tr>
</tfoot>
</table>
......
......@@ -15,12 +15,12 @@
href="{{ $product->editPath() }}"
>Edit product</a>
</div>
<form method="POST" action="{{ $product->path() }}">
@csrf
@method('DELETE')
{{-- <form method="POST" action="{{ $product->path() }}">--}}
{{-- @csrf--}}
{{-- @method('DELETE')--}}
<button class="btn btn-outline-danger mt-5">Delete product</button>
</form>
{{-- <button class="btn btn-outline-danger mt-5">Delete product</button>--}}
{{-- </form>--}}
</div>
</section>
@endsection
......@@ -21,7 +21,7 @@ Route::prefix('product')->group(function() {
Route::get('/{product}', 'ProductController@show')->name('product.show');
Route::get('/{product}/edit', 'ProductController@edit')->name('product.edit');
Route::put('/{product}', 'ProductController@update');
Route::delete('/{product}', 'ProductController@destroy');
// Route::delete('/{product}', 'ProductController@destroy');
});
......@@ -37,3 +37,4 @@ Route::prefix('cart')->group(function() {
Route::post('/clear', 'CartController@clearCart')->name('cart.clearCart');
});
Route::post('order', 'OrderController@store')->name('order.sendOrder')->middleware('auth');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment