Al-HUWAITI Shell
Al-huwaiti


Server : nginx/1.18.0
System : Linux localhost 6.14.3-x86_64-linode168 #1 SMP PREEMPT_DYNAMIC Mon Apr 21 19:47:55 EDT 2025 x86_64
User : www-data ( 33)
PHP Version : 8.0.16
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/www/ecommerce/app/Http/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/ecommerce/app/Http/Helper.php
<?php
use App\Models\Cart;
use App\Models\Category;
use App\Models\Message;
use App\Models\Order;
use App\Models\PaymentMethod;
use App\Models\PostCategory;
use App\Models\PostTag;
use App\Models\Product;
use App\Models\Shipping;
use App\Models\Wishlist;
use App\Models\Option;
use Illuminate\Support\Facades\Cookie;

// use Illuminate\Support\Facades\Auth;
class Helper
{
    public static $dbSettings = null;
    public static $cartProducts = null;
    public static $wishlistProducts = null;
    public static $dbCategories = null;
    public static $recentlyViewed = null;

    public static function messageList()
    {
        return Message::whereNull('read_at')->orderBy('created_at', 'desc')->get();
    }

    public static function getAllCategory()
    {
        if (!static::$dbCategories) {
            static::$dbCategories = Category::getAllParentWithChild();
        }

        return static::$dbCategories;
    }

    public static function getHeaderCategory()
    {
        $menu = static::getAllCategory();

        if ($menu) {
            ?>

            <li>
            <a href="javascript:void(0);">Category<i class="ti-angle-down"></i></a>
                <ul class="dropdown border-0 shadow">
                <?php
                    foreach ($menu as $cat_info) {
                        if ($cat_info->child_cat->count() > 0) {
                            ?>
                            <li><a href="<?php echo route('product-cat', $cat_info->slug); ?>"><?php echo $cat_info->title; ?></a>
                                <ul class="dropdown sub-dropdown border-0 shadow">
                                    <?php
                                    foreach ($cat_info->child_cat as $sub_menu) {
                                        ?>
                                        <li><a href="<?php echo route('product-sub-cat', [$cat_info->slug, $sub_menu->slug]); ?>"><?php echo $sub_menu->title; ?></a></li>
                                        <?php
                                    } ?>
                                </ul>
                            </li>
                            <?php
                        } else {
                            ?>
                                <li><a href="<?php echo route('product-cat', $cat_info->slug); ?>"><?php echo $cat_info->title; ?></a></li>
                            <?php
                        }
                    } ?>
                </ul>
            </li>
        <?php
        }
    }

    public static function productCategoryList($option = 'all')
    {
        if ($option = 'all') {
            return Category::orderBy('id', 'DESC')->get();
        }

        return Category::has('products')->orderBy('id', 'DESC')->get();
    }

    public static function postTagList($option = 'all')
    {
        if ($option = 'all') {
            return PostTag::orderBy('id', 'desc')->get();
        }

        return PostTag::has('posts')->orderBy('id', 'desc')->get();
    }

    public static function postCategoryList($option = 'all')
    {
        if ($option = 'all') {
            return PostCategory::orderBy('id', 'DESC')->get();
        }

        return PostCategory::has('posts')->orderBy('id', 'DESC')->get();
    }

    // Cart Count
    public static function cartCount($user_id = '')
    {
        if (Auth::check()) {
            if ($user_id == '') {
                $user_id = auth()->id();
            }

            return static::getAllProductFromCart()->sum('quantity');
        } else {
            return 0;
        }
    }

    public static function getAllProductFromCart($user_id = '')
    {
        if (Auth::check()) {
            if ($user_id == '') {
                $user_id = auth()->id();
            }

            if (!static::$cartProducts) {
                static::$cartProducts = Cart::with('product')->where('user_id', $user_id)->where('order_id', null)->get();
            }

            return static::$cartProducts;
        }

        return [];
    }

    // Total amount cart
    public static function totalCartPrice($user_id = '')
    {
        if (Auth::check()) {
            if ($user_id == '') {
                $user_id = auth()->id();
            }

            return static::getAllProductFromCart()->sum('amount');
        } else {
            return 0;
        }
    }

    // Wishlist Count
    public static function wishlistCount($user_id = '')
    {
        if (Auth::check()) {
            if ($user_id == '') {
                $user_id = auth()->id();
            }

            return static::getAllProductFromWishlist()->sum('quantity');
        } else {
            return 0;
        }
    }

    public static function getAllProductFromWishlist($user_id = '')
    {
        if (Auth::check()) {
            if ($user_id == '') {
                $user_id = auth()->id();
            }

            if (!static::$wishlistProducts) {
                static::$wishlistProducts = Wishlist::with('product')->where('user_id', $user_id)->where('cart_id', null)->get();
            }

            return static::$wishlistProducts;
        }

        return collect();
    }

    public static function totalWishlistPrice($user_id = '')
    {
        if (Auth::check()) {
            if ($user_id == '') {
                $user_id = auth()->id();
            }

            return static::getAllProductFromWishlist()->sum('amount');
        } else {
            return 0;
        }
    }

    // Total price with shipping and coupon
    public static function grandPrice($id, $user_id)
    {
        $order = Order::find($id);
        dd($id);
        if ($order) {
            $shipping_price = (float) $order->shipping->price;
            $order_price = self::orderPrice($id, $user_id);

            return number_format((float) ($order_price + $shipping_price), 2, '.', '');
        } else {
            return 0;
        }
    }

    // Admin home
    public static function earningPerMonth()
    {
        $month_data = Order::where('status', 'delivered')->get();
        // return $month_data;
        $price = 0;
        foreach ($month_data as $data) {
            $price = $data->cart_info->sum('price');
        }

        return number_format((float) ($price), 2, '.', '');
    }

    public static function shipping()
    {
        return Shipping::orderBy('id', 'DESC')->get();
    }

    public static function paymentMethods()
    {
        return PaymentMethod::all();
    }

    public static function imagePath(string $path)
    {
        return str_replace('shop/', '', $path[0] == 'h' ? $path : "/{$path}");
    }

    public static function getSettings()
    {
        if (!static::$dbSettings) {
            static::$dbSettings = DB::table('settings')->get();
        }

        return static::$dbSettings;
    }

    public static function getRecentlyViewedProducts()
    {
        if (!static::$recentlyViewed) {
            if (Cookie::has(Product::RECENTLY_VIEWED)) {
                $recentlyViewed = explode(',', Cookie::get(Product::RECENTLY_VIEWED));
            } else {
                $recentlyViewed = [];
            }

            if (count($recentlyViewed)) {
                static::$recentlyViewed = Product::with(['getReview', 'cat_info'])->where('status', 'active')->whereIn('id', array_splice($recentlyViewed, 0, 8))->get();
            } else {
                static::$recentlyViewed = [];
            }
        }

        return static::$recentlyViewed;
    }

    public static function getPaymentFrequency($price)
    {
        $settings = (object) Option::getOptions('settings');
        foreach (range(0, 9) as $i) {
            $maxPrice = $settings->{"max_price_$i"};
            $installment = $settings->{"installment_{$i}"};

            if ($maxPrice >= $price) {
                return $installment;
            }
        }
    }
}

?>

Al-HUWAITI Shell