Page 1 of 1

How to show single level of subcategories with images on home page?

Posted: 26 Mar 2020, 21:56
by xarga
This is my first Aimeos project. Currently I have the catalog filter tree residing in a menu that slides out from the left side when a menu icon is clicked. This is working fine.

However, on the home page I wish to show only the first level of sub-categories along with their category images and descriptions.

My catalog tree is

HOME
>Bakery
> >Breads
> >Cakes
>Meals
> >Single Serve
> >Family Size

So on the home (HOME Level) page I wish to display just the Bakery and Meals categories (not the products) with their category images and descriptions.(without altering the catalog filter in the slideout menu)

How would I achieve that?
I tried using <?= $aibody['catalog/filter'] ?> but this just duplicated my slideout menu.

from my composer.json:
"require": {
"php": "^7.2",
"aimeos/ai-payments": "^2019.10",
"aimeos/aimeos-laravel": "~2019.10",
"fideloper/proxy": "^4.0",
"laravel/framework": "^6.0",
"laravel/tinker": "^1.0",
"laravel/ui": "^1.0",
"league/omnipay": "^3.0",
"omnipay/stripe": "^3.1",
"guzzlehttp/guzzle":">=6.3.0 <6.5.0 || ^6.5.1"
},

Re: How to show single level of subcategories with images on home page?

Posted: 27 Mar 2020, 17:07
by aimeos
In your home controller, you can use the Catalog facade to retrieve the data:

Code: Select all

$categories = \Aimeos\Shop\Facades\Catalog::uses(['text', 'media'])
	->getTree(\Aimeos\MW\Tree\Manager\Base::LEVEL_LIST);

Re: How to show single level of subcategories with images on home page?

Posted: 30 Mar 2020, 21:17
by xarga
This doesn't appear to work but perhaps I've implemented it incorrectly?

I've copied the shop\app\Http\Controllers\HomeController up into my active extension directory

ext\myshop\controller\frontend\HomeController.php

In the index method I now have

public function index()
{
$categories = \Aimeos\Shop\Facades\Catalog::uses(['text', 'media'])
->getTree(\Aimeos\MW\Tree\Manager\Base::LEVEL_LIST);

return view('home')->with('categories', $categories);
}
-----------------------

If I dump the categories in the controller it doesn't interrupt the application indicating that this HomeController is not active in http://localhost:8000/shop

(I have cleared the cache)

Re: How to show single level of subcategories with images on home page?

Posted: 01 Apr 2020, 07:19
by aimeos
You can't overwrite the Laravel shop\app\Http\Controllers\HomeController.php controller. Instead, you have to add your code in that class directly.

Re: How to show single level of subcategories with images on home page?

Posted: 10 Jun 2021, 23:08
by bigolho16
aimeos wrote: 27 Mar 2020, 17:07 In your home controller, you can use the Catalog facade to retrieve the data:

Code: Select all

$categories = \Aimeos\Shop\Facades\Catalog::uses(['text', 'media'])
	->getTree(\Aimeos\MW\Tree\Manager\Base::LEVEL_LIST);
Sou iniciante no Aimeos, por favor onde fica este controlador?