fix: add new routes to handle category wise search

This commit is contained in:
Mangesh-Khairnar 2019-11-28 18:57:42 +05:30
parent 647331bbd7
commit 2597817cde
4 changed files with 14 additions and 7 deletions

View File

@ -24,7 +24,7 @@ import NotFound from './pages/NotFound.vue';
function get_route_map() { function get_route_map() {
const read_only_routes = { const read_only_routes = {
'marketplace/home': Home, 'marketplace/home': Home,
'marketplace/search/:keyword': Search, 'marketplace/search/:category/:keyword': Search,
'marketplace/category/:category': Category, 'marketplace/category/:category': Category,
'marketplace/item/:item': Item, 'marketplace/item/:item': Item,
'marketplace/seller/:seller': Seller, 'marketplace/seller/:seller': Seller,

View File

@ -67,7 +67,7 @@ export default {
}, },
set_search_route() { set_search_route() {
frappe.set_route('marketplace', 'search', this.search_value); frappe.set_route('marketplace', 'search', this.category, this.search_value);
}, },
} }
} }

View File

@ -98,7 +98,7 @@ export default {
}, },
set_search_route() { set_search_route() {
frappe.set_route('marketplace', 'search', this.search_value); frappe.set_route('marketplace', 'search', 'All', this.search_value);
}, },
} }
} }

View File

@ -29,8 +29,10 @@ export default {
return { return {
page_name: frappe.get_route()[1], page_name: frappe.get_route()[1],
items: [], items: [],
search_value: frappe.get_route()[2], category: frappe.get_route()[2],
search_value: frappe.get_route()[3],
item_id_fieldname: 'name', item_id_fieldname: 'name',
filters: {},
// Constants // Constants
search_placeholder: __('Search for anything ...'), search_placeholder: __('Search for anything ...'),
@ -40,7 +42,7 @@ export default {
computed: { computed: {
page_title() { page_title() {
return this.items.length return this.items.length
? __(`Results for "${this.search_value}"`) ? __(`Results for <strong>${this.search_value}<strong> in category ${this.category}`)
: __('No Items found.'); : __('No Items found.');
} }
}, },
@ -49,14 +51,19 @@ export default {
}, },
methods: { methods: {
get_items() { get_items() {
hub.call('get_items', { keyword: this.search_value }) if (this.category !== 'All') {
this.filters['hub_category']=this.category;
}
hub.call('get_items', { keyword: this.search_value,
filters: this.filters
})
.then((items) => { .then((items) => {
this.items = items; this.items = items;
}) })
}, },
set_route_and_get_items() { set_route_and_get_items() {
frappe.set_route('marketplace', 'search', this.search_value); frappe.set_route('marketplace', 'search', this.category, this.search_value);
this.get_items(); this.get_items();
}, },