SELECT 
  SQL_CALC_FOUND_ROWS products.product_id, 
  IF(
    shared_descr.product_id IS NOT NULL, 
    shared_descr.product, descr1.product
  ) as product, 
  companies.company as company_name, 
  products.product_type, 
  products.parent_product_id, 
  1 as instock_marker, 
  IF(
    products.product_type = 'C', 
    (
      SELECT 
        MAX(amount) 
      FROM 
        cscart_products 
      WHERE 
        parent_product_id = products.product_id
    ) > 0, 
    IF(
      products.amount > 0, 
      1, 
      IF(products.tracking = 'O', 1, 0)
    )
  ) as instock_sorting 
FROM 
  cscart_products as products 
  LEFT JOIN cscart_product_descriptions as descr1 ON descr1.product_id = products.product_id 
  AND descr1.lang_code = 'en' 
  LEFT JOIN cscart_product_prices as prices ON prices.product_id = products.product_id 
  AND prices.lower_limit = 1 
  LEFT JOIN cscart_companies AS companies ON companies.company_id = products.company_id 
  INNER JOIN cscart_products_categories as products_categories ON products_categories.product_id = products.product_id 
  INNER JOIN cscart_categories ON cscart_categories.category_id = products_categories.category_id 
  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') 
  AND cscart_categories.storefront_id IN (0, 1) 
  LEFT JOIN cscart_ult_product_descriptions shared_descr ON shared_descr.product_id = products.product_id 
  AND shared_descr.company_id = 1 
  AND shared_descr.lang_code = 'en' 
  LEFT JOIN cscart_images_links as img_links ON img_links.object_id = products.product_id 
  AND img_links.object_type = 'product' 
  AND img_links.type = 'M' 
WHERE 
  1 
  AND cscart_categories.category_id IN (
    387, 745, 741, 1112, 693, 679, 681, 659, 
    657, 1022, 1108, 582, 1073, 713, 574, 
    522, 470, 479, 481, 651, 515, 754, 760, 
    1097, 744, 1105, 1106, 726, 1110, 755, 
    743, 450, 1104, 429, 430, 434, 435, 448, 
    415, 1098, 594, 1066, 1107, 468, 489, 
    493, 497, 498, 499, 500, 758, 414, 388, 
    765, 768, 774, 777, 782, 784, 786, 1087, 
    792, 794, 1131, 819, 828, 1094, 833, 
    837, 844, 1134, 1109, 1099, 1100, 1101, 
    1102, 1103, 884, 885, 1088, 939, 941, 
    942, 950, 952, 961, 1186, 1021, 1016, 
    1017, 1028, 1032, 1135, 1188, 1168, 
    1185, 1156, 1157, 1162, 1166, 1169, 
    1171, 1179, 1181, 1182, 1183, 1184, 
    1192
  ) 
  AND companies.status IN ('A') 
  AND (
    products.usergroup_ids = '' 
    OR FIND_IN_SET(0, products.usergroup_ids) 
    OR FIND_IN_SET(1, products.usergroup_ids)
  ) 
  AND products.status IN ('A') 
  AND prices.usergroup_id IN (0, 0, 1) 
  AND img_links.pair_id > 0 
  AND products.parent_product_id = 0 
GROUP BY 
  products.product_id 
ORDER BY 
  instock_sorting DESC, 
  product asc, 
  products.product_id ASC 
LIMIT 
  2016, 24

Query time 0.11703

JSON explain

{
  "query_block": {
    "select_id": 1,
    "filesort": {
      "sort_key": "if(products.product_type = 'C',(subquery#2) > 0,if(products.amount > 0,1,if(products.tracking = 'O',1,0))) desc, if(shared_descr.product_id is not null,shared_descr.product,descr1.product), products.product_id",
      "temporary_table": {
        "nested_loop": [
          {
            "table": {
              "table_name": "companies",
              "access_type": "system",
              "possible_keys": ["PRIMARY"],
              "rows": 1,
              "filtered": 100
            }
          },
          {
            "table": {
              "table_name": "cscart_categories",
              "access_type": "ALL",
              "possible_keys": ["PRIMARY", "c_status", "p_category_id"],
              "rows": 525,
              "filtered": 20.5714283,
              "attached_condition": "cscart_categories.category_id in (387,745,741,1112,693,679,681,659,657,1022,1108,582,1073,713,574,522,470,479,481,651,515,754,760,1097,744,1105,1106,726,1110,755,743,450,1104,429,430,434,435,448,415,1098,594,1066,1107,468,489,493,497,498,499,500,758,414,388,765,768,774,777,782,784,786,1087,792,794,1131,819,828,1094,833,837,844,1134,1109,1099,1100,1101,1102,1103,884,885,1088,939,941,942,950,952,961,1186,1021,1016,1017,1028,1032,1135,1188,1168,1185,1156,1157,1162,1166,1169,1171,1179,1181,1182,1183,1184,1192) 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') and cscart_categories.storefront_id in (0,1)"
            }
          },
          {
            "table": {
              "table_name": "products_categories",
              "access_type": "ref",
              "possible_keys": ["PRIMARY", "pt"],
              "key": "PRIMARY",
              "key_length": "3",
              "used_key_parts": ["category_id"],
              "ref": ["lillyshop_lillyshop.cscart_categories.category_id"],
              "rows": 26,
              "filtered": 100,
              "using_index": true
            }
          },
          {
            "table": {
              "table_name": "products",
              "access_type": "eq_ref",
              "possible_keys": ["PRIMARY", "status", "idx_parent_product_id"],
              "key": "PRIMARY",
              "key_length": "3",
              "used_key_parts": ["product_id"],
              "ref": ["lillyshop_lillyshop.products_categories.product_id"],
              "rows": 1,
              "filtered": 90.49367523,
              "attached_condition": "products.parent_product_id = 0 and products.company_id = 1 and (products.usergroup_ids = '' or find_in_set(0,products.usergroup_ids) or find_in_set(1,products.usergroup_ids)) and products.`status` = 'A'"
            }
          },
          {
            "table": {
              "table_name": "shared_descr",
              "access_type": "eq_ref",
              "possible_keys": ["PRIMARY", "product_id", "company_id"],
              "key": "PRIMARY",
              "key_length": "13",
              "used_key_parts": ["product_id", "lang_code", "company_id"],
              "ref": [
                "lillyshop_lillyshop.products_categories.product_id",
                "const",
                "const"
              ],
              "rows": 1,
              "filtered": 100,
              "attached_condition": "trigcond(shared_descr.lang_code = 'en')"
            }
          },
          {
            "table": {
              "table_name": "descr1",
              "access_type": "eq_ref",
              "possible_keys": ["PRIMARY", "product_id"],
              "key": "PRIMARY",
              "key_length": "9",
              "used_key_parts": ["product_id", "lang_code"],
              "ref": [
                "lillyshop_lillyshop.products_categories.product_id",
                "const"
              ],
              "rows": 1,
              "filtered": 100,
              "attached_condition": "trigcond(descr1.lang_code = 'en')"
            }
          },
          {
            "table": {
              "table_name": "prices",
              "access_type": "ref",
              "possible_keys": [
                "usergroup",
                "product_id",
                "lower_limit",
                "usergroup_id"
              ],
              "key": "usergroup",
              "key_length": "3",
              "used_key_parts": ["product_id"],
              "ref": ["lillyshop_lillyshop.products_categories.product_id"],
              "rows": 1,
              "filtered": 99.99145508,
              "attached_condition": "prices.lower_limit = 1 and prices.usergroup_id in (0,0,1)",
              "using_index": true
            }
          },
          {
            "table": {
              "table_name": "img_links",
              "access_type": "ref",
              "possible_keys": ["PRIMARY", "object_id"],
              "key": "object_id",
              "key_length": "81",
              "used_key_parts": ["object_id", "object_type", "type"],
              "ref": [
                "lillyshop_lillyshop.products_categories.product_id",
                "const",
                "const"
              ],
              "rows": 1,
              "filtered": 100,
              "index_condition": "img_links.object_id = products_categories.product_id and img_links.object_type = 'product' and img_links.`type` = 'M'",
              "attached_condition": "img_links.pair_id > 0"
            }
          }
        ],
        "subqueries": [
          {
            "expression_cache": {
              "state": "uninitialized",
              "query_block": {
                "select_id": 2,
                "nested_loop": [
                  {
                    "table": {
                      "table_name": "cscart_products",
                      "access_type": "ALL",
                      "possible_keys": ["idx_parent_product_id"],
                      "rows": 11707,
                      "filtered": 100,
                      "attached_condition": "cscart_products.parent_product_id = products.product_id"
                    }
                  }
                ]
              }
            }
          }
        ]
      }
    }
  }
}

Result

product_id product company_name product_type parent_product_id instock_marker instock_sorting
23795 Single-phase gel polish GaMa Mono Lac No. 006, soft peach, 6 ml LILLYSHOP P 0 1 1
23797 Single-phase gel polish GaMa Mono Lac No. 008, pink, 6 ml LILLYSHOP P 0 1 1
23798 Single-phase gel polish GaMa Mono Lac No. 009, purple, 6 ml LILLYSHOP P 0 1 1
23799 Single-phase gel polish GaMa Mono Lac No. 010, plum, 6 ml LILLYSHOP P 0 1 1
23801 Single-phase gel polish GaMa Mono Lac No. 012, milky with micro-glitter, 6 ml LILLYSHOP P 0 1 1
23805 Single-phase gel polish GaMa Mono Lac No. 013, pink with micro glitter, 6 ml LILLYSHOP P 0 1 1
23802 Single-phase gel polish GaMa Mono Lac No. 014, peach with micro glitter, 6 ml LILLYSHOP P 0 1 1
23809 Single-phase gel polish GaMa Mono Lac No. 015, cappuccino with sparkles, 6 ml LILLYSHOP P 0 1 1
23803 Single-phase gel polish GaMa Mono Lac No. 016, cherry with micro glitter, 6 ml LILLYSHOP P 0 1 1
23804 Single-phase gel polish GaMa Mono Lac No. 017, graphite with microglitter, 6 ml LILLYSHOP P 0 1 1
23810 Single-phase gel polish GaMa Mono Lac No. 018, Marsala with sparkles, 6 ml LILLYSHOP P 0 1 1
23811 Single-phase gel polish GaMa Mono Lac No. 019, purple with sparkles, 6 ml LILLYSHOP P 0 1 1
23806 Single-phase gel polish GaMa Mono Lac No. 020, red with micro glitter, 6 ml LILLYSHOP P 0 1 1
24409 Single-phase gel polish GaMa Mono Lac No. 022, white, 6 ml LILLYSHOP P 0 1 1
24426 Single-phase gel polish GaMa Mono Lac No. 027, 6 ml LILLYSHOP P 0 1 1
24428 Single-phase gel polish GaMa Mono Lac No. 029, 6 ml LILLYSHOP P 0 1 1
24432 Single-phase gel polish GaMa Mono Lac No. 033, 6 ml LILLYSHOP P 0 1 1
24435 Single-phase gel polish GaMa Mono Lac No. 37, 6 ml LILLYSHOP P 0 1 1
23242 Stained gel varnish DARK Vitrage No. 010, eggplant, 6 ml LILLYSHOP P 0 1 1
23243 Stained gel varnish DARK Vitrage No. 011, black, 6 ml LILLYSHOP P 0 1 1
23244 Stained gel varnish DARK Vitrage No. 012, chocolate, 6 ml LILLYSHOP P 0 1 1
9597 Stained glass gel varnish Oxxi Crystal Glass No. 058, 10 ml LILLYSHOP P 0 1 1
23240 Stained-glass gel polish DARK Vitrage No. 008, dark purple, 6 ml LILLYSHOP P 0 1 1
10167 Top for gel polish DIS Gel Polish Top with LSH 15 g LILLYSHOP P 0 1 1