Помощь Строчка в скрипте вешает наглухо сайт. Как решить?

Alexeina66

Мой дом здесь!
Регистрация
26 Авг 2013
Сообщения
415
Реакции
436
Доброго дня.
Ocstore 3 + нестандартный шаблон Техникс.
Устанавливаю на него модуль Вопросы-ответы, который выводит в карточке товара вкладку с формой и список вопросов.
В скрипте строчка, которая должна подтягивать id товаров и выводить список вопросов наглухо вешает сайт.
Код:
$('#question').load('index.php?route=product/question/question_list&product_id={{ product_id }}');
Сам скрипт такой
Код:
<script type="text/javascript"><!--
$(document).ready(function() {
    $('#button_ask').click(function (e) {
      e.preventDefault();
      $('.nav-tabs a[href="#tab-questions"]').tab('show') ;
    $('html, body').animate({
        scrollTop: $(".nav.nav-tabs.md").offset().top
    }, 1000);
});
});
$('#question').delegate('.pagination a', 'click', function(e) {
  e.preventDefault();
$("html,body").animate({scrollTop:(($("#question").offset().top)-50)},500);
    $('#question').fadeOut(50);

    $('#question').load(this.href);

    $('#question').fadeIn(500);
});


$('#input-private-fake').on('change', function(){
   $('#input-private').val(this.checked ? 1 : 0);
});

$('#question').load('index.php?route=product/question/question_list&product_id={{ product_id }}');

$('#button-question').on('click', function() {
    $.ajax({
        url: 'index.php?route=product/question/ask_question&product_id={{ product_id }}',
        type: 'post',
        dataType: 'json',
        data: 'name=' + encodeURIComponent($('input[name=\'q_name\']').val()) +
              '&email=' + encodeURIComponent($('input[name=\'q_email\']').val()) +
              '&text=' + encodeURIComponent($('textarea[name=\'q_text\']').val()) +
              '&private=' + encodeURIComponent($('input[name=\'q_private\']').val()) +
              '&captcha_product_questions=' + encodeURIComponent($('input[name=\'captcha_product_questions\']').val()),
       
        beforeSend: function() {
            $('#button-question').button('loading');
        },
        complete: function() {
            $('#button-question').button('reset');
            $('#captcha_product_questions').attr('src', 'index.php?route=product/question/captcha#'+new Date().getTime());
            $('input[name=\'captcha_product_questions\']').val('');
        },
        success: function(json) {
            $('.alert-success, .alert-danger').remove();
           
            if (json['error']) {
                $('#question').after('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + '</div>');
            }
           
            if (json['success']) {
                $('#question').after('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + '</div>');
               
                $('input[name=\'q_name\']').val('');
                $('input[name=\'q_email\']').val('');
                $('textarea[name=\'q_text\']').val('');
                $('input[name=\'q_private\']:checked').prop('checked', false);
                $('input[name=\'captcha_product_questions\']').val('');
            }
        }
    });
});
//--></script>
PHP:
<?php
class ControllerProductQuestion extends Controller {
    public function index() {
       
        $this->load->language('product/question');
       
        $data['heading_ask'] = $this->language->get('heading_ask');
        $data['entry_name'] = $this->language->get('entry_name');
        $data['entry_email'] = $this->language->get('entry_email');
       
        $data['entry_private'] = $this->language->get('entry_private');
        $data['entry_question'] = $this->language->get('entry_question');
        $data['entry_captcha'] = $this->language->get('entry_captcha');
        $data['text_note'] = $this->language->get('text_note');
        $data['text_loading'] = $this->language->get('text_loading');
        $data['button_send'] = $this->language->get('button_send');
       
        $data['allow_private'] = $this->config->get('product_question_allow_private');
       
        $this->load->model('catalog/question');
       
        if (isset($this->request->get['product_id'])) {
            $data['product_id'] = (int)$this->request->get['product_id'];
        } else {
            $data['product_id'] = 0;
        }

        return $this->load->view('product/question', $data);
    }
   
   
   
    public function question_list () {
        $this->load->language('product/question');

        $this->load->model('catalog/question');
       
        $data['text_question_from'] = $this->language->get('text_question_from');
        $data['text_no_questions'] = $this->language->get('text_no_questions');
        $data['text_no_answer'] = $this->language->get('text_no_answer');
        $data['text_our_answer'] = $this->language->get('text_our_answer');

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

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

        $questions_total = $this->model_catalog_question->getTotalQuestionsByProductId($this->request->get['product_id']);
       
        $limit = $this->config->get('product_question_per_page');
       
        $results = $this->model_catalog_question->getQuestionsByProductId($this->request->get['product_id'], ($page - 1) * $limit, $limit);
       
        foreach ($results as $result) {
            $data['questions'][] = array(
                'author'     => $result['author'],
                'text'       => nl2br($result['text']),
                'answer'       => nl2br($result['answer']),
                'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
            );
        }

        $pagination = new Pagination();
        $pagination->total = $questions_total;
        $pagination->page = $page;
        $pagination->limit = $this->config->get('product_question_per_page');
        $pagination->url = $this->url->link('product/question/question_list', 'product_id=' . $this->request->get['product_id'] . '&page={page}');

        $data['pagination'] = $pagination->render();
       
        $data['results'] = sprintf($this->language->get('text_pagination'), ($questions_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($questions_total - $limit)) ? $questions_total : ((($page - 1) * $limit) + $limit), $questions_total, ceil($questions_total / $limit));
       
        $this->response->setOutput($this->load->view('product/question_list', $data));
       
    }
   
   
        public function ask_question() {
        $this->load->language('product/question');

        $json = array();

        if ($this->request->server['REQUEST_METHOD'] == 'POST') {
            if ((utf8_strlen($this->request->post['name']) < 2) || (utf8_strlen($this->request->post['name']) > 30)) {
                $json['error'] = $this->language->get('error_name');
            }
           
            if ((utf8_strlen($this->request->post['email']) < 2) || (utf8_strlen($this->request->post['email']) > 60)) {
                $json['error'] = $this->language->get('error_email');
            }

            if ((utf8_strlen($this->request->post['text']) < 10) || (utf8_strlen($this->request->post['text']) > 1000)) {
                $json['error'] = $this->language->get('error_text');
            }

            /* if (empty($this->session->data['captcha_product_questions']) || ($this->session->data['captcha_product_questions'] != $this->request->post['captcha_product_questions'])) {
                $json['error'] = $this->language->get('error_captcha');
            } */

            unset($this->session->data['captcha_product_questions']);

            if (!isset($json['error'])) {
                $this->load->model('catalog/question');

                $this->model_catalog_question->addQuestion($this->request->get['product_id'], $this->request->post);

                $json['success'] = $this->language->get('text_success');
            }
        }

        $this->response->addHeader('Content-Type: application/json');
        $this->response->setOutput(json_encode($json));
    }
   
   
    public function captcha() {
        $num1=rand(2,6); //Generate First number between 1 and 9 
        $num2=rand(2,6); //Generate Second number between 1 and 9 
        $this->session->data['captcha_product_questions'] = $num1+$num2;
        $image = imagecreatetruecolor(58, 22);
        $width = imagesx($image);
        $height = imagesy($image);
        $black = imagecolorallocate($image, 50, 50, 50);
        $white = imagecolorallocate($image, 255, 255, 255);
        imagefilledrectangle($image, 0, 0, $width, $height, $white);
        imagestring($image, 4, 0, 3, "$num1"." + "."$num2"." =", $black);
        header('Content-type: image/png');
        imagepng($image);
        imagedestroy($image);
    }
}

Код:
<file path="catalog/controller/product/product.php">
        <operation>
            <search><![CDATA[
            $this->model_catalog_product->updateViewed($this->request->get['product_id']);
            ]]></search>
            <add position="after"><![CDATA[
            $data['question_status'] = $this->config->get('product_question_status');
            $data['product_questions'] = $this->load->controller('product/question');
            $this->load->language('product/question');
            $data['tab_questions'] = $this->language->get('tab_questions');
            $data['button_ask'] = $this->language->get('button_ask');
            $this->load->model('catalog/question');
            $data['questions_total'] = $this->model_catalog_question->getTotalQuestionsByProductId($this->request->get['product_id']);
            ]]></add>
        </operation>
    </file>
    <file path="catalog/view/theme/*/template/product/product.twig">
        <operation>
            <search index="0"><![CDATA[
            {% if attribute_groups %}
            ]]></search>
            <add position="before"><![CDATA[
            {% if question_status %}
            <li id="product-question"><a href="#tab-questions" data-toggle="tab">{{ tab_questions }} ({{ questions_total }})</a></li>
            {% endif %}
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[
            <div class="tab-content">
            ]]></search>
            <add position="after"><![CDATA[
            {% if question_status %}
              <div class="tab-pane" id="tab-questions">
              {{ product_questions }}
            </div>
              {% endif %}
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[
            <button type="button" data-toggle="tooltip" class="btn btn-default" title="{{ button_compare }}" onclick="compare.add('{{ product_id }}');"><i class="fa fa-exchange"></i></button>
            ]]></search>
            <add position="after"><![CDATA[
            {% if (question_status) %}
            <button type="button" data-toggle="tooltip" class="btn btn-default" id="button_ask" href="#tab-questions" data-toggle="tooltip" title="{{ button_ask }}"><i class="fa fa-question-circle"></i></button>
            {% endif %}
            ]]></add>
        </operation>
    </file>
    <file path="catalog/view/theme/oct_ultrastore/template/product/product.twig">
        <operation>
            <search index="0"><![CDATA[
            {% if (dop_tab.title is defined and dop_tab.title) and (dop_tab.text is defined and dop_tab.text) %}
            ]]></search>
            <add position="before"><![CDATA[
                    {% if question_status %}
                    <li class="us-product-nav-item">
                        <a href="javascript:;" onclick="dd('us-product-question');">{{ tab_questions }} ({{ questions_total }})</a>
                    </li>
                    {% endif %}
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[
            $( ".us-product-attributes" ).hide();
            ]]></search>
            <add position="after"><![CDATA[
            $( ".us-product-question" ).hide();
            ]]></add>
        </operation>
        <operation>
            <search index="1"><![CDATA[
            {% if description %}
            ]]></search>
            <add position="after"><![CDATA[
                {% if question_status %}
                <div id="us-product-question" class="us-product-question" style="display:none;">
                    <style>
                        #us-product-question {
                            padding: 30px;
                        }
                        .well.question {
                            padding-bottom: 30px;
                        }
                    </style>   
                      {{ product_questions }}
                </div>
                {% endif %}
            ]]></add>
        </operation>
    </file>
    <file path="admin/controller/common/column_left.php">
        <operation>
            <search><![CDATA[
            if ($catalog) {
            ]]></search>
            <add position="before"><![CDATA[
            $this->load->language('catalog/question');
            if ($this->user->hasPermission('access', 'catalog/question')) {
                $catalog[] = array(
                    'name'       => $this->language->get('question_menu'),
                    'href'     => $this->url->link('catalog/question', 'user_token=' . $this->session->data['user_token'], true),
                    'children' => array()
                );}
            ]]></add>
        </operation>
    </file>
    <file path="admin/model/catalog/product.php">
        <operation>
            <search><![CDATA[
            $this->db->query("DELETE FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product_id . "'");
            ]]></search>
            <add position="after"><![CDATA[
            $this->db->query("DELETE FROM " . DB_PREFIX . "question WHERE product_id = '" . (int)$product_id . "'");
            ]]></add>
        </operation>
    </file>
 
Назад
Сверху