diff --git a/modules/order/back/methods/order/catalogFilter.js b/modules/order/back/methods/order/catalogFilter.js
index e96d24cfc..64ee73d1c 100644
--- a/modules/order/back/methods/order/catalogFilter.js
+++ b/modules/order/back/methods/order/catalogFilter.js
@@ -23,7 +23,7 @@ module.exports = Self => {
},
{
arg: 'tagGroups',
- type: [['Object']],
+ type: ['Object'],
description: 'Filter by tag'
},
],
@@ -55,45 +55,30 @@ module.exports = Self => {
JOIN vn.itemType it ON it.id = i.typeFk
JOIN vn.itemCategory ic ON ic.id = it.categoryFk`);
- console.log(tagGroups);
// Filter by tag
if (tagGroups) {
- /* for (const [group, i] of tagGroups.entries()) {
- for (const tag of group)
- console.log(tag);
- }
- */
- /* for (const tag of tags) {
- const tAlias = `it${i++}`;
+ for (const [i, tagGroup] of tagGroups.entries()) {
+ const values = tagGroup.values;
+ const tAlias = `it${i}`;
- if (tag.tagFk) {
- stmt.merge({
- sql: `JOIN vn.itemTag ${tAlias} ON ${tAlias}.itemFk = i.id
- AND ${tAlias}.tagFk = ?
- AND ${tAlias}.value LIKE ?`,
- params: [tag.tagFk, `%${tag.value}%`],
- });
- // Convertir:
- JOIN vn.itemTag it1 ON it1.itemFk = i.id
- AND (
- (it1.tagFk = ? AND it1.value LIKE ?)
- OR (it1.tagFk = ? AND it1.value LIKE ?)
- OR (it1.tagFk = ? AND it1.value LIKE ?)
- )
- JOIN vn.itemTag it2 ON it2.itemFk = i.id
- AND (
- (it2.tagFk = ? AND it2.value LIKE ?)
- OR (it2.tagFk = ? AND it2.value LIKE ?)
- OR (it2.tagFk = ? AND it2.value LIKE ?)
- )
+ if (tagGroup.tagFk) {
+ stmt.merge(`JOIN vn.itemTag ${tAlias} ON ${tAlias}.itemFk = i.id AND (`);
+ for (const [i, tagValue] of values.entries()) {
+ stmt.merge({
+ sql: `${i > 0 ? 'OR' : ''} (${tAlias}.tagFk = ? AND ${tAlias}.value LIKE ?)`,
+ params: [tagGroup.tagFk, `%${tagValue.value}%`],
+ });
+ }
+ stmt.merge(`)`);
} else {
+ const tagValue = values[0];
stmt.merge({
sql: `JOIN vn.itemTag ${tAlias} ON ${tAlias}.itemFk = i.id
AND ${tAlias}.value LIKE ?`,
- params: [`%${tag.value}%`],
+ params: [`%${tagValue.value}%`],
});
}
- } */
+ }
}
stmt.merge(conn.makeWhere(filter.where));
diff --git a/modules/order/front/catalog-search-panel/index.html b/modules/order/front/catalog-search-panel/index.html
index 54fcefb3c..822445a18 100644
--- a/modules/order/front/catalog-search-panel/index.html
+++ b/modules/order/front/catalog-search-panel/index.html
@@ -1,64 +1,37 @@