get_setting('OrderComponentID'); $limit = 10; $sql = "SELECT `Item_ID`, `Item_Type`, COUNT(`Netshop_OrderGoods_ID`) AS `Count` FROM `Netshop_OrderGoods` AS `a` JOIN `Message{$order_table}` AS `b` ON (`a`.`Order_Component_ID`={$order_table} AND `a`.`Order_ID`=`b`.`Message_ID`) WHERE `Order_ID` IN ( SELECT `Order_ID` FROM `Netshop_OrderGoods` WHERE `Item_Type` = $component_id AND `Item_ID` IN ($item_ids) ) AND NOT (`Item_Type` = $component_id AND `Item_ID` IN ($item_ids)) GROUP BY Item_Type, Item_ID ORDER BY `Count` DESC LIMIT $limit"; $rows = (array)nc_db()->get_results($sql, ARRAY_A); $goods = new nc_netshop_item_collection(); $goods->set_index_property('_ItemKey'); // обеспечит уникальность товаров в коллекции foreach ($rows as $row) { try { $item = nc_netshop_item::by_id($row['Item_Type'], $row['Item_ID']); if (!$item['Sub_Class_ID']) { throw new Exception(''); } // seems that the item data is missing if ($item->has_parent()) { $item = $item['_Parent']; } $goods->add($item); } catch (Exception $e) {} } if (count($goods)) { echo '
'; }