[Solved] Display nested categories

Questions around the TYPO3 integration and plugins
Forum rules
Always add your TYPO3, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
rowild

[Solved] Display nested categories

Post by rowild » 30 Sep 2019, 21:58

I use a category like this:

Language -> does NOT contain any products
- Phonetics -> contains products
- Voice Training -> contains products
- Breathing & Body -> contains products

The intention is to use the "Language" category for displaying its header and description. Its html is a fieldset that encompasses the children.
The first level of subchildren are again wrapped into a fieldset, each different color, checkboxes and radioboxes are used to select their embedded programs.

So far I was not successful do display child categories. The plugin has "Language" as its root category defined. The template looks like this:

Code: Select all

// catalog/lis/body-standard

<section class="aimeos catalog-list<?= $enc->attr( $classes ); ?>" data-jsonurl="<?= $enc->attr( $this->url( $optTarget, $optCntl, $optAction, [], [], $optConfig ) ); ?>">
	<div class="row">
		<div class="col-xs-12 col-lg-6">
			<?php if( isset( $this->listErrorList ) ) : ?>
				<ul class="error-list">
					<?php foreach( (array) $this->listErrorList as $errmsg ) : ?>
						<li class="error-item"><?= $enc->html( $errmsg ); ?></li>
					<?php endforeach; ?>
				</ul>
			<?php endif; ?>
			<fieldset class="fieldset-parent">
				<legend>
					<h2 class="catalog-list-head">
					<?php if( ( $catItem = end( $catPath ) ) !== false ) : ?>
						<?= $enc->html( $catItem->getName() ); ?>
					<?php endif; ?>
					</h2>
				</legend>
				<div class="row">
					<div class="col-xs-12">
						<!-- Products (Courses) - calls "item-body-standard.php" -->
						<!-- < ?= $this->block()->get( 'catalog/lists/items' ); ?> -->
						<!-- Display child categories here - try NAVIGATOR => wrong-->
						<?= $this->block()->get( 'catalog/stage/navigator' ); ?>
					</div>
				</div>
			</fieldset>
		</div>
	</div>
</section>
I read about "Creating your own Decorator" - would this be the way to go? If so, how to I call the db to get the children categories of the current one?

Or do I oversee something and aimeos covers that functionality already?

Thank you!
Last edited by rowild on 09 Nov 2020, 07:19, edited 1 time in total.

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

Re: Display nested categories

Post by aimeos » 01 Oct 2019, 09:48

You have to place the catalog filter plugin reduced to the tree subpart (by TS configuration) above your catalog list plugin and render the category children there. To render the children in the catalog/filter/tree-body-standard.php, you have to use

Code: Select all

foreach( $this->treeCatalogTree->getChildren() as $child )
to loop over the children of the root category.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

rowild

Re: Display nested categories

Post by rowild » 01 Oct 2019, 10:57

Thank you for your feedback!

If I use the filter plugin for displaying the category tree, then I assume I will not be able to display the products of the last nested category, right? The idea is to use the outer category or even categories as wrapper using their titles and descriptions; and only on the most inner part (= deepest category level, which in my case would be "2") there would be products.

The included screenshot examplifies what the goal should be:

Code: Select all

[level 0:] ROOT
[level 1:] - Schauspiel (no products here)
[level 2:] -- Schauspiel Grundlagen (this category has products)
[level 2:] -- Rollenarbeits-Zyklus (this category has products)
Since the idea is to use checkboxes, fieldsets are used to group courses. Therefor the nesting is so important...
(A live version of the how-it-should-be is here: https://www.schauspielschule.at/29/. This is done with formhandler, though, the school wants to switch to a shop system.)

My current solution is to put all those headers of the level-1 categories as regular headers and then place a "Catalog list" plugin with a preselected level-2 category beneath that header. That kind of works (do far, I am not finished), but the overview definitely suffers a lot, and there is also duplicate data (like category titles an descriptions...)

Any way to do this catalog-list?

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

Re: Display nested categories

Post by aimeos » 01 Oct 2019, 12:04

Our recommendation based on the link to the page you want to reproduce:
- Use a TYPO3 content element for "KURSE ÜBERBLICK UND ANMELDUNG" and the rest of the text
- Use one catalog list plugin for each category (e.g. for "Schauspiel" and "Stimme und Sprache")
- Use a selection product for each course (e.g. "SCHAUSPIEL GRUNDLAGEN [SG]")
- Use articles associated to the selection products for the items that are displayed inside the box for each selection product

You can get the attributes and articles for selection products if you add "product" and "attribute" to the list of domains using this configuration: https://aimeos.org/docs/Configuration/C ... ts/domains

To add a "add to basket" button for each article or adapt that to your needs, you can use:
- https://aimeos.org/docs/Configuration/C ... basket-add
- https://github.com/aimeos/ai-client-htm ... #L253-L312
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

rowild

Re: Display nested categories

Post by rowild » 01 Oct 2019, 19:19

Wow! This is fantastic advice! Very generous! Thank you!
I will give feedback as soon as I get to again!

rowild

Re: Display nested categories

Post by rowild » 02 Oct 2019, 06:31

I added new text types to "product", and they do show up at the proper place and take content (screenshots included below). Now I struggle with adding them to the display. My first thought is: "Add the new text types to the domain", do I try this:

Code: Select all

plugin.tx_aimeos.settings {
    client.html {
        catalog {
            lists {
                basket-add = 1
                domains =  {
                	0 = short
                	1 = course-date-time
                	2 = course-time
                }
            }
        }
    }
}
but I get this error message:

Code: Select all

 TypeError
Argument 1 passed to Aimeos\Controller\Frontend\Product\Standard::uses() must be of the type array, string given, called in /Volumes/_II_/_SITES/typo3-9-comp.oaa.lokal/ext/ai-client-html/client/html/src/Client/Html/Catalog/Lists/Standard.php on line 656
I also tried adding them to the "common/product-standard.php" template like this:

Code: Select all

// common/partials/products-standard.php
<div class="text-list">
	<h2 itemprop="name"><?= $enc->html( $productItem->getName(), $enc::TRUST ); ?></h2>
	<?php foreach( $productItem->getRefItems( 'short', 'course-date-start', 'course-time' ) as $textItem ) : ?>
		<div class="text-item" itemprop="description">
			<?= $enc->html( $textItem->getContent(), $enc::TRUST ); ?><br/>
		</div>
	<?php endforeach; ?>
</div>
I am pretty confused now... I wonder how long the list of my wrong-doings is!?!?? Can you help me?
Is there a way to get access to all the product-related items somehow? Or is there a tutorial somewhere that exemplifies the steps of how to do that?

– Thank you!

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

Re: Display nested categories

Post by aimeos » 02 Oct 2019, 07:06

This is wrong TS:

Code: Select all

                domains =  {
                	0 = short
                	1 = course-date-time
                	2 = course-time
                }
It must be:

Code: Select all

                domains {
                	0 = attribute
                	1 = media
                	2 = price
                	3 = product
                	4 = text
                }
All available texts are then automatically fetched. The parameters of getRefItems() are:

Code: Select all

$productItem->getRefItems( '<domain>', '<type>', '<list-type>' )
i.e. this gives you all short texts:

Code: Select all

$productItem->getRefItems( 'text', 'short' )
For the date and times you can use the "event" product type with start and end date. Thus, these articles won't be available any more if the course is over.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

rowild

Re: Display nested categories

Post by rowild » 02 Oct 2019, 07:53

Thank you again!!

Unfortunately, the error remains, if I use the TypoScript with the proper order...

And when I use the php snippet you recommended me, the "->getContent()" returns an error ("Call to a member function getContent() on array")... this is the snippet:

Code: Select all

<div class="texts">
	<pre>
	<?php
		$courseStartDate = $productItem->getRefItems( 'text', 'course-date-start' );
		var_export($courseStartDate);
		// echo $enc->html( $courseStartDate->getContent(), $enc::TRUST );
	?>
	</pre>
</div>
Any idea, what I am doing wrong here?

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

Re: Display nested categories

Post by aimeos » 02 Oct 2019, 09:24

getRefItems() always returns an array you have to loop over:

Code: Select all

foreach( $product->getRefItems( 'text' ) as $textItem ) {
	$textItem->getContent();
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

rowild

Re: Display nested categories

Post by rowild » 02 Oct 2019, 10:15

Ah! Ok! I got that now!
Thank you very much! Your help is highly appreciated!

Post Reply