<?php
namespace Clevercherry\Backslash4\Controllers;

use App\Models\Wishlist;
use Clevercherry\Backslash4\Traits\cartControl;

class WishlistController extends Controller
{
    use cartControl;
    public static $cartName = 'wishlist';

    
    //implement this function as cartControl does not interact with Models
    public static function saveCart($cart = null)
    {
        if(empty($cart))
            $cart = self::getCalcCart();
            
            //session()->getId();
        if(isset($cart['id']) && !empty($cart['id']))
        {
                Wishlist::where('id', $cart['id'])->update(
                    [   'items' => json_encode($cart['items']),
                        'total_nett' => $cart['total_nett'],
                        'total_shipping' => $cart['shipping'],
                        'total_gross' => $cart['total_gross']
                    ]);

        } else
        {
                $newRecord = new Wishlist;
                $newRecord->items = json_encode($cart['items']);
                $newRecord->total_nett = $cart['total_nett'];
                $newRecord->total_gross = $cart['total_gross'];
                $newRecord->total_shipping = $cart['shipping'];
                $newRecord->save();
                $cart['id'] = $newRecord->id;
        }

        self::putCart($cart);
    }

}
