Matteo Posted July 4, 2018 Share Posted July 4, 2018 i'm tring to make the ajax search block working on ps 1.7 with no luck. Default installation has a bug on variable on product object (the category are not show on default ajax suggestion in ps 1.7.2 ..... after month of "stable" release). This is the default ps_blockserach module variable accessible on frontend in the ajax serach autocomplete for the product object active:"1" add_to_cart_url:"https://store.sixrace.it/it/carrello?add=1&id_product=184&id_product_attribute=0" canonical_url:"https://store.sixrace.it/it/cerchioni/184-cerchi-oz-gass-rs-a-in-alluminio-per-panigale-v4-ozgaspaniv4.html" description_short:"<p>Cerchi OZ GASS RS-A in alluminio per Ducati Panigale V4 monobraccio</p>" discount_amount:"362,16 €" discount_percentage:"-15%" discount_percentage_absolute:"15%" discount_to_display:"362,16 €" discount_type:"percentage" has_discount:true id_product:"184" label:undefined labels:{tax_short: "(Tasse incl.)", tax_long: "Tasse incluse"} link:"https://store.sixrace.it/it/cerchioni/184-cerchi-oz-gass-rs-a-in-alluminio-per-panigale-v4-ozgaspaniv4.html" link_rewrite:"cerchi-oz-gass-rs-a-in-alluminio-per-panigale-v4-ozgaspaniv4" main_variants:[] manufacturer_name:"OZ" name:"Cerchi OZ GASS RS-A in alluminio per Panigale V4" price:"2.052,22 €" price_amount:2052.22 rate:22 reference:"OZGASPANIV4" regular_price:"2.414,38 €" regular_price_amount:2414.38 tax_name:"IVA IT 22%" unit_price:"" url:"https://store.sixrace.it/it/cerchioni/184-cerchi-oz-gass-rs-a-in-alluminio-per-panigale-v4-ozgaspaniv4.html" value:undefined in /classes/Search.php we can find a lot of database query and one with ajax if ($ajax) { $sql = 'SELECT DISTINCT p.id_product, pl.name pname, cl.name cname, cl.link_rewrite crewrite, pl.link_rewrite prewrite '.$score.', pi.id_image pimg FROM '._DB_PREFIX_.'product p INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON ( p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').' ) '.Shop::addSqlAssociation('product', 'p').' INNER JOIN `'._DB_PREFIX_.'category_lang` cl ON ( product_shop.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').' ) INNER JOIN `'._DB_PREFIX_.'image` pi ON ( p.`id_product` = pi.`id_product` AND position = 1 ) WHERE p.`id_product` '.$product_pool.' ORDER BY position DESC LIMIT 10'; return $db->executeS($sql, true, false); } But this not help me on find WHY category are not passed to the product object and also a way to query the default image link This is the ps_searchbar.js module file with some modification, the "category_name" is a standard code of the 1.7.2 "stable" release that result in an non exist variable .. /* global $ */ $(document).ready(function () { var $searchWidget = $('#search_widget'); var $searchBox = $searchWidget.find('input[type=text]'); var searchURL = $searchWidget.attr('data-search-controller-url'); $.widget('prestashop.psBlockSearchAutocomplete', $.ui.autocomplete, { _renderItem: function (ul, product) { console.log(product); return $("<LI>") /*manufacturer_name price*/ .append($("<A>") .append($("<SPAN>").html(product.image).addClass("image")) .append($("<SPAN>").html(product.category_name).addClass("category")) .append($("<SPAN>").html(product.manufacturer_name)) .append($("<SPAN>").html(' > ').addClass("separator")) .append($("<SPAN>").html(product.name).addClass("product")) .append($("<SPAN>").html(' - ')) .append($("<SPAN>").html(product.reference)) .append($("<SPAN>").html(' (')) .append($("<SPAN>").html(product.price)) .append($("<SPAN>").html(')')) ).appendTo(ul) ; } }); $searchBox.psBlockSearchAutocomplete({ source: function (query, response) { $.post(searchURL, { s: query.term, resultsPerPage: 10 }, null, 'json') .then(function (resp) { response(resp.products); }) .fail(response); }, select: function (event, ui) { var url = ui.item.url; window.location.href = url; }, }); }); I cant find how to add image to the $product object, any help? Link to comment Share on other sites More sharing options...
DARKF3D3 Posted July 17, 2018 Share Posted July 17, 2018 Hello, did you find a solution? Link to comment Share on other sites More sharing options...
Tunçer Damat Posted September 6, 2018 Share Posted September 6, 2018 Hi, I have encountered a similar issue before. Have you tried adding 'category_name' as a value to $allowed_properties array in prepareProductArrayForAjaxReturn method of the ProductListFrontController? /** * Cleans the products array with only whitelisted properties. * * @return array */ protected function prepareProductArrayForAjaxReturn(array $products) { $allowed_properties = array('id_product', 'price', 'reference', 'active', 'description', 'category_name', 'description_short', 'link', 'link_rewrite', 'name', 'manufacturer_name', 'position', 'url', 'canonical_url', 'add_to_cart_url', 'has_discount', 'discount_type', 'discount_percentage', 'discount_percentage_absolute', 'discount_amount', 'price_amount', 'regular_price_amount', 'regular_price', 'discount_to_display', 'labels', 'main_variants', 'unit_price', 'tax_name', 'rate' ); Link to comment Share on other sites More sharing options...
blondel.da Posted September 8, 2018 Share Posted September 8, 2018 https://www.prestashop.com/forums/topic/511807-add-images-in-search-bar/?do=findComment&comment=2967036 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now