Custom order in product manager

Questions around the TYPO3 integration and plugins
Forum rules
Always add your TYPO3, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
loeffe1
Posts: 52
Joined: 21 Feb 2020, 10:33

Custom order in product manager

Post by loeffe1 » 16 Jan 2024, 14:16

I am fetching products by a comma separated list of product codes. When passing this list to the product manager, the order is lost and instead the products are ordered by product id. How can I ensure the order of my list is respected?

This is the relevant code in my Decorator:

Code: Select all

$codesArray = explode(',', $codes);
        $manager = \Aimeos\MShop::create($context, 'product');
        $search = $manager->filter()->add( ['product.code' => $codesArray] )->slice( 0, count( $codesArray ) );
        $result = $manager->search( $search );

        $cntl = \Aimeos\Controller\Frontend::create($context, 'product');
        return $cntl
            ->uses($domains)
            ->product($result->keys()->toArray())
            ->search();

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

Re: Custom order in product manager

Post by aimeos » 18 Jan 2024, 15:13

You have to sort the result set using the PHP Map "uasort()" method before returning the result:
https://php-map.org/#uasort
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply