db = new Database(); } function exists($priceset_id, $product_id) { $query = "SELECT * FROM ".$this->db->price_table." WHERE priceset_id=".$priceset_id." AND product_id='".$product_id."'"; if(count($this->db->fetchRows($this->db->query($query))) > 0) return true; else return false; } function create($priceset_id, $product_id, $price) { if (!$price) $price = 0; $query = "INSERT INTO ".$this->db->price_table." VALUES(0, ".$priceset_id.", '".$product_id."', ".$price.")"; $this->db->query($query); } function update($priceset_id, $product_id, $value) { $query = "UPDATE ".$this->db->price_table." SET "; $query .= "price='".$value[0]."' "; $query .= "WHERE priceset_id=".$priceset_id." AND product_id='".$product_id."'"; $this->db->query($query); } function delete($price_id) { $query = "DELETE FROM ".$this->db->price_table." WHERE price_id=".$price_id.""; $this->db->query($query); } function get($price_id = "", $col_names = array(), $search = "") { if($price_id == "") { if(count($col_names) == 0) $query = "SELECT * FROM ".$this->db->price_table; else { $query = "SELECT ".$col_names[0]; for($i = 1; $i < count($col_names); $i++) $query .= ", ".$col_names[$i]; $query .= " FROM ".$this->db->price_table; } if($search != "") $query .= " WHERE ".$search; $query .= " ORDER BY price_id ASC"; return $this->db->fetchRows($this->db->query($query)); } else { $query = "SELECT * FROM ".$this->db->price_table." WHERE price_id='".$price_id."'"; $query .= " ORDER BY price_id ASC"; return $this->db->fetchRows($this->db->query($query)); } } function getPrice($priceset_id, $product_id) { $query = "SELECT * FROM ".$this->db->price_table." WHERE priceset_id='".$priceset_id."' AND product_id='".$product_id."'"; return $this->db->fetchRows($this->db->query($query)); } function getPriceTax($priceset_id, $product_id, $netto, $tax_id = -1) { $query = "SELECT * FROM ".$this->db->price_table." WHERE priceset_id='".$priceset_id."' AND product_id='".$product_id."'"; $tmp = $this->db->fetchRows($this->db->query($query)); $price = $tmp[0][3]; if($tax_id == -1) { $product = new Product(); $tmp_product = $product->get($product_id); if(count($tmp_product) > 0) $tax_id = $tmp_product[0][4]; else return 0; } if($netto) { $tax = new Tax(); $tmp_tax = $tax->get($tax_id); if(count($tmp_tax) <= 0) return 0; $price = $price * ( 1 + $tmp_tax[0][2]); } return $price; } } ?>