Back to Opencart

File catalog\model\catalog\review.php

docs/api/source-catalog.model.catalog.review.html

4.1.0.35.8 KB
Original Source

Namespaces

Classes

| 1: | <?php | | 2: | namespace Opencart\Catalog\Model\Catalog; | | 3: | /** | | 4: | * Class Review | | 5: | * | | 6: | * @package Opencart\Catalog\Model\Catalog | | 7: | */ | | 8: | class Review extends \Opencart\System\Engine\Model { | | 9: | /** | | 10: | * Add Review | | 11: | * | | 12: | * @param int $product_id | | 13: | * @param array<string, mixed> $data | | 14: | * | | 15: | * @return int | | 16: | */ | | 17: | public function addReview(int $product_id, array $data): int { | | 18: | $this->db->query("INSERT INTO " . DB\_PREFIX . "review SET author = '" . $this->db->escape($data['author']) . "', customer_id = '" . (int)$this->customer->getId() . "', product_id = '" . (int)$product_id . "', text = '" . $this->db->escape($data['text']) . "', rating = '" . (int)$data['rating'] . "', date_added = NOW()"); | | 19: | | | 20: | return $this->db->getLastId(); | | 21: | } | | 22: | | | 23: | /** | | 24: | * Get Reviews By Product ID | | 25: | * | | 26: | * @param int $product_id | | 27: | * @param int $start | | 28: | * @param int $limit | | 29: | * | | 30: | * @return array<int, array<string, mixed>> | | 31: | */ | | 32: | public function getReviewsByProductId(int $product_id, int $start = 0, int $limit = 20): array { | | 33: | if ($start < 0) { | | 34: | $start = 0; | | 35: | } | | 36: | | | 37: | if ($limit < 1) { | | 38: | $limit = 20; | | 39: | } | | 40: | | | 41: | $query = $this->db->query("SELECT r.author, r.rating, r.text, r.date_added FROM " . DB\_PREFIX . "review r LEFT JOIN " . DB\_PREFIX . "product p ON (r.product\_id = p.product\_id) LEFT JOIN " . DB\_PREFIX . "product\_description pd ON (p.product\_id = pd.product\_id) WHERE r.product\_id = '" . (int)$product_id . "' AND p.date_available <= NOW() AND p.status = '1' AND r.status = '1' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY r.date_added DESC LIMIT " . (int)$start . "," . (int)$limit); | | 42: | | | 43: | return $query->rows; | | 44: | } | | 45: | | | 46: | /** | | 47: | * Get Total Reviews By Product ID | | 48: | * | | 49: | * @param int $product_id | | 50: | * | | 51: | * @return int | | 52: | */ | | 53: | public function getTotalReviewsByProductId(int $product_id): int { | | 54: | $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB\_PREFIX . "review r LEFT JOIN " . DB\_PREFIX . "product p ON (r.product\_id = p.product\_id) LEFT JOIN " . DB\_PREFIX . "product\_description pd ON (p.product\_id = pd.product\_id) WHERE p.product\_id = '" . (int)$product_id . "' AND p.date_available <= NOW() AND p.status = '1' AND r.status = '1' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'"); | | 55: | | | 56: | return (int)$query->row['total']; | | 57: | } | | 58: | } | | 59: | |

OpenCart API API documentation generated by ApiGen dev-master