Created
December 5, 2017 23:00
-
-
Save blaggacao/f180ea5db4f20e563973f6e372eab67e to your computer and use it in GitHub Desktop.
pos_variant limit problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get_product_by_category: function(category_id){ | |
var product_ids = this.product_by_category_id[category_id]; | |
var list = []; | |
var tmpl_list = []; | |
if (product_ids) { | |
for (var i = 0, len = Math.min(product_ids.length, this.limit); i < len; i++) { | |
var product = this.product_by_id[product_ids[i]]; | |
if (!tmpl_list.includes(product.product_tmpl_id)) { | |
list.push(product); | |
tmpl_list.push(product.product_tmpl_id); | |
} else { | |
len++ | |
len = Math.min(product_ids.length, len); | |
} | |
} | |
} | |
return list; | |
}, | |
search_product_in_category: function(category_id, query){ | |
try { | |
query = query.replace(/[\[\]\(\)\+\*\?\.\-\!\&\^\$\|\~\_\{\}\:\,\\\/]/g,'.'); | |
query = query.replace(/ /g,'.+'); | |
var re = RegExp("([0-9]+):.*?"+query,"gi"); | |
}catch(e){ | |
return []; | |
} | |
var results = []; | |
var tmpl_list = []; | |
for(var i = 0, len = this.limit; i < len; i++){ | |
var r = re.exec(this.category_search_string[category_id]); | |
if(r){ | |
var id = Number(r[1]); | |
var product = this.get_product_by_id(id); | |
if (!tmpl_list.includes(product.product_tmpl_id)) { | |
results.push(product); | |
tmpl_list.push(product.product_tmpl_id); | |
} else { | |
len++; | |
} | |
}else{ | |
break; | |
} | |
} | |
return results; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment