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

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
xarga
Posts: 43
Joined: 16 Dec 2019, 22:54

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

Post by xarga » 26 Mar 2020, 21:56

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"
},

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

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

Post by aimeos » 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);
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

xarga
Posts: 43
Joined: 16 Dec 2019, 22:54

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

Post by xarga » 30 Mar 2020, 21:17

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)

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

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

Post by aimeos » 01 Apr 2020, 07:19

You can't overwrite the Laravel shop\app\Http\Controllers\HomeController.php controller. Instead, you have to add your code in that class directly.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
bigolho16
Posts: 3
Joined: 10 Jun 2021, 22:50

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

Post by bigolho16 » 10 Jun 2021, 23:08

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?

Post Reply