Move categories list to top menu

Help for integrating the Laravel package
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!
MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Move categories list to top menu

Post by MikaelNazarenko » 25 Oct 2019, 10:37

Hi everybody) I have a top menu on the shop, and I want to add category dropdown to top menu. The main question here is I need to get categories on all pages. What should I extend and where (on which file/controller) I have to get categories to pass them to view that show them on top menu ?

Also the problem is that files app.blade.php and aimeos-nav.blade.php are blade views. If I create decorator or something and pass new values to view - sees I can't use it in blade..(( Here I am confused..

For example I created decorator:

Code: Select all

<?php

namespace Aimeos\Client\Html\Common\Decorator;

class Mydecorator extends Base
{
    public function addData( \Aimeos\MW\View\Iface $view, array &$tags = array(), &$expire = null )
    {
        $view = parent::addData( $view, $tags, $expire );

        // access already added data
//        $products = $view->get( 'listsItems', [] );

        // fetch some items from the database
        $view->var = 'data';

        return $view;
    }
}
But how can I use it in blade templates ?

Thank you all!

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

Re: Move categories list to top menu

Post by aimeos » 26 Oct 2019, 08:41

You can use the catalog frontend controller in your Laravel controller action to retrieve the category tree and assign it to the Blade template:

Code: Select all

$tree = \Aimeos\Controller\Frontend::create( $context, 'catalog' )->getTree();
return Response::view( 'shop::catalog.list', $params + ['categories' => $tree] );
Laravel doesn't support decorators in that context.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: Move categories list to top menu

Post by MikaelNazarenko » 26 Oct 2019, 08:46

Great thank you!! I was hanging at this point and didn't have ideas)

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: Move categories list to top menu

Post by MikaelNazarenko » 26 Oct 2019, 09:18

How to get context in Laravel controller ?

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

Re: Move categories list to top menu

Post by aimeos » 26 Oct 2019, 09:23

Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: Move categories list to top menu

Post by MikaelNazarenko » 26 Oct 2019, 11:17

Yes it works, I have displayed the categories at the top menu. But problem is how to generate correct url for categories ? I am in blade view, here the aimeos functions are not accessable ((

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

Re: Move categories list to top menu

Post by aimeos » 26 Oct 2019, 11:25

The Aimeos url() method only uses the Laravel route() method internally:
https://laravel.com/docs/6.0/urls#urls-for-named-routes
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: Move categories list to top menu

Post by MikaelNazarenko » 26 Oct 2019, 11:37

Where can I take a look at Aimeos url function ? I am confused because url function has less params that route function.

Code: Select all

$this->url( ( $item->getTarget() ?: $target ), $controller, $action, $params, [], $config )

Code: Select all

route('post.show', ['post' => 1]);

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

Re: Move categories list to top menu

Post by aimeos » 26 Oct 2019, 12:09

It boils down to this:

Code: Select all

route('aimeos_shop_list', ['f_catid' => 1])
https://github.com/aimeos/ai-laravel/bl ... l5.php#L61
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: Move categories list to top menu

Post by MikaelNazarenko » 26 Oct 2019, 12:23

Yes it works, but then url looks ugly /?f_catid=2. Can I customize this route. For example make it shop/category/{id}

Post Reply