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 (
    704, 703, 663, 710, 709, 708, 707, 706, 
    719, 718, 717, 716, 715, 714, 713, 711, 
    666, 724, 723, 722, 721, 720, 726, 725, 
    727, 945, 946, 953, 954, 955, 956, 957, 
    958
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00088

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "109.65"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "3.93"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 126,
            "rows_produced_per_join": 5,
            "filtered": "4.00",
            "cost_info": {
              "read_cost": "29.72",
              "eval_cost": "1.01",
              "prefix_cost": "30.73",
              "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": 3,
            "filtered": "6.49",
            "index_condition": "(`cscart`.`cscart_products_categories`.`product_id` in (704,703,663,710,709,708,707,706,719,718,717,716,715,714,713,711,666,724,723,722,721,720,726,725,727,945,946,953,954,955,956,957,958))",
            "cost_info": {
              "read_cost": "62.90",
              "eval_cost": "0.79",
              "prefix_cost": "105.72",
              "data_read_per_join": "62"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
663 313M,415
666 312,313M,415
703 313M,415
704 313M,415
706 415,313M
707 415,313M
708 313M,415
709 313M,415
710 313M,415
711 312,313M,415
713 312,313M,415
714 415,312,313M
715 415,312,313M
716 313M,415,312
717 312,313M,415
718 312,313M,415
719 312,313M,415
720 415M
721 415M
722 415M
723 415M
724 415M
725 312,313,402M
726 402M,312,313
727 313,402M,312
945 333,334,336M
946 336M,333,334
953 334,339M,333
954 334,339M,333
955 334,339M,333
956 340M,334,333
957 333,340M,334
958 333,340M,334