K
K
kentos2021-03-18 16:56:45
Twig
kentos, 2021-03-18 16:56:45

How to display reviews without AJAX?

Hello, I want to display reviews without ajax, but for some reason the old solution is pulled up

What I changed in the product controller

// review no AJAX    
      $this->load->model('catalog/review');

      $data['text_no_reviews'] = $this->language->get('text_no_reviews');

      if (isset($this->request->get['page'])) {
        $page = $this->request->get['page'];
      } else {
        $page = 1;
      }

      $data['reviews_array'] = array();

      $review_total = $this->model_catalog_review->getTotalReviewsByProductId($product_id);

      $results = $this->model_catalog_review->getReviewsByProductId($product_id, ($page - 1) * 5, 5);

      foreach ($results as $result) {
        $data['reviews_array'][] = array(
          'author' => $result['author'],
          'text'   => nl2br($result['text']),
          'rating' => (int)$result['rating'],
          'reviews' => sprintf($this->language->get('text_reviews'), (int)$review_total),
          'date_added' => date("Y-m-d")
        );
      }

      $pagination = new Pagination();
      $pagination->total = $review_total;
      $pagination->page = $page;
      $pagination->limit = 5;
      $pagination->url = $this->url->link('product/product/review', 'product_id=' . $this->request->get['product_id'] . '&page={page}');

      $data['review_pagination'] = $pagination->render();
// review no AJAX


What added to Product.twig'
Replaced instead of div id="reviews">
<div id="reviews">
          {% if (reviews_array) %} 
            {% for review in reviews_array %} 
            <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>
              {% set i = 1 %}{% for i in i..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>
            <div itemprop="review" itemscope itemtype="http://schema.org/Review">
              <meta itemprop="name" content="{{ heading_title }}" >
              <meta itemprop="itemreviewed" content="{{ heading_title }}" >
              <meta itemprop="author" content="{{ review['author'] }}" >
              <meta itemprop="datePublished" content="{{ review['date_added'] }}">
              <div itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">
              <meta itemprop="worstRating" content = "1"/>
              <meta itemprop="ratingValue" content="{{ review['rating']}}"/>
              <meta itemprop="bestRating" content = "5"/>
              </div>
              <meta itemprop="description" content="{{ review['text'] }}" />
            </div>
            {% endfor %} 
            <div class="text-right">{{ pagination }}</div>
            {% else %} 
            <p>{{ text_no_reviews }}</p>
            {% endif %} 
              </div>


opencart 3.x

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question