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 (
    599, 600, 601, 602, 603, 604, 605, 606, 
    675, 676, 677, 911, 912, 914, 915, 916, 
    917, 918, 919, 920, 921, 922, 923, 924, 
    925, 926, 927, 928, 929, 930, 931, 596, 
    597, 672, 673, 674, 678, 679, 680, 880, 
    881, 882, 883, 890, 891, 892, 893, 896, 
    897, 898, 899, 900, 901, 902, 903, 904, 
    905, 906, 907, 934, 935, 937, 938, 939, 
    940
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00177

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "113.15"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "9.06"
      },
      "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": 9,
            "filtered": "15.10",
            "index_condition": "(`cscart`.`cscart_products_categories`.`product_id` in (599,600,601,602,603,604,605,606,675,676,677,911,912,914,915,916,917,918,919,920,921,922,923,924,925,926,927,928,929,930,931,596,597,672,673,674,678,679,680,880,881,882,883,890,891,892,893,896,897,898,899,900,901,902,903,904,905,906,907,934,935,937,938,939,940))",
            "cost_info": {
              "read_cost": "61.60",
              "eval_cost": "1.81",
              "prefix_cost": "104.09",
              "data_read_per_join": "144"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
596 304M,303,326
597 303,326,304M
599 305,303M,329
600 329,305,303M
601 329,305M,303
602 329,305M,303
603 329,305M,303
604 329,305M,303
605 303M,329,305
606 305,303M,329
672 326,304M,303
673 326,304M,303
674 326,304M,303
675 329,305,303M
676 303M,329,305
677 303M,329,305
678 317,303M,315
679 315,317,303M
680 315,317,303M
880 315,317M,303
881 315,317M,303
882 318M,303,315
883 318M,303,315
890 316,321M,303
891 316,321M,303
892 322M,303,304
893 322M,303,304
896 322M,303,304
897 322M,303,304
898 322M,303,304
899 322M,303,304
900 322,303,304M
901 322,303,304M
902 303,304,325M
903 325M,303,304
904 325M,303,304
905 325M,303,304
906 325M,303,304
907 325M,303,304
911 327M,305,303
912 303,327M,305
914 327M,305,303
915 327M,305,303
916 327M,305,303
917 327M,305,303
918 327M,305,303
919 303,327M,305
920 303,327M,305
921 327M,305,303
922 328M,305,303
923 328M,305,303
924 328M,305,303
925 328M,305,303
926 303,329M,305
927 305,303,329M
928 305,303,329M
929 329M,305,303
930 329M,305,303
931 329M,305,303
934 303,330M,314
935 314,303,330M
937 314,303,332M
938 332M,314,303
939 332M,314,303
940 332M,314,303