public function crossSelling($product_id, $limit = 5, $available_only = false, $key = false) { if (!is_numeric($limit)) { $key = $available_only; $available_only = $limit; $limit = 5; } if (is_string($available_only)) { $key = $available_only; $available_only = false; } if (!$product_id) { return array(); } if (is_array($product_id)) { if ($key) { foreach ($product_id as &$r) { $r = $r[$key]; } unset($r); } $product_model = new shopProductModel(); $sql = "SELECT p.* FROM shop_product p JOIN shop_type t ON p.type_id = t.id\n WHERE (p.id IN (i:id)) AND (t.cross_selling != '' OR p.cross_selling = 2)\n ORDER BY RAND() LIMIT 1"; $p = $product_model->query($sql, array('id' => $product_id))->fetchAssoc(); $p = new shopProduct($p); $result = $p->crossSelling($limit, $available_only); foreach ($result as $p_id => $pr) { if (in_array($p_id, $product_id)) { unset($result[$p_id]); } } return $result; } else { $p = new shopProduct($product_id); return $p->crossSelling($limit, $available_only); } }