File: D:/HostingSpaces/stafa/werkenbijstafa.nl/app/Komma/Shop/Products/ProductController.php
<?php
namespace App\Komma\Shop\Products;
use App\Komma\Base\Controller;
use App\Komma\Shop\Catalog\Kms\CatalogService;
use App\Komma\Shop\Products\Product\Product;
class ProductController extends Controller
{
private $pagePrefix = 'shop.pages.products.';
private $catalogService;
public function __construct(CatalogService $catalogService)
{
parent::__construct();
$this->catalogService = $catalogService;
}
/**
* @return \Illuminate\Contracts\View\View
*/
public function index()
{
$page = $this->pageService->getPageByCodeName('products');
$otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);
$allItems = $this->catalogService->getAllItems();
// Return view
return view($this->pagePrefix.'index',[
'page' => $page,
'links' => $this->links,
'otherLanguages' => $otherLanguageRoutes,
'items' => $allItems,
]);
}
/**
* @return \Illuminate\Contracts\View\View
*/
public function filters()
{
$filters = request('filters');
var_dump('Filter posts with these filters:');
$page = $this->pageService->getPageByCodeName('products');
$otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);
//$posts = $this->productService->getAllPosts(true);
$products = $this->catalogService->modelsWithoutGroups(); //All products that are not in groups or composites with their translation for the current language
// Return view
return view($this->pagePrefix.'index',[
'page' => $page,
'links' => $this->links,
'otherLanguages' => $otherLanguageRoutes,
'products' => $products,
]);
}
/**
* @param Page $page
* @return \Illuminate\Contracts\View\View
*/
public function show(Product $product)
{
$product->load('translation', 'sites');
// This checks if the post belongs to the set site
if(! $product->sites->contains($this->site)) throw abort(404);
$page = $this->pageService->getPageByCodeName('products');
$otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page, $product);
// Return view
return view($this->baseViewPath.$this->pagePrefix.'show',[
'page' => $page,
'product' => $product,
'links' => $this->links,
'otherLanguages' => $otherLanguageRoutes
]);
}
}