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.00099

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 415,313M
706 415,313M
707 313M,415
708 313M,415
709 313M,415
710 313M,415
711 415,312,313M
713 415,312,313M
714 415,312,313M
715 312,313M,415
716 312,313M,415
717 312,313M,415
718 312,313M,415
719 415,312,313M
720 415M
721 415M
722 415M
723 415M
724 415M
725 402M,312,313
726 313,402M,312
727 312,313,402M
945 336M,333,334
946 334,336M,333
953 334,339M,333
954 334,339M,333
955 333,334,339M
956 333,340M,334
957 333,340M,334
958 333,340M,334