<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;

class CartController extends Controller {

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index() {
        return view('cart-page');
    }

    public function add_item_to_cart(Request $request) {
        $item_stockid = $request->get('item_stock_id');
        $item_name = $request->get('item_name');
        $item_category = $request->get('item_category');
        $item_image = $request->get('item_image');
        $item_color = $request->get('item_color');
        $item_colorid = $request->get('item_color_id');
        $item_size = $request->get('item_size');
        $item_sizeid = $request->get('item_size_id');
        $item_price = $request->get('item_price');

        $cart_item = array(
            'item_stock_id' => $item_stockid,
            'item_name' => $item_name,
            'item_category' => $item_category,
            'item_size' => $item_size,
            'item_size_id' => $item_sizeid,
            'item_color' => $item_color,
            'item_color_id' => $item_colorid,
            'item_image' => $item_image,
            'item_price' => $item_price
        );
        if (Session::has('cartdata')) {
            $cart = Session::get('cartdata');
            array_push($cart, $cart_item);
            Session::put("cartdata", $cart);
        } else {
            $cart = [];
            array_push($cart, $cart_item);
            Session::put("cartdata", $cart);
        }
        return redirect('checkout');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create() {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @return Response
     */
    public function store() {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function show($id) {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function edit($id) {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function update($id) {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function destroy($id) {
        //
    }

}
