Jump to content
Sign in to follow this  
ARTEMN5

Цена в живом поиске

Recommended Posts

Есть модуль, работающий чисто через vqmod(не помню где брал), он выводит поисковые ответы сразу после ввода.

Есть ли мастера, которые знают как добавить помимо названия и картинки добавить стоимость товара?

Вот код модуля 

ставить в папку public_html/vqmod/xml  у меня файл называется livesearch-02.xml

<?xml version="1.0" encoding="UTF-8"?>
<modification>
        <id>Opencart Live Search</id>
        <version>0.2</version>
        <author>Kardos Sándor / sandor.kardos@cantinart.hu</author>
        <file name="catalog/controller/product/search.php">
                <operation>
                        <search position="replace" offset="1"><![CDATA[
							$this->response->setOutput($this->render());
                        ]]></search>
                        <add><![CDATA[
							$this->response->setOutput($this->render()); }
							function livesearch() { 
								$search = $this->request->get['search'];
								$this->load->model('catalog/product');
								$this->load->model('tool/image');
								$limit = 10;
								$data = array('filter_name' => $search, 'filter_description' => $search, 'start' => 0, 'limit' => $limit);
								$products = $this->model_catalog_product->getProducts($data);
								$i = 0;
								foreach ($products as $product) {
									if ($product['image']) {
										$results[$i]["img"] = $this->model_tool_image->resize($product['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
									} else {
										$results[$i]["img"] = "";
									}
									$results[$i]["name"] = $product["name"];
									$results[$i]["href"] = $this->url->link('product/product', 'product_id=' . $product['product_id']);
									$i++;
								}
								if (count($results) >= $limit) {
									$results[] = array(
										"img" => "",
										"name" => '<p class="more">More...</p>',
										"href" => $this->url->link('product/search', 'description=true&search=' . $search)
									);
								}
								if (isset($results)) {
									echo json_encode($results);
								} else {
									echo json_encode("");
								}
							}
                        ]]></add>
                </operation>
        </file>
        <file name="catalog/view/theme/*/template/common/footer.tpl">
                <operation>
                        <search position="replace"><![CDATA[
							</body></html>
                        ]]></search>
                        <add><![CDATA[
							<script>
								$(function(){
									var i = (!!$("#livesearch").length ? $("#livesearch") : $("<ul id='livesearch'></ul>") ), s = $("#header [name=search]");
									function repositionLivesearch() { i.css({ top: (s.offset().top+s.outerHeight()), left:s.offset().left, width: s.outerWidth() }); }
									$(window).resize(function(){ repositionLivesearch(); });
									s.keyup(function(e){
										switch (e.keyCode) {
											case 13:
												$(".active", i).length && (window.location = $(".active a", i).attr("href"));
												return false;
											break;
											case 40:
												($(".active", i).length ? $(".active", i).removeClass("active").next().addClass("active") : $("li:first", i).addClass("active"))
												return false;
											break;
											case 38:
												($(".active", i).length ? $(".active", i).removeClass("active").prev().addClass("active") : $("li:last", i).addClass("active"))
												return false;
											break;
											default:
												var query = s.val();
												if (query.length > 2) {
													$.getJSON(
														"<?php echo HTTP_SERVER; ?>?route=product/search/livesearch&search=" + query,
														function(data) {
															i.empty();
															$.each(data, function( k, v ) { i.append("<li><a href='"+v.href+"'><img src='"+v.img+"' alt='"+v.name+"'><span>"+v.name+"</span></a></li>") });
															i.remove(); $("body").prepend(i); repositionLivesearch();
														}
													);
												} else {
													i.empty();
												}
										}
									}).blur(function(){ setTimeout(function(){ i.hide() },500); }).focus(function(){ repositionLivesearch(); i.show(); });
								});
							</script>
							<style>
								[name=search] {
									outline: none;
								}
								#livesearch, #livesearch * {
									margin: 0;
									padding: 0;
									list-style: none;
								}
								#livesearch {
									position: absolute;
									width: 200px;
									top: 0px;
									background: #ffffff;
									z-index: 100;
									box-shadow: 0px 10px 30px rgba(0,0,0,.5);
								}
								#livesearch li {
									border-top: 1px solid #eeeeee;
								}
								#livesearch a {
									display: block;
									clear: both;
									overflow: hidden;
									line-height: 25px;
									padding: 10px;
								}
								#livesearch a:hover, #livesearch li.active a {
									background: #38B0E3;
									color: #ffffff;
								}
								#livesearch img {
									float: left;
									width: 50px;
									height: 50px;
									margin-right: 10px;
								}
								#livesearch img[src=''] {
									display: none;
								}
								.more {
									text-align: center;
								}
							</style>
							</body></html>
                        ]]></add>
                </operation>
        </file>
</modification>

Надеюсь поможете

Share this post


Link to post
Share on other sites

Хорошее решение=)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×

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.