<?php
use App\Models\Cart;
use App\Models\Shop;
use Illuminate\Support\Facades\Auth;

/** Get cart details */
function core_getCart()
{
    return Auth::guard('customer')->check() ?
        Cart::where('status', 'pending')->with(['cartPackages.package'])->where('user_id', Auth::guard('customer')->user()->id)->first() :
        Cart::where('status', 'pending')->with(['cartPackages.package'])->where('user_id', null)->where('ip', request()->getClientIp())->first();

}

/** check the special prices  */
function core_price($product = null)
{
    if($product != null){
        $now = date('Y-m-d');
        if($product->special_price >= 0)
            if($product->special_to != null)
                if($now >= $product->special_from && $now <= $product->special_to)
                    return $product->special_price;
                else
                    return $product->price;
            else
                return $product->special_price;
        else
            return $product->price;
    }
}


/** Convert to currency */
function core_currency_formate($amount = 0, $currency = '$')
{
    return $currency . number_format((float)$amount, 2, '.', '');
}


/** Default shop */
function core_shop()
{
    return Shop::where('is_default', '1')->first();
}
