Help for integrating the Laravel package
Forum rules: Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
#7447 by Trent
01 Jan 2019, 17:04
Hello everyone,

I'm sorry to trouble you all. I'm just wondering if there was a way to see where the /list page blade is or if there are example pages to learn from (controllers and all?).

I'm currently doing this https://aimeos.org/docs/Laravel/Create_new_pages to create my own custom listing page but am getting the following error attached. My biggest questions at the moment are:

1) Where can I view the listing, display and default blade php
2) How do I add things to the basket that correspond to the page it is on? Example: I pull details of an item from the database. I want to add that specific item to the basket. I believe this is just a matter of figuring out how to use the basket?

Thanks a lot for your time everyone. I'm off to work now but I'll reply as soon as I get back!
Attachments
Screenshot from 2019-01-01 17-00-16.png
Screenshot from 2019-01-01 17-00-16.png (81.84 KiB) Viewed 361 times
#7452 by aimeos
02 Jan 2019, 16:37
In the default Blade templates you only see how the existing components are integrated.

If you want to create a list page of your own, you should write a controller/action that contains similar code to that one:
Code: Select all$context = app( '\Aimeos\Shop\Base\Context' )->get();
$cntl = \Aimeos\Controller\Frontend\Factory::createController( $context, 'product' );
$filter = $cntl->createFilter();
$filter->setConditions( $filter->compare( '==', 'product.code', 'test' ) );
$items = $cntl->searchItems( $filter, ['text', 'media', 'attribute'] );


If you have the product items, you can create the HTML form that adds your products to the basket. The available parameters are described here: https://aimeos.org/docs/Developers/Html_frontend/Used_parameter_names#Basket
#7454 by Trent
02 Jan 2019, 18:40
aimeos wrote:In the default Blade templates you only see how the existing components are integrated.

If you want to create a list page of your own, you should write a controller/action that contains similar code to that one:
Code: Select all$context = app( '\Aimeos\Shop\Base\Context' )->get();
$cntl = \Aimeos\Controller\Frontend\Factory::createController( $context, 'product' );
$filter = $cntl->createFilter();
$filter->setConditions( $filter->compare( '==', 'product.code', 'test' ) );
$items = $cntl->searchItems( $filter, ['text', 'media', 'attribute'] );


If you have the product items, you can create the HTML form that adds your products to the basket. The available parameters are described here: https://aimeos.org/docs/Developers/Html_frontend/Used_parameter_names#Basket


Thank you so much for the reply!

I'm trying to find the default templates to learn from them. The issue is I'm not sure where they are (default blade php and default controller) and where I can go to alter the default css of some of the defaults.

The code you pasted explains a lot of things but being a noob at this could I ask for you to elaborate a bit or point me to the direction to read? From my understanding:

- Context gets the data in the db. A controller is created to search specific data from the database and the filters out data from that set which is where the product code is equal to test. Then the items is actually the items where filter is true and we just grab the 3 parameters there.

From here I assume we're passing the $items to the view and calling it as normal $items as $item -> $item->text etc. Am I off?
Attachments
Screenshot from 2019-01-02 18-39-19.png
Screenshot from 2019-01-02 18-39-19.png (6.58 KiB) Viewed 350 times
Screenshot from 2019-01-02 18-39-09.png
Seems as though css won't load when I try to load it by myself as opposed to the default /list page
Screenshot from 2019-01-02 18-39-09.png (7.53 KiB) Viewed 350 times
#7460 by aimeos
03 Jan 2019, 16:59
The components itself are not yet written as Blade templates but use plain PHP. You can have a look at them here:
https://github.com/aimeos/ai-client-html/tree/master/client/html/templates

You can have a look at the product detail template which contains many information:
https://github.com/aimeos/ai-client-html/blob/master/client/html/templates/catalog/detail/body-standard.php

Here you can see the form for putting the product into the basket:
https://github.com/aimeos/ai-client-html/blob/master/client/html/templates/catalog/detail/body-standard.php#L284

The posted code consists of:
- Get the context you need to access the database
- Create the product controller which is able to retrieve the products
- Create a filter to search for specific products
- Add a filter condition to look up a product by its code
- Retrieve the list of products including related texts, media and attributes

When you pass the list of items to the view, you can loop over them and output e.g.:
- name : $item->getName()
- list of short descriptions : $item->getRefItems( 'text', 'short', 'default' )
- list of images : $item->getRefItems( 'media', 'default', 'default' )
- list of attributes : $item->getRefItems( 'attribute', null, 'default' )

The interface of the product controller is a bit complicated. In the next versions, it will be radically simplified and till the end of the year, Blade templates for the frontend should be available.
#7474 by Trent
07 Jan 2019, 14:30
Thanks so much for the links and explanations Aimeos!

I'm just working on getting them to display but seem to be getting this error. I've tried changing the facade and such to extend to it but doesn't seem to work. Would you know whats wrong?
Attachments
Screenshot from 2019-01-07 14-29-36.png
Screenshot from 2019-01-07 14-29-36.png (85.31 KiB) Viewed 330 times
#7476 by Trent
09 Jan 2019, 09:23
Sorry for the double post. I've tried using the parameters you gave to return values and the getName() works but the other ones to find details is giving me an error.

Is there a page with the getRefItems() uses? Like what parameters retrieves what?
Attachments
Screenshot from 2019-01-09 09-18-39.png
Screenshot from 2019-01-09 09-18-39.png (39.93 KiB) Viewed 318 times
Screenshot from 2019-01-09 09-17-31.png
Screenshot from 2019-01-09 09-17-31.png (9.4 KiB) Viewed 318 times
#7487 by Trent
10 Jan 2019, 19:36
Thanks man. I’m doing it all in the controller now to retrieve everything then pass it through.

Any chance you could help me out with the retrieving of getRefItems() function?
#7492 by aimeos
11 Jan 2019, 10:49
The getRefItems() method returns the items of the associated domains, e.g. this retrieves all product texts:
Code: Select all$textItems = $product->getRefItems( 'text' );


You can also get specific texts by adding a second and third parameter, e.g. the product name:
Code: Select all$textItems = $product->getRefItems( 'text', 'name', 'default' );


The second parameter is the text type (name, short, long, etc.), the third parameter is the product list type (usually only "default"). This works not only with texts but with all domains you are requesting in searchItems():
Code: Select all$products = $cntl->searchItems( $filter, ['text', 'media', 'price', 'attribute', 'product'] );
#7573 by Trent
28 Jan 2019, 20:23
Two questions:

1) Do I need to extend something to use getRefItems() as searchItems() works but the other doesn't
2) How do I get it to display on the actual page?

I'm using:

@foreach($items as $item)
{{$item->getName()}}
{{$item->text}}
{{$item->price}}
@endforeach

on the display page and bar the getName() I can't seem to display the other fields.

I'm passing:

$params = app('\Aimeos\Shop\Base\Page')->getSections('displayItem');

$context = app( '\Aimeos\Shop\Base\Context' )->get();
$cntl = \Aimeos\Controller\Frontend\Factory::createController( $context, 'product' );
$filter = $cntl->createFilter();
$filter->setConditions( $filter->compare( '==', 'product.code', 'Splendor' ) );
$items = $cntl->searchItems( $filter, ['text', 'media', 'attribute', 'price'] );

return view('item')->with('items', $items);

in the controller