Help for integrating the Laravel package
Forum rules: Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
#2056 by swpierce
15 Nov 2015, 21:57
Got it! I had a typo in the manifest file. Lesson learned: use the extension generator you guys provide ;)

Now to figure out how to show products in subcategories when viewing the parent category.

Basically, if I'm in Category1 (which has subs of Subcategory1 and Subcategory2), I want to be able to see all the products in the tree from the top of the tree. If I drill down to Subcategory1, I only want to see those products and not any in the parent or sibling subs.
#2058 by aimeos
15 Nov 2015, 22:24
swpierce wrote:Got it! I had a typo in the manifest file. Lesson learned: use the extension generator you guys provide ;)


Yep, that helps :-)

swpierce wrote:Basically, if I'm in Category1 (which has subs of Subcategory1 and Subcategory2), I want to be able to see all the products in the tree from the top of the tree. If I drill down to Subcategory1, I only want to see those products and not any in the parent or sibling subs.


Use this method to retrieve the products by category/categories:
https://github.com/aimeos/aimeos-core/blob/2015.10/controller/frontend/src/Controller/Frontend/Catalog/Default.php#L186

Here is an example how it's used:
https://github.com/aimeos/aimeos-core/blob/2015.10/client/html/src/Client/Html/Catalog/Abstract.php#L364
#2070 by swpierce
18 Nov 2015, 14:04
As I'm looking at where to put the code for this (displaying products from subcategories in parent category list), I'm thinking a Decorator would be best option?

I don't really want to write another layout. I want to use the current catalog list layout. I just need to inject additional information before the view is rendered.

My thought is a Decorator applied to Html\Catalog\List\Default - in the Decorator, I can do something like:
Code: Select all$topCatId = $view->listCurrentCatItem->getId();
// perform search where catalog.parentid == topCatId to get list of children categories
// (or would doing something like catalogController->getCatalogPath($topCatId, $domains) be better?

// build an array of catalog IDs from the list we just pulled
$childIDs = .....;

// get a product controller and do a search where product.parentid in $childIDs
$productList = .....;

// merge the new product list with the product list set by Html\Catalog\List\Default
$currentCatProds = $view->listProductItems;
// $view->listProductItems = ($currentCatProds merged with $productList)


Does that make any sense at all? The sun isn't up and I haven't had my coffee yet so I might not be thinking clearly yet this morning. Is there an easier way?
#2071 by aimeos
18 Nov 2015, 15:01
Good morning :-)

swpierce wrote:As I'm looking at where to put the code for this (displaying products from subcategories in parent category list), I'm thinking a Decorator would be best option?


Decorators are cool and I think you can do it that way if you need a merged list of products from parent and child categories. But what about simply assigning the products from the child categories also to the parent category in the admin interface (or during the product import)? Seems to me a more elegant way and you additionally have full control over the product order in the list.