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

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 303,326,304M
597 303,326,304M
599 329,305,303M
600 329,305,303M
601 329,305M,303
602 329,305M,303
603 303,329,305M
604 305M,303,329
605 329,305,303M
606 329,305,303M
672 326,304M,303
673 326,304M,303
674 326,304M,303
675 303M,329,305
676 303M,329,305
677 303M,329,305
678 315,317,303M
679 315,317,303M
680 315,317,303M
880 317M,303,315
881 317M,303,315
882 318M,303,315
883 315,318M,303
890 316,321M,303
891 316,321M,303
892 303,304,322M
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 325M,303,304
903 325M,303,304
904 325M,303,304
905 325M,303,304
906 325M,303,304
907 325M,303,304
911 303,327M,305
912 327M,305,303
914 327M,305,303
915 327M,305,303
916 327M,305,303
917 327M,305,303
918 303,327M,305
919 327M,305,303
920 327M,305,303
921 327M,305,303
922 328M,305,303
923 328M,305,303
924 303,328M,305
925 305,303,328M
926 305,303,329M
927 329M,305,303
928 329M,305,303
929 329M,305,303
930 303,329M,305
931 303,329M,305
934 314,303,330M
935 314,303,330M
937 332M,314,303
938 332M,314,303
939 332M,314,303
940 314,303,332M