I need favorite items on a custom page
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!
- parmonov98
- Posts: 33
- Joined: 24 Sep 2020, 12:12
I need favorite items on a custom page
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.
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.
Re: I need favorite items on a custom page
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:
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.
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']
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,

Re: I need favorite items on a custom page
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:
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:
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:
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.
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);
}
}
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
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'
] );
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.
Re: I need favorite items on a custom page
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!
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!