SELECT 
  cscart_products_categories.product_id, 
  GROUP_CONCAT(
    IF(
      cscart_products_categories.link_type = "M", 
      CONCAT(
        cscart_products_categories.category_id, 
        "M"
      ), 
      cscart_products_categories.category_id
    )
  ) AS category_ids 
FROM 
  cscart_products_categories 
  INNER JOIN cscart_categories ON cscart_categories.category_id = cscart_products_categories.category_id 
  AND cscart_categories.storefront_id IN (0, 1) 
  AND (
    cscart_categories.usergroup_ids = '' 
    OR FIND_IN_SET(
      0, cscart_categories.usergroup_ids
    ) 
    OR FIND_IN_SET(
      1, cscart_categories.usergroup_ids
    )
  ) 
  AND cscart_categories.status IN ('A', 'H') 
WHERE 
  cscart_products_categories.product_id IN (
    672, 673, 674, 675, 676, 677, 883, 882, 
    891, 890, 899, 898, 897, 896, 907, 906, 
    905, 904, 903, 902, 912, 911, 917, 916, 
    915, 914, 919, 918, 921, 920, 925, 924, 
    931, 930, 929, 928, 927, 926, 934, 935, 
    937, 938, 939, 940
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00107

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "110.32"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "6.23"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 125,
            "rows_produced_per_join": 5,
            "filtered": "4.00",
            "cost_info": {
              "read_cost": "29.49",
              "eval_cost": "1.00",
              "prefix_cost": "30.49",
              "data_read_per_join": "20K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`cscart`.`cscart_categories`.`storefront_id` in (0,1)) and ((`cscart`.`cscart_categories`.`usergroup_ids` = '') or find_in_set(0,`cscart`.`cscart_categories`.`usergroup_ids`) or find_in_set(1,`cscart`.`cscart_categories`.`usergroup_ids`)) and (`cscart`.`cscart_categories`.`status` in ('A','H')))"
          }
        },
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "cscart.cscart_categories.category_id"
            ],
            "rows_examined_per_scan": 12,
            "rows_produced_per_join": 6,
            "filtered": "10.39",
            "index_condition": "(`cscart`.`cscart_products_categories`.`product_id` in (672,673,674,675,676,677,883,882,891,890,899,898,897,896,907,906,905,904,903,902,912,911,917,916,915,914,919,918,921,920,925,924,931,930,929,928,927,926,934,935,937,938,939,940))",
            "cost_info": {
              "read_cost": "61.60",
              "eval_cost": "1.25",
              "prefix_cost": "104.09",
              "data_read_per_join": "99"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
672 304M,303,326
673 326,304M,303
674 326,304M,303
675 305,329,303M
676 305,329,303M
677 303M,305,329
882 315,303,318M
883 315,303,318M
890 321M,316,303
891 321M,316,303
896 322M,304,303
897 303,322M,304
898 303,322M,304
899 304,303,322M
902 325M,304,303
903 325M,304,303
904 325M,304,303
905 325M,304,303
906 303,325M,304
907 304,303,325M
911 303,327M,305
912 303,327M,305
914 303,327M,305
915 303,327M,305
916 303,327M,305
917 303,327M,305
918 303,327M,305
919 303,327M,305
920 303,327M,305
921 303,327M,305
924 305,303,328M
925 303,328M,305
926 303,305,329M
927 303,305,329M
928 329M,303,305
929 329M,303,305
930 329M,303,305
931 303,305,329M
934 314,303,330M
935 314,303,330M
937 332M,314,303
938 332M,314,303
939 332M,314,303
940 303,332M,314