I need favorite items on a custom page

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!
User avatar
parmonov98
Posts: 33
Joined: 24 Sep 2020, 12:12

I need favorite items on a custom page

Post by parmonov98 » 12 Oct 2020, 18:35

I need favorite items on a custom page
I created a controller and view.
Can I use any built-in components? or Do I have to write my own?

and how? I know you point me I have to read docs, I tried many times. and I'll be reading when you read this topic. but anyways, please write a post about creating custom components.

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

Re: I need favorite items on a custom page

Post by aimeos » 13 Oct 2020, 10:02

Create a new controller and use existing components:
https://aimeos.org/docs/latest/laravel/ ... eate-pages

In your ./config/shop.php there's a "page" section where you can add:

Code: Select all

'mypage' => ['account/favorite']
This will display the account/favorite component in your new page. Be aware that the user must be logged in to see his favorite products. If you only want a session based product list, use the "catalog/session" component instead which has a subpart for pinned products.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

kdim95
Advanced
Posts: 196
Joined: 26 Aug 2022, 12:17

Re: I need favorite items on a custom page

Post by kdim95 » 31 Oct 2022, 23:06

I had the same task, but struggled a bit while getting the custom page to work, so I want to add some details on how I did it, hopefully it helps others.

I placed the controller in src/Controllers/FavouritesController.php.

The controller looks like this:

Code: Select all

namespace App\Http\Controllers;

use Aimeos\Shop\Facades\Shop;

class FavouritesController extends Controller
{
    public function indexAction()
    {
        foreach( config( 'shop.page.account-favourites' ) as $name )
        {
            $params['aiheader'][$name] = Shop::get( $name )->header();
            $params['aibody'][$name] = Shop::get( $name )->body();
        }
        return \View::make('favourites', $params);
    }
}
Inside /config/shop.php:
Under page I added account-favourites => [ 'catalog/search', 'basket/mini', 'catalog/tree', 'account/favorite' ]

A new blade template needs to be created. I placed it inside /resources/views/favourites.blade.php
I also tried to place the blade template in my extension under /views but it wasn't accepting it from there.
Likely I forgot details on how to use it from there.

The blade template looks something like this:

Code: Select all

@extends('default::base')

@section('aimeos_header')
	<?= $aiheader['catalog/search'] ?? '' ?>
	<?= $aiheader['basket/mini'] ?? '' ?>
	<?= $aiheader['catalog/tree'] ?? '' ?>
	<?= $aiheader['account/favorite'] ?? '' ?>
@stop

@section('aimeos_head_search')
    <?= $aibody['catalog/search'] ?? '' ?>
@stop

@section('aimeos_head_basket')
    <?= $aibody['basket/mini'] ?? '' ?>
@stop

@section('aimeos_head_nav')
    <?= $aibody['catalog/tree'] ?? '' ?>
@stop

@section('aimeos_body')
    <div class="container-fluid">
        <?= $aibody['account/favorite'] ?? '' ?>
    </div>
@stop
You need to have routing for this new page inside /routes/web.php
The routing has a middleware check if the user is authenticated.
If the user is not authenticated, he or she is redirected to the login page.
That is because favourites can only be viewed for logged in users.

The favourites routing looks like this:

Code: Select all

Route::match( ['GET', 'POST'], '/favourites', [
	'middleware' => ['auth'],
	'as' => 'aimeos_favourites',
	'uses'=> 'App\Http\Controllers\FavouritesController@indexAction'
] );
Remember to place this routing before any CMS Pages routing, or it won't work.

Command composer dump-autoload or composer up should be used to get the controller to work.
It's composer autoloading stuff that loads the controller class into memory.

Now you should be able to use {{ airoute(aimeos_favourites) }} in your blade templates to get the link to the page.

User avatar
peter69
Posts: 95
Joined: 09 Jun 2022, 19:31

Re: I need favorite items on a custom page

Post by peter69 » 16 Feb 2023, 20:49

I have created several pages with the steps described in this topic,
Thank you very much!

I certainly think it is a much better option to create the pages with code/manually instead of doing it with the CMS module. The CMS module complicates certain parts of the development process because you have to create many components and traits (in order to have modern designs and customization options). I recently did it and found that it took me much longer to create so many components and traits for GrapesJS.

I leave this comment in case it is helpful to anyone,

Regards!

Post Reply