WITH RECURSIVE catalogs_tree AS
(
    SELECT
        catalog_id,
        1 AS hierarchy_level
    FROM
        catalog
    WHERE
        catalog_id = '".$catalog_id."'
        AND mailbox_id = '".$session['mailbox_id']."'
    UNION ALL
    SELECT
        cat.catalog_id,
        ct.hierarchy_level + 1
    FROM
        catalog cat,
        catalogs_tree ct
    WHERE
        cat.parent_catalog_id = ct.catalog_id
)
SELECT
    products.*
FROM
    catalogs_tree
    INNER JOIN products on catalogs_tree.catalog_id = products.catalog_id;