File: D:/HostingSpaces/SBogers95/rentman.io/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;
}
}