want to list child categories
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
- mahammadareef
- Posts: 50
- Joined: 14 Oct 2022, 11:54
want to list child categories
I wanted to show the next child categories lists of parent categories in the catalog List page when the parent category is active in catalog List page .............
please explain to me with steps to fulfill this ...
for checking, I am uploading an image ...
Thanks in advance ...
please explain to me with steps to fulfill this ...
for checking, I am uploading an image ...
Thanks in advance ...
Re: want to list child categories
You can use code similar to this one.
The first is a decorator for the catalog list component you have to place in ./src/Client/Html/Common/Decorator/ directory:
Then, you have to configure the decorator in the ./config/client.php file of your extension:
Finally, render the categories in the catalog/list/body.php template.
The first is a decorator for the catalog list component you have to place in ./src/Client/Html/Common/Decorator/ directory:
Code: Select all
<?php
namespace Aimeos\Client\Html\Common\Decorator;
class ListCategories
extends \Aimeos\Client\Html\Common\Decorator\Base
implements \Aimeos\Client\Html\Common\Decorator\Iface
{
public function addData( \Aimeos\Base\View\Iface $view, array &$tags = array(), string &$expire = null ) : \Aimeos\Base\View\Iface
{
$view = parent::addData( $view, $tags, $expire );
$view->listNode = \Aimeos\Controller\Frontend::create( $this->context(), 'catalog' )
->uses( ['media', 'text'] )->root( $view->param( 'f_catid' ) )
->getTree( \Aimeos\Controller\Frontend\Catalog\Iface::LIST );
return $view;
}
}
Code: Select all
'html' => [
'catalog' => [
'lists' => [
'decorators' => [
'global' => ['ListCategories']
],
],
],
],
Code: Select all
<?php if( isset( $this->listNode ) ) : ?>
<?php foreach( $this->listNode->getChildren() as $item ) : ?>
<a class="cat-item" href="<?= $enc->attr( $this->url( ( $item->getTarget() ?: $target ), $controller, $action, $params, [], $config ) ); ?>">
<?php if( $mediaItem = $item->getRefItems( 'media', 'default', 'default' )->first() ) : ?>
<img src="<?= $enc->attr( $mediaItem->getPreview() ) ?>" >
<?php endif ?>
<span class="cat-name"><?= $enc->html( $item->getName(), $enc::TRUST ); ?></span>
</a>
<?php endforeach; ?>
<?php endif ?>
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,

- PedroLópezAndradas
- Posts: 22
- Joined: 16 Jan 2023, 11:30
Re: want to list child categories
Thank you for your help and support in this forum
I'm trying to get same functionallity,but in common/partials/products.php
Where do I have to register my decorator?

I'm trying to get same functionallity,but in common/partials/products.php
Where do I have to register my decorator?
Code: Select all
'html' => [
'common' => [
'partials' => [
'decorators' => [
'global' => ['ListCategories']
],
],
],
],
- PedroLópezAndradas
- Posts: 22
- Joined: 16 Jan 2023, 11:30
Re: want to list child categories
I have tried to replicate this example in catalog/lists, and I'm unable to achieve it.
It is like if the decorator is not being used. Do we need to register somewhere else than in client.php config file on our extension?
It is like if the decorator is not being used. Do we need to register somewhere else than in client.php config file on our extension?
Code: Select all
<?php
return [
'html' => [
'themes' => [
'xxxx' => 'xxxx',
],
'theme-presets' => [
'xxxx' => [
'--ai-product-image-ratio' => '3/4',
'--ai-bg' => '#FFFFFF',
'--ai-bg-alt' => '#F6F6F6',
'--ai-primary' => '#FFF000',
'--ai-primary-alt' => '#282828',
'--ai-secondary' => '#555555',
'--ai-secondary-alt' => '#555555',
'--ai-tertiary' => '#CCCCCC',
'--ai-tertiary-alt' => '#F6F6F6',
'--ai-danger' => '#A00000',
'--ai-success' => '#006000',
'--ai-warning' => '#FFA500',
'--ai-radius' => '0',
]
],
'catalog' => [
'lists' => [
'decorators' => [
'global' => ['ListCategories']
],
],
],
],
'jsonapi' => [
],
];
Re: want to list child categories
You still have to register the decorator for the catalog/lists component but you want to use the data in a partial so you have to pass the new data to the partial too:
https://github.com/aimeos/ai-client-htm ... #L148-L157
https://github.com/aimeos/ai-client-htm ... #L148-L157
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,

- PedroLópezAndradas
- Posts: 22
- Joined: 16 Jan 2023, 11:30
Re: want to list child categories
Yes, but I'm having problems getting params from the view in the first example, directly in templates/client/html/catalog/lists/body.
My decorator:
My config:
My template client/html/catalog/lists/body.php:
I think I'm missing something important, because it is like if decorator is not being detected.
My decorator:
Code: Select all
<?php
namespace Aimeos\Client\Html\Common\Decorator;
class ListCategories
extends \Aimeos\Client\Html\Common\Decorator\Base
implements \Aimeos\Client\Html\Common\Decorator\Iface
{
public function addData( \Aimeos\Base\View\Iface $view, array &$tags = array(), string &$expire = null ) : \Aimeos\Base\View\Iface
{
$view = parent::addData( $view, $tags, $expire );
$view->set('test', 'hello');
return $view;
}
public function getCat(){
return 'ey!';
}
}
Code: Select all
<?php
return [
'html' => [
[...]
'catalog' => [
'lists' => [
'decorators' => [
'global' => ['ListCategories'],
],
],
],
],
'jsonapi' => [
],
];
Code: Select all
<?php
//Testing decorator
var_dump( $this->get( 'test' ) ); //Returns NULL
var_dump( $this->getCat() ); //Returns ERROR
?>
I think I'm missing something important, because it is like if decorator is not being detected.
Re: want to list child categories
The example code for ListCategories is for Aimeos 2021.x, in 2022.x the method has been renamed from "addData()" to "data()" only.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,

- PedroLópezAndradas
- Posts: 22
- Joined: 16 Jan 2023, 11:30
Re: want to list child categories
Yes! It works!
Thank you!
Now I have an error taking the url of the children categories, but I'll be able to figure out why.
Thanks!
Thank you!
Now I have an error taking the url of the children categories, but I'll be able to figure out why.
Thanks!