order Desc in products query
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!
order Desc in products query
Hello plz how can order the products in a descending order like order by product.id "DESC" in this query?
$products = $this->homeTree->getRefItems( 'product', null, 'promotion', )->slice(0,6);
and other question plz:
$this->homeTree is the manager?
thx
$products = $this->homeTree->getRefItems( 'product', null, 'promotion', )->slice(0,6);
and other question plz:
$this->homeTree is the manager?
thx
Re: order Desc in products query
You can't because the referenced products are always ordered by the position you can set in the category panel. If you add a decorator that uses the product controller directly, you can execute a query with a custom order. The disadvantage is that you will fetch the products again and most likely not in an optimized way so your home page will slow down.Oscar wrote: ↑25 Aug 2021, 18:24 Hello plz how can order the products in a descending order like order by product.id "DESC" in this query?Code: Select all
$products = $this->homeTree->getRefItems( 'product', null, 'promotion', )->slice(0,6);
No, it's the root tree node of the category tree.
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
Re: order Desc in products query
Could be a search with filter? And then aply to the filter a -product.id
Thx for help
Thx for help
Re: order Desc in products query
Yes, if you use the product controller, you can do that.
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
Re: order Desc in products query
Hello, I have tried to do a search ordering them descendingly and I have been able, but how could I filter only the promotional ones?
Thank you very much for the help. This is my code
Thank you very much for the help. This is my code
Code: Select all
$context = app()->make('\Aimeos\Shop\Base\Context')->get();
$manager = \Aimeos\MShop::create( $context, 'product' );
$filter = $manager->filter();
$filter = $manager->filter( true );
$filter->order( '-product.id' );
$items = $manager->search( $filter);
Re: order Desc in products query
You should use the product controller instead of the manager:
https://github.com/aimeos/ai-client-htm ... #L317-L321
Available methods are:
https://github.com/aimeos/ai-controller ... /Iface.php
https://github.com/aimeos/ai-client-htm ... #L317-L321
Code: Select all
$context = app()->make('aimeos.context')->get();
$items = \Aimeos\Controller\Frontend::create($context, 'product')
->category( $catId, 'promotion' )
->sort( '-product.id' )->slice( 0, 6 )
->uses( ['media', 'price', 'text'] )
->search();
https://github.com/aimeos/ai-controller ... /Iface.php
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
Re: order Desc in products query
Thanks a lot!! runs perfect