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 (
    6780, 6689, 6769, 6686, 6688, 6785, 6690, 
    6670, 6799, 6687, 6773, 6795, 6777, 
    6784, 6691, 6807, 6770, 6781, 6783, 
    6776, 6797, 6774, 6790, 7315, 6746, 
    6808, 6731, 6792, 6732, 6744, 6756, 
    6782, 6673, 6714, 6789, 6796, 6694, 
    6778, 6793, 6674, 6718, 6816, 6775, 
    6809, 6715, 6758, 6766, 6768, 6717, 
    6771, 6813, 6716, 6772, 6669, 6671, 
    6812, 6761, 6672, 6760, 6767, 6815, 
    6759, 6668, 6762, 6765, 6810, 6757, 
    6764, 6811, 6763, 6814
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00266

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "107.36"
    },
    "grouping_operation": {
      "using_filesort": false,
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "pt",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "rows_examined_per_scan": 112,
            "rows_produced_per_join": 112,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (6780,6689,6769,6686,6688,6785,6690,6670,6799,6687,6773,6795,6777,6784,6691,6807,6770,6781,6783,6776,6797,6774,6790,7315,6746,6808,6731,6792,6732,6744,6756,6782,6673,6714,6789,6796,6694,6778,6793,6674,6718,6816,6775,6809,6715,6758,6766,6768,6717,6771,6813,6716,6772,6669,6671,6812,6761,6672,6760,6767,6815,6759,6668,6762,6765,6810,6757,6764,6811,6763,6814))",
            "cost_info": {
              "read_cost": "56.96",
              "eval_cost": "11.20",
              "prefix_cost": "68.16",
              "data_read_per_join": "1K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        },
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "softwarepirmam_hewadelivard_cscart_4.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 5,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "28.00",
              "eval_cost": "0.56",
              "prefix_cost": "107.36",
              "data_read_per_join": "17K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`storefront_id` in (0,1)) and ((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`))) and (`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`status` in ('A','H')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
6668 466,574M
6669 466,574M
6670 466,574M
6671 466,574M
6672 466,575M
6673 466,575M
6674 466,575M
6686 466,467M
6687 467M
6688 466,467M
6689 466,467M
6690 466,467M
6691 466,574M
6694 466,574M
6714 466,574M
6715 466,574M
6716 466,574M
6717 466,574M
6718 466,574M
6731 466,579M
6732 466,579M
6744 466,579M
6746 466,579M
6756 466,579M
6757 466,573M
6758 466,579M
6759 466M
6760 466M
6761 466M
6762 466M
6763 466,573M
6764 466,573M
6765 466,573M
6766 372,384M
6767 372,384M
6768 372,384M
6769 372,460M
6770 372,598M
6771 372,384M
6772 372,384M
6773 554,556M
6774 466,573M
6775 372,573M
6776 372,573M
6777 372,574M
6778 372,574M
6780 372,460M
6781 372,587M
6782 372,587M
6783 372,587M
6784 372,587M
6785 372,587M
6789 466,574M
6790 466,574M
6792 466,574M
6793 466,574M
6795 466,574M
6796 466,574M
6797 466,574M
6799 372,587M
6807 372,587M
6808 466,574M
6809 466,574M
6810 466,574M
6811 466,574M
6812 466,574M
6813 466,574M
6814 466,574M
6815 466,574M
6816 466,574M
7315 466,575M