File: D:/HostingSpaces/SBogers10/douven.komma.pro/app/KommaApp/Shop/Categories/CategoryController.php
<?php
namespace App\KommaApp\Shop\Categories;
use App\Http\Controllers\Controller;
use App\KommaApp\Shop\Catalog\Kms\CatalogService;
use App\KommaApp\Shop\Categories\Kms\CategoryService;
use App\KommaApp\Shop\Categories\Kms\CategoryServiceInterface;
use App\KommaApp\Shop\Categories\Models\Category;
use App\KommaApp\Shop\Categories\Models\CategoryTranslation;
class CategoryController extends Controller
{
private $pagePrefix = 'shop.pages.categories.';
private $subpagePrefix = 'shop.pages.subcategories.';
private $catalogService;
protected $categoryService;
public function __construct(CatalogService $catalogService, CategoryServiceInterface $categoryService)
{
parent::__construct();
$this->categoryService = $categoryService;
$this->catalogService = $catalogService;
}
/**
* @return \Illuminate\Contracts\View\View
*/
public function index()
{
$page = $this->pageService->getPageByCodeName('categories');
$page->translation = $this->decodeDynamicContent( $page->translation );
$transportServicePage = $this->pageService->getPageByCodeName('transportservice');
$transportServicePage->load('images');
$transportServicePage->translation = $this->decodeDynamicContent($transportServicePage->translation);
// Return view
return \View::make($this->pagePrefix . 'index', [
'page' => $page,
'links' => $this->links,
'categoryTree' => $this->categoryTree,
'transportServicePage' => $transportServicePage,
]);
}
/**
* @return \Illuminate\Contracts\View\View
*/
public function filters()
{
$filters = request('filters');
$page = $this->pageService->getPageByCodeName('categories');
// Return view
return \View::make($this->pagePrefix . 'index', [
'page' => $page,
'links' => $this->links,
'categoryTree' => $this->categoryTree,
]);
}
/**
* @param Category $category
* @return \Illuminate\Contracts\View\View
* @internal param CategoryTranslation $categoryTranslation
* @internal param Page $page
*/
public function show(Category $category)
{
$category->load('translation', 'images');
if ($category->getChildrenCount() > 0) {
// main category
$subcategories = $category->findChildren();
foreach ($subcategories as $subcategory) {
$subcategory->load('translation', 'images');
}
// Return view
return \View::make($this->pagePrefix . 'show', [
//'page' => $page,
'category' => $category,
'subcategories' => $subcategories,
'links' => $this->links,
'categoryTree' => $this->categoryTree,
]);
} else {
// subcategory
$currentPage = \Request::has('page') ? \Request::get('page') : 1;
$parent = $category->getParent();
$parent->load('translation');
$categoryItems = $this->catalogService->getItemsByCategoryID($category->id, 6, $currentPage);
if(count($categoryItems) > 0) {
$categoryItems->withPath('/aanbod/' . $parent->translation->name . '/' . $category->translation->name);
}
$subcategorySiblings = $parent->findChildren();
// Return view
return \View::make($this->subpagePrefix . 'show', [
//'page' => $page,
'category' => $category,
'categoryItems' => $categoryItems,
'subcategorySiblings' => $subcategorySiblings,
'categoryTree' => $this->categoryTree,
'parent' => $parent,
'links' => $this->links,
]);
}
}
}