Add global scope on retrieving products
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
- GagDalakyan
- Posts: 17
- Joined: 03 Dec 2020, 13:13
Add global scope on retrieving products
Laravel : 8.4
Aimeos : 2021.04
PHP Version : 7.4
Environment : Windows
Good day. I need to add global scope for products in frontend ( Product lists, detail page, bought together products, etc. ) , for example
Can anyone help ?
I see there is a similar global scope on product status in frontend manager ( product.status = 1 ).
I need to add something similar to this to add my scope.
Thanks a lot!
Aimeos : 2021.04
PHP Version : 7.4
Environment : Windows
Good day. I need to add global scope for products in frontend ( Product lists, detail page, bought together products, etc. ) , for example
Code: Select all
$productManager->compare( '==', 'product.config', 'visibility":"1' );
I see there is a similar global scope on product status in frontend manager ( product.status = 1 ).
I need to add something similar to this to add my scope.
Thanks a lot!
Re: Add global scope on retrieving products
The easiest solution is to add a mshop_product.visibility column and extend the product manager with a decorator to make the column known to Aimeos:
https://aimeos.org/docs/latest/models/extend-managers/
https://aimeos.org/docs/latest/models/extend-managers/
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
- GagDalakyan
- Posts: 17
- Joined: 03 Dec 2020, 13:13
Re: Add global scope on retrieving products
Thanks for reply!
Im sorry.I asked wrong question.
I need to show in frontend for example only products where ( '>', 'product.rating', '2' );
Rating column is already in mshop_product table. How i can add this rule in all queries?
Im sorry.I asked wrong question.
I need to show in frontend for example only products where ( '>', 'product.rating', '2' );
Rating column is already in mshop_product table. How i can add this rule in all queries?
Re: Add global scope on retrieving products
Code: Select all
filter[>][product.rating]=2
// escaped
filter[%3E][product.rating]=2
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
- GagDalakyan
- Posts: 17
- Joined: 03 Dec 2020, 13:13
Re: Add global scope on retrieving products
And where add this filter ?
Re: Add global scope on retrieving products
Sorry, that was for the JSON API. When using the product manager directly, you should use:
Code: Select all
$filter = $manager->filter( true )->add( 'product.rating', '>', 2 );
$items = $manager->search( $filter );
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
- GagDalakyan
- Posts: 17
- Joined: 03 Dec 2020, 13:13
Re: Add global scope on retrieving products
Thanks for your reply.
I understand. But i want to know is there a way, to add it global to product manager class( as product status is always set to 1 ), not every time add this filter while using product manager.
I understand. But i want to know is there a way, to add it global to product manager class( as product status is always set to 1 ), not every time add this filter while using product manager.
Re: Add global scope on retrieving products
Create a new product manager that extends from the original one, overwrite the filter() method and add your condition there:
https://github.com/aimeos/aimeos-core/b ... #L280-L328
https://github.com/aimeos/aimeos-core/b ... #L280-L328
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
- GagDalakyan
- Posts: 17
- Joined: 03 Dec 2020, 13:13
Re: Add global scope on retrieving products
Many thanks.
And my last question. ))
This works fine, but does not affect to similar products and products bought together in product detail. Any suggestions ?
And my last question. ))
This works fine, but does not affect to similar products and products bought together in product detail. Any suggestions ?
Re: Add global scope on retrieving products
You have to overwrite the isAvailable() method of the product item too:
https://github.com/aimeos/aimeos-core/b ... #L444-L449
See also:
https://aimeos.org/docs/latest/models/e ... custom-way
https://github.com/aimeos/aimeos-core/b ... #L444-L449
See also:
https://aimeos.org/docs/latest/models/e ... custom-way
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star