Extending Aimeos Controller

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Bananamoon
Posts: 26
Joined: 22 Jun 2015, 09:12
Location: Herentals
Contact:

Extending Aimeos Controller

Post by Bananamoon » 17 Aug 2015, 08:49

Hello again! :-)

I'm trying to extend the CatalogController to change the listAction so I can add a bit of my own code.
The core problem lies in the fact that Aimeos uses the same view for /list and /list?catalogname=123. This means I don't have a difference in my homepage and an overview page of the products in a specific catalog.

I created a new controller, extended Catalogcontroller and wrote my own listAction function, only problem is that the routes are ofcourse, pointing to the original CatalogController, I'm not sure how to fix this so it uses my catalogController?

Thanks again! :-)

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

Re: Extending Aimeos Controller

Post by aimeos » 17 Aug 2015, 08:54

Bananamoon wrote: I'm trying to extend the CatalogController to change the listAction so I can add a bit of my own code.
The core problem lies in the fact that Aimeos uses the same view for /list and /list?catalogname=123. This means I don't have a difference in my homepage and an overview page of the products in a specific catalog.
What exactly do you want to achieve? Maybe there's a simpler method to get what you want if you can tell me what your two pages should contain.

Bananamoon
Posts: 26
Joined: 22 Jun 2015, 09:12
Location: Herentals
Contact:

Re: Extending Aimeos Controller

Post by Bananamoon » 17 Aug 2015, 09:33

aimeos wrote:
Bananamoon wrote: I'm trying to extend the CatalogController to change the listAction so I can add a bit of my own code.
The core problem lies in the fact that Aimeos uses the same view for /list and /list?catalogname=123. This means I don't have a difference in my homepage and an overview page of the products in a specific catalog.
What exactly do you want to achieve? Maybe there's a simpler method to get what you want if you can tell me what your two pages should contain.
the list page (homepage) should contain a slider, which should not be shown on the overview.
The overview on the other hand should have the filter showing.
In total, there's a whole different setup for both views.

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

Re: Extending Aimeos Controller

Post by aimeos » 17 Aug 2015, 10:04

Bananamoon wrote: the list page (homepage) should contain a slider, which should not be shown on the overview.
The overview on the other hand should have the filter showing.
In total, there's a whole different setup for both views.
OK, I would do it the same way :-)
To use another route, for your homepage, you have to change the configuration in your action:

Code: Select all

class HomepageController extends Controller
{
    public function listAction()
    {
        $context = app( 'Aimeos\Shop\Base\Context' )->get();
        $context->getConfig()->set( 'client/html/catalog/list/url/target', 'myproject_homepage' );
        // get and assign catalog list component to your view
    }
}
Afterwards, you need to define a new route:

Code: Select all

Route::match( array( 'GET', 'POST' ), '/', array(
	'as' => 'myproject_homepage,
	'uses' => 'HomepageController@listAction'
));
There's one thing to note: We need to merge a change made yesterday to the stable branch. Otherwise, the changed configuration will be stored if you use APCu and this would result in a flaky route :-)

Bananamoon
Posts: 26
Joined: 22 Jun 2015, 09:12
Location: Herentals
Contact:

Re: Extending Aimeos Controller

Post by Bananamoon » 17 Aug 2015, 10:22

aimeos wrote:
Bananamoon wrote: the list page (homepage) should contain a slider, which should not be shown on the overview.
The overview on the other hand should have the filter showing.
In total, there's a whole different setup for both views.
OK, I would do it the same way :-)
To use another route, for your homepage, you have to change the configuration in your action:

Code: Select all

class HomepageController extends Controller
{
    public function listAction()
    {
        $context = app( 'Aimeos\Shop\Base\Context' )->get();
        $context->getConfig()->set( 'client/html/catalog/list/url/target', 'myproject_homepage' );
        // get and assign catalog list component to your view
    }
}
Afterwards, you need to define a new route:

Code: Select all

Route::match( array( 'GET', 'POST' ), '/', array(
	'as' => 'myproject_homepage,
	'uses' => 'HomepageController@listAction'
));
There's one thing to note: We need to merge a change made yesterday to the stable branch. Otherwise, the changed configuration will be stored if you use APCu and this would result in a flaky route :-)
Just to make sure I understand it all, in the code you wrote above, I am redefining my '/list' route, right? So for the overview page I can just use the default /list for these kind of urls: list?f_name=cat-1&f_catid=4451?

about the merge, I can just update through composer and all is fine? or not? :P

Thanks for your help!

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

Re: Extending Aimeos Controller

Post by aimeos » 17 Aug 2015, 10:28

Bananamoon wrote: Just to make sure I understand it all, in the code you wrote above, I am redefining my '/list' route, right? So for the overview page I can just use the default /list for these kind of urls: list?f_name=cat-1&f_catid=4451?
Not exactly a redefinition but you create a new route (myproject_homepage) instead. The "/list" route will continue to work as expected, you only change the used route name in the catalog list component for the homepage.
Bananamoon wrote: about the merge, I can just update through composer and all is fine? or not? :P
Yes, that will be the case :-)

Bananamoon
Posts: 26
Joined: 22 Jun 2015, 09:12
Location: Herentals
Contact:

Re: Extending Aimeos Controller

Post by Bananamoon » 17 Aug 2015, 10:47

aimeos wrote:
Bananamoon wrote: Just to make sure I understand it all, in the code you wrote above, I am redefining my '/list' route, right? So for the overview page I can just use the default /list for these kind of urls: list?f_name=cat-1&f_catid=4451?
Not exactly a redefinition but you create a new route (myproject_homepage) instead. The "/list" route will continue to work as expected, you only change the used route name in the catalog list component for the homepage.
Bananamoon wrote: about the merge, I can just update through composer and all is fine? or not? :P
Yes, that will be the case :-)
Superb, thanks!

About the views itself, I will have to rewrite components for the homepage too. I found in the shop config file the pages, where you can add and remove components. Can I create my own component/page to go with the homepage?
I tried earlier to create a component (catalog/overview), but failed to succeed. It gave me an error about a missing factory.php file or something.

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

Re: Extending Aimeos Controller

Post by aimeos » 17 Aug 2015, 11:47

Bananamoon wrote: About the views itself, I will have to rewrite components for the homepage too. I found in the shop config file the pages, where you can add and remove components. Can I create my own component/page to go with the homepage?
I tried earlier to create a component (catalog/overview), but failed to succeed. It gave me an error about a missing factory.php file or something.
Yes, sure! Here's the documentation:
https://aimeos.org/docs/Laravel/Create_new_pages
https://aimeos.org/docs/Developers/Html ... components

For the factory, simply copy and adapt the Factory.php of the catalog list component. We will add that part to the documentation too :-)

Bananamoon
Posts: 26
Joined: 22 Jun 2015, 09:12
Location: Herentals
Contact:

Re: Extending Aimeos Controller

Post by Bananamoon » 17 Aug 2015, 12:02

aimeos wrote:
Bananamoon wrote: About the views itself, I will have to rewrite components for the homepage too. I found in the shop config file the pages, where you can add and remove components. Can I create my own component/page to go with the homepage?
I tried earlier to create a component (catalog/overview), but failed to succeed. It gave me an error about a missing factory.php file or something.
Yes, sure! Here's the documentation:
https://aimeos.org/docs/Laravel/Create_new_pages
https://aimeos.org/docs/Developers/Html ... components

For the factory, simply copy and adapt the Factory.php of the catalog list component. We will add that part to the documentation too :-)
Nice, thanks! Really appreciate the work you guys put in this shop! ;)

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

Re: Extending Aimeos Controller

Post by aimeos » 17 Aug 2015, 17:20

Bananamoon wrote:Nice, thanks! Really appreciate the work you guys put in this shop! ;)
Thank you very much but don't forget the girls! ;-)

The documentation for creating the factory class is now available too:
https://aimeos.org/docs/Developers/Html ... tory_class

If you finished you project, would you mind answering a few questions? :-)

Post Reply