sort products by id

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!
User avatar
ahmed31916
Advanced
Posts: 148
Joined: 14 Apr 2022, 12:15

sort products by id

Post by ahmed31916 » 11 Jul 2022, 09:46

Hello Aimeos,

Why the sort method doesn't work here?

Code: Select all

$manager = \Aimeos\Controller\Frontend::create( $context, 'product' )->uses( $domains );
$feature_cars = $manager->search()->slice(0,5)->sort('-', 'product.id');

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

Re: sort products by id

Post by aimeos » 12 Jul 2022, 06:12

The sort() method accepts only a single parameter, not two:

Code: Select all

$cntl = \Aimeos\Controller\Frontend::create( $context, 'product' )->uses( $domains );
$cntl->slice(0,5)->order('-product.id')->search();
See here: https://github.com/aimeos/ai-controller ... #L187-L194
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
ahmed31916
Advanced
Posts: 148
Joined: 14 Apr 2022, 12:15

Re: sort products by id

Post by ahmed31916 » 12 Jul 2022, 07:55

I got this error:

Code: Select all

Call to a member function getType() on null
https://flareapp.io/share/LPlLk8DP#F66

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

Re: sort products by id

Post by aimeos » 13 Jul 2022, 06:54

Please create a new topic for questions not related to the existing topic.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
ahmed31916
Advanced
Posts: 148
Joined: 14 Apr 2022, 12:15

Re: sort products by id

Post by ahmed31916 » 13 Jul 2022, 07:20

aimeos wrote: 13 Jul 2022, 06:54 Please create a new topic for questions not related to the existing topic.
it is related to the same topic, when I apply this code I got the previous error:
$cntl->slice(0,5)->sort('-product.id')->search();

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

Re: sort products by id

Post by aimeos » 13 Jul 2022, 07:56

But nevertheless, another problem in another file and not related to your initial question.

The problem is that you use:

Code: Select all

$prices->first()->getType()
This will error if there's not price available and to circumvent the error, you can use this instead:

Code: Select all

$prices->getType()->first()
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply