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, 1094, 1149, 1150, 1151
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00143

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "116.62"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "8.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": 8,
            "filtered": "14.76",
            "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,1094,1149,1150,1151))",
            "cost_info": {
              "read_cost": "64.86",
              "eval_cost": "1.79",
              "prefix_cost": "107.69",
              "data_read_per_join": "142"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        }
      ]
    }
  }
}

Result

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