Post by SkeR » Wed Jun 20, 2018 6:07 pm

Hello Guys,

I would ask for some help as its bugging me now. I am trying to rework the REVIEW section of opencart and make it as a module so i can display it whatever I want and also to display a number of reviews which i set as limit from the admin panel. I don't want to be dependend of the product anymore.

Everything at the backend modifications works fine and i can install the module edit it and so on.

Ot the CATALOG side on the other hand the things are different.
Here is my code of the different files at CATALOG side:

catalog/controller/extension/module/review.php

Code: Select all

<?php
class ControllerExtensionModuleReview extends Controller {
	public function index($setting) {
	    		$this->load->language('extension/module/review');

		$this->load->model('catalog/product');

		$data['reviews'] = array();
		
	    $results = $this->model_catalog_product->getReviews($setting['limit']);


	if ($results) {
			foreach ($results as $result) {

		    	$data['reviews'][] = array(
		    	'review_id'  => $result['review_id'],
				'author'     => $result['author'],
				'text'       => $result['text'],
				'rating'     => $result['rating'],
				'date_added' => $result['date_added']
		    	);
			}

			return $this->load->view('extension/module/review', $data);
	    }
	}
}

This function getReviews() i have added to the model product file and here is the code.

catalog/model/catalog/product.php

Code: Select all

		public function getReviews($limit) {
			$review_data = array();

	     $reviews_results_query = $this->db->query("SELECT r.review_id, r.author, r.rating, r.text, r.date_added FROM " . DB_PREFIX . "review r WHERE r.status = '1' ORDER BY r.date_added DESC LIMIT " . (int)$limit);

			foreach ($reviews_results_query->rows as $review_result) {
				$review_data[] = array(
				    'review_id'    => $review_result['review_id'],
					'author'       => $review_result['author'],
					'text'         => $review_result['text'],
			        'rating'       => $review_result['rating'],
					'date_added'   => $review_result['date_added']
				);
			}
			
	    	return $review_data;
		}
There i have modified the query which most likely to be the case of my problem but i don't know.

and the last but not least is the VIEW twig file

catalog/view/theme/my_theme/extension/module/review.twig

Code: Select all

<div class="list-group"> 
<h3 class="ListTitle">Reviews</h3>
<div class="row">
    {% if review %}
        {% for review in reviews %}

            <table class="table table-striped table-bordered">
                 <tr>
                     <td style="width: 50%;"><strong>{{ review.author }}</strong></td>
                    <td class="text-right">{{ review.date_added }}</td>
                 </tr>
                 <tr>
                 <td colspan="2"><p>{{ review.text }}</p>
                           {% for i in 1..5 %}
                                 {% if review.rating < i %} <span class="fa fa-stack"><i class="fa fa-star-o fa-stack-2x"></i></span> {% else %} <span class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i><i class="fa fa-star-o fa-stack-2x"></i></span> {% endif %}
                     {% endfor %}</td>
                </tr>
                </table>
        {% endfor %}
{% else %}
<p>No Reviews</p>
{% endif %}
</div>
</div>
I will be thankful if someone can have a look at it and give me some directions of how i can fix this issue.

Almost forgot to say what the promlem is.
When I add the module say to column right in layout/product for example page becomes blank, it loads the url and everything but white screen.

Thank you in advance

Newbie

Posts

Joined
Thu Oct 26, 2017 3:15 pm

Post by Qphoria » Thu Jun 21, 2018 1:48 am

You have

Code: Select all

{% if review %}
but I don't see that declared in the controller. I see "reviews" but not "review"

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by SkeR » Thu Jun 21, 2018 5:45 pm

It is my mistaek as the

Code: Select all

{% review %}
has to be

Code: Select all

{% reviews %}
and anyway i have corrected it and still blank white page if the module is loaded :( :( :( :(

Newbie

Posts

Joined
Thu Oct 26, 2017 3:15 pm

Post by Qphoria » Fri Jun 22, 2018 10:48 am

If you'd like i can take a look.. pm me ftp access

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: RoyT and 139 guests