HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/rentman2019.komma.pro/app/Komma/Products/ProductService.php
<?php

namespace App\Komma\Products;

use App\Komma\Base\Service;
use Carbon\Carbon;

class ProductService extends Service
{
    private $today;

    public function __construct()
    {
        $this->today = Carbon::now()->addHour();
        $this->today = $this->today->format('Y-m-d H:i:s');

        parent::__construct();
    }

    public function appendProductsToLinks(&$links)
    {
        // If the products page isn't found, return
        if (! isset($links->products)) {
            return;
        }

        // Find all pages
        if (! $products = $this->site
            ->products()
            ->where('lft', '!=', 1)
            ->orderBy('lft', 'asc')
            ->has('translations')
            ->has('productGroup')
            ->with('translations', 'productGroup', 'productGroup.translation')
            ->get()
        ) {
            return;
        }

        $this->appendModelsToLinks($links, $products, 'product', $links->products);
    }

    public function getAllProducts($pagination = false, $itemsPerPage = 9)
    {
        $products = $this->site
            ->products()
            ->with('translation')
            ->where('lft', '!=', 1)
            ->orderBy('lft', 'desc')

            // We need to use a join to select the active solution because that is defined on the translations
            ->join('product_translations', 'products.id', '=', 'product_translations.product_id')
            ->select('products.*', 'product_translations.active', 'product_translations.language_id')
            ->where('active', 1)
            ->where('language_id', \App::getLanguage()->id);

        if ($pagination) {
            $products = $products->paginate($itemsPerPage);
        } else {
            $products = $products->get();
        }

        return $products;
    }
}