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 (
    337, 335, 334, 329, 330, 331, 325, 319, 
    320, 321, 322, 323, 318, 317, 306, 307, 
    308, 309, 310, 311, 312, 313, 314, 315, 
    316, 303, 304, 305, 302, 301, 300, 298, 
    293, 292, 291, 290, 287, 278, 280, 282, 
    247, 248, 241, 244, 245, 246, 240, 6, 
    66, 166, 214, 219, 221, 223, 192, 194, 
    195, 196, 197, 198, 199, 200, 201, 202, 
    203, 204, 205, 206, 207, 208, 209, 210, 
    211, 212, 213, 215, 217, 218, 220, 222, 
    224, 225, 226, 227, 228, 229, 230, 231, 
    232, 233, 234, 235, 236, 237, 238, 239
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00137

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "37.29"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "3.72"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 86,
            "rows_produced_per_join": 3,
            "filtered": "4.00",
            "cost_info": {
              "read_cost": "19.95",
              "eval_cost": "0.69",
              "prefix_cost": "20.64",
              "data_read_per_join": "8K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`atulecarter_atul_demo1`.`cscart_categories`.`storefront_id` in (0,1)) and ((`atulecarter_atul_demo1`.`cscart_categories`.`usergroup_ids` = '') or find_in_set(0,`atulecarter_atul_demo1`.`cscart_categories`.`usergroup_ids`) or find_in_set(1,`atulecarter_atul_demo1`.`cscart_categories`.`usergroup_ids`)) and (`atulecarter_atul_demo1`.`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": [
              "atulecarter_atul_demo1.cscart_categories.category_id"
            ],
            "rows_examined_per_scan": 3,
            "rows_produced_per_join": 3,
            "filtered": "36.08",
            "index_condition": "(`atulecarter_atul_demo1`.`cscart_products_categories`.`product_id` in (337,335,334,329,330,331,325,319,320,321,322,323,318,317,306,307,308,309,310,311,312,313,314,315,316,303,304,305,302,301,300,298,293,292,291,290,287,278,280,282,247,248,241,244,245,246,240,6,66,166,214,219,221,223,192,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,215,217,218,220,222,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239))",
            "cost_info": {
              "read_cost": "10.87",
              "eval_cost": "0.74",
              "prefix_cost": "33.57",
              "data_read_per_join": "59"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
6 191M
66 189M
166 198M,199
192 232M
194 232M
195 232M
196 232M
197 229M,231
198 229M
199 229M
200 230M
201 230M
202 230M
203 230M
204 232M
205 171M
206 171M
207 171M
208 171M
209 172M
210 172M
211 172M
212 172M
213 201M
214 168M
215 201M
217 168M
218 168M
219 169M
220 169M
221 169M
222 169M
223 165M
224 165M
225 165M
226 201M
227 170M
228 170M
229 170M
230 216M
231 216M
232 216M
233 217M
234 217M
235 217M
236 218M
237 218M
238 235M
239 235M
240 165M
241 165M
244 168M
245 235M
246 199M
247 165M
248 248M,255
278 224M
280 224M
282 224M
287 224M
290 265M
291 265M
292 265M
293 265M
298 265M
300 265M
301 265M
302 265M
303 265M
304 265M
305 265M
306 265M
307 265M
308 265M
309 265M
310 265M
311 265M
312 265M
313 265M
314 265M
315 265M
316 265M
317 265M
318 265M
319 265M
320 265M
321 265M
322 265M
323 265M
325 224M
329 265M
330 265M
331 265M
334 265M
335 265M
337 265M