Skip to content
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

Hofix: Improved offline mode handlers #2217

Merged
merged 1 commit into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions core/pages/Category.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Vue from 'vue'
import toString from 'lodash-es/toString'

import i18n from '@vue-storefront/i18n'
import store from '@vue-storefront/store'
import EventBus from '@vue-storefront/core/compatibility/plugins/event-bus'
import { baseFilterProductsQuery, buildFilterProductsQuery } from '@vue-storefront/core/helpers'
Expand Down Expand Up @@ -242,6 +243,15 @@ export default {
this.$store.dispatch('category/products', this.$store.state.category.current_product_query)
EventBus.$emitFilter('category-after-load', { store: this.$store, route: this.$route })
}
}).catch(err => {
if (err.message.indexOf('query returned empty result') > 0) {
this.$store.dispatch('notification/spawnNotification', {
type: 'error',
message: i18n.t('The product, category or CMS page is not available in Offline mode. Redirecting to Home.'),
action1: { label: i18n.t('OK') }
})
this.$router.push(localizedRoute('/', currentStoreView().storeCode))
}
})
},
onUserPricesRefreshed () {
Expand Down
30 changes: 14 additions & 16 deletions core/store/lib/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,6 @@ export const quickSearchByQuery = async ({ query, start = 0, size = 50, entityT
resolve(res)
console.debug('Result from cache for ' + cacheKey + ' (' + entityType + '), ms=' + (new Date().getTime() - benchmarkTime.getTime()))
servedFromCache = true
} else {
if (!isOnline()) {
console.debug('No results and offline ' + cacheKey + ' (' + entityType + '), ms=' + (new Date().getTime() - benchmarkTime.getTime()))
res = {
items: [],
total: 0,
start: 0,
perPage: 0,
aggregations: {},
offline: true,
cache: true,
noresults: true
}
servedFromCache = true
resolve(res)
}
}
}).catch((err) => {
console.error('Cannot read cache for ' + cacheKey + ', ' + err)
Expand Down Expand Up @@ -109,6 +93,20 @@ export const quickSearchByQuery = async ({ query, start = 0, size = 50, entityT
}
}
}).catch(err => {
if (!servedFromCache) {
console.debug('No results and offline ' + cacheKey + ' (' + entityType + '), ms=' + (new Date().getTime() - benchmarkTime.getTime()))
const res = {
items: [],
total: 0,
start: 0,
perPage: 0,
aggregations: {},
offline: true,
cache: true,
noresults: true
}
resolve(res)
}
reject(err)
})
})
Expand Down