Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Живой поиск перекидывает на пустот поиск


 Share

Recommended Posts

Есть сайт
запилен на шаблоне Aridius Eclipse , перепилен наверное много раз


в нем есть модуль пои ска - живой поиск
ик вот
если ввести запрос, выводит в выпадаюещём блоке товары, в которых есть поисковая фраза
но если нажать на кнопку поиска, или нажать на показать все
перекидывает на пустую гдефолтную страницу поиска /index.php?route=product/search
вот его tpl

Спойлер
<script>
  window.jquery_scripts.push(function() {
    // livesearch
    (function($) { $.fn.livesearch = function(option) { return this.each(function() { this.timer = null; this.items = new Array(); this.minLength = <?php echo $aridius_livesearch_symbol; ?>; $.extend(this, option); $(this).attr('livesearch', 'off');
// Blur
      $(this).on('blur', function() { setTimeout(function(object) { object.hide(); }, 200, this); });
// Keydown
      $(this).on('input', function(event) { if (event.keyCode == 27) { this.hide(); } else if (this.value.length <= this.minLength) { this.hide(); } else { this.request(); } });
// Show
      this.show = function() { var pos = $(this).position();  $(this).siblings('ul.dropdown-menu').css({ top: pos.top + $(this).outerHeight(), left: pos.left });  $(this).siblings('ul.dropdown-menu').show(); }
// Hide
      this.hide = function() { $(this).siblings('ul.dropdown-menu').hide(); }
// Request
      this.request = function() { clearTimeout(this.timer);  this.timer = setTimeout(function(object) { object.source($(object).val(), $.proxy(object.response, object)); }, 200, this); }
// Response
      this.response = function(json) { html = '';  if (json.length) { for (i = 0; i < json.length; i++) { this.items[json[i]['value']] = json[i]; }  for (i = 0; i < json.length; i++) { if (!json[i]['category']) { html += '<a href="javascript:void(0)" onclick="location = &quot; '+ json[i]['href'] + '&quot;" >'; html += '<li class="search-container2" data-value="' + json[i]['value'] + '">'; if(json[i]['image']){ html += '<div class="search-thumb"><img src="' + json[i]['image'] + '"/></div>'; } html += '<div class="search-container">'; html += '<div ><div class="search-name">' + json[i]['label'] + '</div><br/>'; html += '<div class="search-special">' + json[i]['special'] + '</div></div>'; if(json[i]['special']){ html += '<div class="search-price2">' + json[i]['price'] + '</div></div>'; } else { html += '<div class="search-price">' + json[i]['price'] + '</div></div>'; } html += '</div>'; html += '<div style="clear:both;"></div></li></a>'; } }  html += '<a onclick="$(\'#search .btn-default\').trigger(\'click\');" class="search-all"><?php echo $aridius_livesearch_viewmore; ?></a>';  }  if (html) { this.show(); } else { this.hide(); }  $(this).siblings('ul.dropdown-menu').html(html); }
      $(this).after('<ul class="dropdown-menu"></ul>'); $(this).siblings('ul.dropdown-menu').delegate('a', 'click', $.proxy(this.click, this));  }); } })(window.jQuery);

    $("input[name='search']").livesearch({source:function(a,b){$.ajax({url:"index.php?route=extension/module/aridius_livesearch/livesearch&search="+encodeURIComponent(a),dataType:"json",success:function(a){b($.map(a,function(a){return{label:a.name,price:a.price,special:a.special,image:a.image,href:a.href,value:a.product_id}}))}})},select:function(a){$("input[name='search']").val(a.label)}});
  });
</script>

 

 

вот его контироллер
мож кто подскажет в чем гдело?
 

Спойлер
<?php
class ControllerExtensionModuleAridiusLivesearch extends Controller {
	
    public function index($setting) {

        $this->load->language('extension/module/aridius_livesearch');

		$data['aridius_livesearch_viewmore'] = $this->language->get('aridius_livesearch_viewmore');
	    $data['aridius_livesearch_symbol'] = $this->config->get('aridius_livesearch_symbol');
		$data['aridius_livesearch_img'] = $this->config->get('aridius_livesearch_img');

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

	public function livesearch() {
		
		$json = array();

		if (isset($this->request->get['search'])) {
			$this->load->model('catalog/product');
            $this->load->model('tool/image');
			if (isset($this->request->get['search'])) {
				$filter_name = $this->request->get['search'];
			} else {
				$filter_name = '';
			}

			if (isset($this->request->get['search'])) {
				$filter_tag = $this->request->get['search'];
			} else {
				$filter_tag = '';
			}
			
			if (isset($this->request->get['search'])) {
				$filter_model = $this->request->get['search'];
			} else {
				$filter_model = '';
			}
			
			if (isset($this->request->get['search'])) {
				$filter_sku = $this->request->get['search'];
			} else {
				$filter_sku = '';
			}
			
			if (isset($this->request->get['search'])) {
				$filter_description = $this->request->get['search'];
			} else {
				$filter_description = '';
			}

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

			$data = array(
				'filter_name'         => $filter_name,
				'filter_tag'          => ($this->config->get('aridius_livesearch_tag')) ? false : $filter_tag,
				'filter_model'        => ($this->config->get('aridius_livesearch_livesearch_model')) ? false : $filter_model,
				'filter_sku'          => ($this->config->get('aridius_livesearch_sku')) ? false : $filter_sku,
				'filter_description'  => ($this->config->get('aridius_livesearch_description')) ? false : $filter_description,
				'start'               => 0,
				'limit'               => $this->config->get('aridius_livesearch_limit')
			);

			$results = $this->model_catalog_product->liveSearch($data);

			foreach ($results as $result) {
				
			if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
			  $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
		    } else {
			  $price = '';
			}

			if ((float)$result['special']) {
			  $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
			} else {
			  $special = '';
			}

			if ($result['image']) {
			  $image = $this->model_tool_image->resize($result['image'], $this->config->get('aridius_livesearch_width'), $this->config->get('aridius_livesearch_height'));
			} else {
			  $image = $this->model_tool_image->resize('placeholder.png', $this->config->get('aridius_livesearch_width'), $this->config->get('aridius_livesearch_height'));
			}

			$json[] = array(
					'product_id' => $result['product_id'],
				    'price'      => $price,
					'special'    => $special,
		            'image'      => ($this->config->get('aridius_livesearch_img')) ? false : $image,
                    'href'       => $this->url->link('product/product', '&product_id=' . $result['product_id']),
					'name'       => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'))
				);
			}
		}

		$this->response->setOutput(json_encode($json));
	}
}

 


 

Link to comment
Share on other sites


1 час назад, annnn сказал:

Есть сайт
запилен на шаблоне Aridius Eclipse , перепилен наверное много раз


в нем есть модуль пои ска - живой поиск
ик вот
если ввести запрос, выводит в выпадаюещём блоке товары, в которых есть поисковая фраза
но если нажать на кнопку поиска, или нажать на показать все
перекидывает на пустую гдефолтную страницу поиска /index.php?route=product/search
вот его tpl

  Скрыть контент

<script>
  window.jquery_scripts.push(function() {
    // livesearch
    (function($) { $.fn.livesearch = function(option) { return this.each(function() { this.timer = null; this.items = new Array(); this.minLength = <?php echo $aridius_livesearch_symbol; ?>; $.extend(this, option); $(this).attr('livesearch', 'off');
// Blur
      $(this).on('blur', function() { setTimeout(function(object) { object.hide(); }, 200, this); });
// Keydown
      $(this).on('input', function(event) { if (event.keyCode == 27) { this.hide(); } else if (this.value.length <= this.minLength) { this.hide(); } else { this.request(); } });
// Show
      this.show = function() { var pos = $(this).position();  $(this).siblings('ul.dropdown-menu').css({ top: pos.top + $(this).outerHeight(), left: pos.left });  $(this).siblings('ul.dropdown-menu').show(); }
// Hide
      this.hide = function() { $(this).siblings('ul.dropdown-menu').hide(); }
// Request
      this.request = function() { clearTimeout(this.timer);  this.timer = setTimeout(function(object) { object.source($(object).val(), $.proxy(object.response, object)); }, 200, this); }
// Response
      this.response = function(json) { html = '';  if (json.length) { for (i = 0; i < json.length; i++) { this.items[json[i]['value']] = json[i]; }  for (i = 0; i < json.length; i++) { if (!json[i]['category']) { html += '<a href="javascript:void(0)" onclick="location = &quot; '+ json[i]['href'] + '&quot;" >'; html += '<li class="search-container2" data-value="' + json[i]['value'] + '">'; if(json[i]['image']){ html += '<div class="search-thumb"><img src="' + json[i]['image'] + '"/></div>'; } html += '<div class="search-container">'; html += '<div ><div class="search-name">' + json[i]['label'] + '</div><br/>'; html += '<div class="search-special">' + json[i]['special'] + '</div></div>'; if(json[i]['special']){ html += '<div class="search-price2">' + json[i]['price'] + '</div></div>'; } else { html += '<div class="search-price">' + json[i]['price'] + '</div></div>'; } html += '</div>'; html += '<div style="clear:both;"></div></li></a>'; } }  html += '<a onclick="$(\'#search .btn-default\').trigger(\'click\');" class="search-all"><?php echo $aridius_livesearch_viewmore; ?></a>';  }  if (html) { this.show(); } else { this.hide(); }  $(this).siblings('ul.dropdown-menu').html(html); }
      $(this).after('<ul class="dropdown-menu"></ul>'); $(this).siblings('ul.dropdown-menu').delegate('a', 'click', $.proxy(this.click, this));  }); } })(window.jQuery);

    $("input[name='search']").livesearch({source:function(a,b){$.ajax({url:"index.php?route=extension/module/aridius_livesearch/livesearch&search="+encodeURIComponent(a),dataType:"json",success:function(a){b($.map(a,function(a){return{label:a.name,price:a.price,special:a.special,image:a.image,href:a.href,value:a.product_id}}))}})},select:function(a){$("input[name='search']").val(a.label)}});
  });
</script>

 

 

вот его контироллер
мож кто подскажет в чем гдело?
 

  Скрыть контент

<?php
class ControllerExtensionModuleAridiusLivesearch extends Controller {
	
    public function index($setting) {

        $this->load->language('extension/module/aridius_livesearch');

		$data['aridius_livesearch_viewmore'] = $this->language->get('aridius_livesearch_viewmore');
	    $data['aridius_livesearch_symbol'] = $this->config->get('aridius_livesearch_symbol');
		$data['aridius_livesearch_img'] = $this->config->get('aridius_livesearch_img');

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

	public function livesearch() {
		
		$json = array();

		if (isset($this->request->get['search'])) {
			$this->load->model('catalog/product');
            $this->load->model('tool/image');
			if (isset($this->request->get['search'])) {
				$filter_name = $this->request->get['search'];
			} else {
				$filter_name = '';
			}

			if (isset($this->request->get['search'])) {
				$filter_tag = $this->request->get['search'];
			} else {
				$filter_tag = '';
			}
			
			if (isset($this->request->get['search'])) {
				$filter_model = $this->request->get['search'];
			} else {
				$filter_model = '';
			}
			
			if (isset($this->request->get['search'])) {
				$filter_sku = $this->request->get['search'];
			} else {
				$filter_sku = '';
			}
			
			if (isset($this->request->get['search'])) {
				$filter_description = $this->request->get['search'];
			} else {
				$filter_description = '';
			}

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

			$data = array(
				'filter_name'         => $filter_name,
				'filter_tag'          => ($this->config->get('aridius_livesearch_tag')) ? false : $filter_tag,
				'filter_model'        => ($this->config->get('aridius_livesearch_livesearch_model')) ? false : $filter_model,
				'filter_sku'          => ($this->config->get('aridius_livesearch_sku')) ? false : $filter_sku,
				'filter_description'  => ($this->config->get('aridius_livesearch_description')) ? false : $filter_description,
				'start'               => 0,
				'limit'               => $this->config->get('aridius_livesearch_limit')
			);

			$results = $this->model_catalog_product->liveSearch($data);

			foreach ($results as $result) {
				
			if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
			  $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
		    } else {
			  $price = '';
			}

			if ((float)$result['special']) {
			  $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
			} else {
			  $special = '';
			}

			if ($result['image']) {
			  $image = $this->model_tool_image->resize($result['image'], $this->config->get('aridius_livesearch_width'), $this->config->get('aridius_livesearch_height'));
			} else {
			  $image = $this->model_tool_image->resize('placeholder.png', $this->config->get('aridius_livesearch_width'), $this->config->get('aridius_livesearch_height'));
			}

			$json[] = array(
					'product_id' => $result['product_id'],
				    'price'      => $price,
					'special'    => $special,
		            'image'      => ($this->config->get('aridius_livesearch_img')) ? false : $image,
                    'href'       => $this->url->link('product/product', '&product_id=' . $result['product_id']),
					'name'       => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'))
				);
			}
		}

		$this->response->setOutput(json_encode($json));
	}
}

 


 

 

Не передается value в input при поиске. Нужно гдебажить.

  • +1 1
Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.