Hassaan
Hassaan

Reputation: 13

How to show only reviews of current logged in user in Opencart?

I need a little help regarding OpenCart

I want to show reviews only to logged In customers [I have succeeded in that]

But now I want to show review only to user who have wrote it.

Example:

If User A logged in and wrote a Review Only User A will see it not any other users

If User B logged in and wrote a Review Only user B will see his review, not user A or any other logged in user.

Why I Want This:

I want because if user comes back after few days or months he can see his review, I don't want to show all reviews to all users only to user who have added it

Upvotes: 0

Views: 327

Answers (1)

machineaddict
machineaddict

Reputation: 3236

In the model ModelCatalogReview there are 2 functions you need to change: getReviewsByProductId and getTotalReviewsByProductId.

getReviewsByProductId:

$query = $this->db->query("SELECT r.review_id, r.author, r.rating, r.text, p.product_id, pd.name, p.price, p.image, 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 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') . "' AND r.customer_id = '" . (int)$this->customer->getId() . "' ORDER BY r.date_added DESC LIMIT " . (int)$start . "," . (int)$limit);

(notice AND r.customer_id = '" . (int)$this->customer->getId() . "')

getTotalReviewsByProductId:

$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') . "' AND r.customer_id = '" . (int)$this->customer->getId() . "'");

(notice AND r.customer_id = '" . (int)$this->customer->getId() . "')

This also lists the comments to logged in user only, because there are no comments with the customer_id = '0'.

Later Edit:
This applies to Opencart 1.5.5.1. If you are using a different version, you might need to change the code a little.

Upvotes: 1

Related Questions