-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exclude search fields #3
Comments
How do you see that all fields are used as soon as you start typing something? |
I'll provide an example screenshot tomorrow. But when I searched for
|
Here is the promised screenshot. Please note that I've disabled localStorage in the settings, but that shouldn't make any difference. As you can see I simply searched for the term <script type="text/javascript">
//<![CDATA[
// Bypass default autocomplete
Ajax.Autocompleter.prototype.getUpdatedChoices = function() {
return false;
};
jQuery('#search').removeClass('required-entry');
// init some useful variables
var priceFormat = {"pattern":"%s\u00a0\u20ac","precision":2,"requiredPrecision":2,"decimalSymbol":",","groupSymbol":".","groupLength":3,"integerRequired":1};
var baseUrl = 'http://mage1910.localhost/';
var baseUrlMedia = 'http://mage1910.localhost/media/catalog/product';
var imgPlaceholder = 'http://mage1910.localhost/media/catalog/product/cache/1/small_image/100x100/9df78eab33525d08d6e5fb8d27136e95/images/catalog/product/placeholder/small_image.jpg';
// constructs the suggestion engine
var engine = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: { url: 'http://mage1910.localhost/autocomplete/product/json/' },
limit: 5,
ttl: 86400000 // milliseconds
});
// kicks off the loading/processing of `local` and `prefetch`
engine.initialize();
jQuery('#search').typeahead({
hint: true,
highlight: true,
minLength: 1}, {
name: 'products',
displayKey: 'name',
// `ttAdapter` wraps the suggestion engine in an adapter that
// is compatible with the typeahead jQuery plugin
source: engine.ttAdapter(),
templates: {
empty: '<div class="empty">' +
'No Result' +
'</div>',
suggestion: function(product) {
var img = imgPlaceholder;
if (product.thumbnail && product.thumbnail != 'no_selection') {
img = baseUrlMedia + product.thumbnail;
}
return '<a href="' + baseUrl + product.url_path + '">' +
'<div class="image">' +
'<img src="' + img + '">' +
'</div>' +
'<div class="info">' +
'<span class="name">' + product.name + '</span>' +
'<div class="price-box">' + formatSuggestionPrice(product, priceFormat) + '</div>' +
'</div>' +
'<div class="clearer"><!-- --></div>' +
'</a>';
}
}
});
jQuery('#search').bind('typeahead:selected', function(obj, product, name) {
window.location.href = baseUrl + product.url_path;
});
function formatSuggestionPrice(product, priceFormat) {
var price = '';
switch (product.type_id) {
case 'grouped':
case 'configurable':
case 'bundle':
price = '<p class="minimal-price">' +
'<span class="price-label">Ab: </span>' +
'<span class="price">' + formatCurrency(product.min_price, priceFormat, false) + '</span>' +
'</p>';
break;
default:
price = '<span class="price">' +
formatCurrency(product.price, priceFormat, false) +
'</span>';
}
return price;
}
//]]>
</script> |
Hello guys, realy nice and useful extension. |
@riker09 Is this report still valid? I cannot confirm this on a fresh installation. Bloodhound.tokenizers works as expected.. @awwea This extension expects prices incl. taxes in magento from what I can see. Adding code for reading tax information for each product and add it to the collection seems to be a lot of work. |
@riker09 Think I found the bug during my tests related to #2. @jreinke is using Bloodhound a bit wrong. Prefetch & Remote serve a different purpose. If remote is triggered, the result set is actually treated as a real 'result set' - so everything coming from the url remote is a result. I am trying to implement a correct ajax request handling now which prefetches the most current or best selling products as initial json and the real search requests on demand by fetching from db. This should solve this. |
Fixed in preview fork winkelsdorf@f6b4df8 |
I noticed that when I start to type, every field returned by
autocomplete/product/json/
is used for autocompletion. So a search formin_price
orsimple
results in some matches simply because these field names / values are present in the json string. Although these fields and values may be required for a (harder) better, faster (stronger) display of the results they shouldn't be used for matching.The text was updated successfully, but these errors were encountered: