Hackfut Security File Manager
Current Path:
/home/u126195517/domains/foodstamping.in/public_html/models
home
/
u126195517
/
domains
/
foodstamping.in
/
public_html
/
models
/
📁
..
📄
Product.php
(4.04 KB)
📁
gallery
Editing: Product.php
<?php class Product { private $conn; private $table_name = "products"; public $id; public $category_id; public $name; public $slug; public $description; public $price; public $original_price; public $image_primary; public $image_secondary; public $stock_quantity; public $status; public function __construct($db) { $this->conn = $db; } // Get all products public function getAllProducts($category_id = null, $limit = null, $offset = 0) { $query = "SELECT p.*, c.name as category_name FROM " . $this->table_name . " p LEFT JOIN categories c ON p.category_id = c.id WHERE p.status = 1"; if($category_id) { $query .= " AND p.category_id = :category_id"; } $query .= " ORDER BY p.created_at DESC"; if($limit) { $query .= " LIMIT :limit OFFSET :offset"; } $stmt = $this->conn->prepare($query); if($category_id) { $stmt->bindParam(":category_id", $category_id); } if($limit) { $stmt->bindParam(":limit", $limit, PDO::PARAM_INT); $stmt->bindParam(":offset", $offset, PDO::PARAM_INT); } $stmt->execute(); return $stmt; } // Create product public function create() { $query = "INSERT INTO " . $this->table_name . " SET name=:name, slug=:slug, category_id=:category_id, description=:description, price=:price, original_price=:original_price, image_primary=:image_primary, image_secondary=:image_secondary, stock_quantity=:stock_quantity"; $stmt = $this->conn->prepare($query); // Sanitize $this->name = htmlspecialchars(strip_tags($this->name)); $this->slug = $this->createSlug($this->name); // Bind values $stmt->bindParam(":name", $this->name); $stmt->bindParam(":slug", $this->slug); $stmt->bindParam(":category_id", $this->category_id); $stmt->bindParam(":description", $this->description); $stmt->bindParam(":price", $this->price); $stmt->bindParam(":original_price", $this->original_price); $stmt->bindParam(":image_primary", $this->image_primary); $stmt->bindParam(":image_secondary", $this->image_secondary); $stmt->bindParam(":stock_quantity", $this->stock_quantity); if($stmt->execute()) { return true; } return false; } // Update product public function update() { $query = "UPDATE " . $this->table_name . " SET name=:name, category_id=:category_id, description=:description, price=:price, original_price=:original_price, stock_quantity=:stock_quantity WHERE id = :id"; $stmt = $this->conn->prepare($query); $stmt->bindParam(":name", $this->name); $stmt->bindParam(":category_id", $this->category_id); $stmt->bindParam(":description", $this->description); $stmt->bindParam(":price", $this->price); $stmt->bindParam(":original_price", $this->original_price); $stmt->bindParam(":stock_quantity", $this->stock_quantity); $stmt->bindParam(":id", $this->id); if($stmt->execute()) { return true; } return false; } // Delete product public function delete() { $query = "UPDATE " . $this->table_name . " SET status = 0 WHERE id = :id"; $stmt = $this->conn->prepare($query); $stmt->bindParam(":id", $this->id); if($stmt->execute()) { return true; } return false; } private function createSlug($string) { return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string))); } } ?>
Upload File
Create Folder