src/Backend/Modules/Commerce/Domain/Product/ProductRepository.php
/**
     * After searching the search_index, we need to decorate the search results and return the search objects.
     * We use a raw query for performance reasons.
     * @param int[] $ids
     * @return Product[]
     */
After searching the search_index, we need to decorate the search results and return the search objects.
We use a raw query for performance reasons.
@param int[] $ids
@return Product[]
After searching the search_index we need to decorate the search results and return the search objects . We use a raw query for performance reasons . @param int [] $ids @return Product []
public function search(array $ids): array
    {
        $em = FrontendModel::getContainer()->get('doctrine.orm.entity_manager');
        $items = $em->getConnection()->executeQuery(
            '
            SELECT
                p.id,
                p.title,
                p.categoryId AS category_id,
                p.text,
                p.priceAmount AS price_amount,
                m.url AS url,
                CONCAT(:detailUrl, "/", m2.url, "/", m.url) AS full_url,
                MIN(mgmi.mediaItemId) AS media_item_id
            FROM commerce_products AS p
            INNER JOIN meta AS m ON m.id = p.metaId
            LEFT JOIN commerce_categories AS cc ON cc.id = p.categoryId
            LEFT JOIN meta AS m2 ON m2.id = cc.metaId
            LEFT JOIN MediaGroupMediaItem AS mgmi ON mgmi.mediaGroupId = p.imageGroupId AND mgmi.sequence = 0
            WHERE
                p.hidden = 0
                AND p.id IN (:ids)
            GROUP BY 1',
            ['detailUrl' => FrontendNavigation::getUrlForBlock('Commerce'), 'ids' => $ids],
            ['detailUrl' => PDO::PARAM_STR, 'ids' => Connection::PARAM_INT_ARRAY]
        )->fetchAllAssociativeIndexed();
        foreach ($items as &$item) {
            if (!empty($item['media_item_id'])) {
                $item['preview_image_url'] = FrontendModel::get('media_library.repository.item')
                    ->findOneById($item['media_item_id'])
                    ->getThumbnail('product_slider_thumbnail');
            }
        }
        return $items;
    }
public function search ( array $ ids ) : array { $ em = FrontendModel :: getContainer ( ) -> get ( 'doctrine.orm.entity_manager' ) ; $ items = $ em -> getConnection ( ) -> executeQuery ( '
            SELECT
                p.id,
                p.title,
                p.categoryId AS category_id,
                p.text,
                p.priceAmount AS price_amount,
                m.url AS url,
                CONCAT(:detailUrl, "/", m2.url, "/", m.url) AS full_url,
                MIN(mgmi.mediaItemId) AS media_item_id
            FROM commerce_products AS p
            INNER JOIN meta AS m ON m.id = p.metaId
            LEFT JOIN commerce_categories AS cc ON cc.id = p.categoryId
            LEFT JOIN meta AS m2 ON m2.id = cc.metaId
            LEFT JOIN MediaGroupMediaItem AS mgmi ON mgmi.mediaGroupId = p.imageGroupId AND mgmi.sequence = 0
            WHERE
                p.hidden = 0
                AND p.id IN (:ids)
            GROUP BY 1' , [ 'detailUrl' => FrontendNavigation :: getUrlForBlock ( 'Commerce' ) , 'ids' => $ ids ] , [ 'detailUrl' => PDO :: PARAM_STR , 'ids' => Connection :: PARAM_INT_ARRAY ] ) -> fetchAllAssociativeIndexed ( ) ; foreach ( $ items as & $ item ) { if ( ! empty ( $ item [ 'media_item_id' ] ) ) { $ item [ 'preview_image_url' ] = FrontendModel :: get ( 'media_library.repository.item' ) -> findOneById ( $ item [ 'media_item_id' ] ) -> getThumbnail ( 'product_slider_thumbnail' ) ; } } return $ items ; }
After searching the search_index, we need to decorate the search results and return the search objects.
After searching the search_index we need to decorate the search results and return the search objects .
/** @var EntityManager $em */ // Fetch image preview thumb //        // Fetch categories //        $categories = $this->getEntityManager() //            ->getRepository('commerce.repository.category') //            ->findBy(['id' => array_map(fn ($item) => $item['category_id'], $items)]); // Note: array must have the ID as key, else search breaks!