Adding a column from products table to searchable index so that all products with specific column value can be searched

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!
rahulhhh
Posts: 10
Joined: 11 Jan 2022, 04:54

Adding a column from products table to searchable index so that all products with specific column value can be searched

Post by rahulhhh » 13 May 2022, 06:31

I have added new addition column as tags in the database. This tags are attached to every product so that i can select all products with particular tag assigned to it. Its similar like "New Product" tag or "Best Seller" tag. I am not able to understand how i can search all those products based on that tags column.

Like getting all products with Tag "Best Seller". I was trying to do the search based on column index but i am not able to understand how i can add that column in searchable index in aimeos.

Please guide me for the same.

Below is the database snap of products. Here i need to select products based on a particular theme for search page display
search column issue.png
search column issue.png (92.28 KiB) Viewed 171 times

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

Re: Adding a column from products table to searchable index so that all products with specific column value can be searc

Post by aimeos » 14 May 2022, 07:13

If you create a decorator for the product manager, you can also search for new properties:
https://aimeos.org/docs/latest/models/e ... /#easy-way

Code: Select all

$manager = \Aimeos\MShop::create( $context, 'product' );
$filter = $manager->filter()->add( 'tags', '==', 'Best Seller' );
$items = $manager->search( $filter );
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

rahulhhh
Posts: 10
Joined: 11 Jan 2022, 04:54

Re: Adding a column from products table to searchable index so that all products with specific column value can be searc

Post by rahulhhh » 16 May 2022, 03:05

Thank you for the details. I tried the method given by you but that is not returning all data required for database display in frontend. The manager which we use for other searches is as follows
frontend manager.png
frontend manager.png (36.17 KiB) Viewed 142 times
This returns perfect data for frontend but when i use the manager mentioned by you, it is not returning images. it returns data which can be displayed moreover for backend. below is the snap of how data is returned
search images not returned.png
search images not returned.png (63.17 KiB) Viewed 142 times
it returns proper with frontend manager
search page.jpg
search page.jpg (86.99 KiB) Viewed 142 times

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

Re: Adding a column from products table to searchable index so that all products with specific column value can be searc

Post by aimeos » 17 May 2022, 14:30

In that case, use the frontend product controller from your screenshot and add this for filtering by tags:

Code: Select all

->compare( '==', 'tags', 'Best seller' )
See: https://github.com/aimeos/ai-controller ... ce.php#L62
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

rahulhhh
Posts: 10
Joined: 11 Jan 2022, 04:54

Re: Adding a column from products table to searchable index so that all products with specific column value can be searc

Post by rahulhhh » 18 May 2022, 08:43

confition added.png
confition added.png (188.12 KiB) Viewed 103 times
->compare( '==', 'themes', $view->param( 'f_theme' ) )

I have added this condition as given by you, but if the search term themes is not added then it not returning anything. I need to make the search in way where if the filter is added then it should return filtered results as per condition or else it should return the results without this condition. Currently if condition is sent blank then it is comparing it as blank and not returning the result.

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

Re: Adding a column from products table to searchable index so that all products with specific column value can be searc

Post by aimeos » 19 May 2022, 06:38

Place your condition between the create() and search() methods in an if() condition:

Code: Select all

$cntl = \Aimeos\Controller\Frontend::create( $context, 'product' );

if( $theme = $view->param( 'f_theme' ) ) {
	$cnt->compare( '==', 'themes', $theme );
}

$products = $cntl->...()->search();
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply