diff --git a/assets/less/style.less b/assets/less/style.less index 927a2b18..cdaa4b12 100644 --- a/assets/less/style.less +++ b/assets/less/style.less @@ -901,6 +901,22 @@ div:focus, span:focus, button:focus, input:focus { } } +.refresh-products-tooltip-wrapper { + .tooltip-inner { + padding: 5px 10px !important; + background-color: rgba(0, 0, 0, .6) !important; + + .refresh-products-tooltip-text { + color: #fff; + font-size: 13px !important; + } + } + + .tooltip-arrow { + border-color: rgba(0, 0, 0, .6) !important; + } +} + .wepos-multiselect { min-height: 35px !important; font-size: 13px !important; diff --git a/assets/src/frontend/components/CustomerSearch.vue b/assets/src/frontend/components/CustomerSearch.vue index 60b7241e..0bbcf7cc 100644 --- a/assets/src/frontend/components/CustomerSearch.vue +++ b/assets/src/frontend/components/CustomerSearch.vue @@ -24,7 +24,7 @@ - +
@@ -181,7 +181,7 @@ export default { phone: '', }, showCustomerResults: false, - serachInput: '', + searchInput: '', showNewCustomerModal: false, stateList: [], selectedState: null, @@ -226,7 +226,7 @@ export default { }, 'orderdata.customer_id'(newVal) { - this.serachInput = newVal ? this.orderdata.billing.first_name + ' ' + this.orderdata.billing.last_name : ''; + this.searchInput = newVal ? this.orderdata.billing.first_name + ' ' + this.orderdata.billing.last_name : ''; } }, @@ -238,7 +238,7 @@ export default { }, searchClose() { this.showCustomerResults = false; - this.serachInput = ''; + this.searchInput = ''; this.showNewCustomerModal= false; this.$refs.customerSearch.blur(); }, @@ -278,8 +278,8 @@ export default { this.showNewCustomerModal = false; }, searchCustomer() { - if ( this.serachInput ) { - wepos.api.get( wepos.rest.root + wepos.rest.posversion + '/customers?search=' + this.serachInput ) + if ( this.searchInput ) { + wepos.api.get( wepos.rest.root + wepos.rest.posversion + '/customers?search=' + this.searchInput ) .done(response => { this.customers = response; }); @@ -289,7 +289,7 @@ export default { }, selectCustomer( customer ) { this.$emit( 'onCustomerSelected', customer ); - this.serachInput = customer.first_name + ' ' + customer.last_name; + this.searchInput = customer.first_name + ' ' + customer.last_name; this.showCustomerResults = false; }, createCustomer() { @@ -318,7 +318,7 @@ export default { wepos.api.post( wepos.rest.root + wepos.rest.posversion + '/customers', customerData ) .done(response => { - this.serachInput = response.first_name + ' ' + response.last_name; + this.searchInput = response.first_name + ' ' + response.last_name; this.$emit( 'onCustomerSelected', response ); $contentWrap.unblock(); this.closeNewCustomerModal(); @@ -369,13 +369,13 @@ export default { }, created() { this.eventBus.$on( 'emptycart', ( orderdata ) => { - this.serachInput = ''; + this.searchInput = ''; } ); var orderdata = JSON.parse( localStorage.getItem( 'orderdata' ) ); if ( orderdata.customer_id != 'undefined' && orderdata.customer_id != 0 ) { - this.serachInput = orderdata.billing.first_name + ' ' + orderdata.billing.last_name; + this.searchInput = orderdata.billing.first_name + ' ' + orderdata.billing.last_name; } } }; diff --git a/assets/src/frontend/components/Home.vue b/assets/src/frontend/components/Home.vue index ac95dfea..d69245e5 100644 --- a/assets/src/frontend/components/Home.vue +++ b/assets/src/frontend/components/Home.vue @@ -34,7 +34,16 @@
- +
+ + + + + + +
@@ -639,6 +648,7 @@ export default { filteredProducts: [], totalPages: 1, page: 1, + productLogsLoading: false, showOverlay: false, selectedVariationProduct: {}, attributeDisabled: true, @@ -729,6 +739,9 @@ export default { } } return []; + }, + productsStorageUpdatedOn() { + return localStorage.getItem( 'productsStorageUpdatedOn' ); } }, @@ -1021,7 +1034,7 @@ export default { } if ( ( this.totalPages >= this.page ) ) { - wepos.api.get( wepos.rest.root + wepos.rest.posversion + '/products?status=publish&per_page=30&page=' + this.page ) + wepos.api.get( wepos.rest.root + wepos.rest.posversion + '/products?status=publish&per_page=50&page=' + this.page ) .done( ( response, status, xhr ) => { this.appendProducts( response ); this.page += 1; @@ -1030,9 +1043,54 @@ export default { }).then( ( response, status, xhr ) => { this.fetchProducts(); }); - } else { - this.productLoading = false; + } else if ( this.isProductsStorageUpdateRequired() ) { + // Remove existing products from the IndexedDB storage. + wepos.productIndexedDb.deleteAllProducts(); + + // Insert products to the IndexedDB storage. + wepos.productIndexedDb.insertProducts( this.products ); + + // Store products IndexedDB updating time to Local Storage. + localStorage.setItem( 'productsStorageUpdatedOn', dayjs().unix() ); } + + this.productLoading = false; + }, + isProductsStorageUpdateRequired() { + if ( ! this.productsStorageUpdatedOn || this.productsStorageUpdatedOn < dayjs().subtract( 7, 'days' ).unix() ) { + return true; + } + + return false; + }, + refreshProducts() { + this.fetchProductLogs( wepos.current_cashier.counter_id ); + }, + fetchProductLogs( counterId ) { + let fetchingToast = { + title: this.__( 'Products already updated!', 'wepos' ), + type: 'info' + } + + this.productLogsLoading = true; + + wepos.api.get( wepos.rest.root + wepos.rest.posversion + '/product/logs/' + counterId ) + .done( ( response, status, xhr ) => { + if ( response.length > 0 ) { + wepos.productLogs.updateProductsToIndexedDb( response ); + wepos.productLogs.updateProductLogsData( counterId ); + + fetchingToast.title = this.__( 'Products refreshed successfully!', 'wepos' ); + fetchingToast.type = 'success'; + } + } ).fail( ( response, status, xhr ) => { + fetchingToast.title = this.__( 'Failed to refresh products!', 'wepos' ); + fetchingToast.type = 'error'; + } ).then( ( response, status, xhr ) => { + this.productLogsLoading = false; + + this.toast( fetchingToast ); + } ); }, appendProducts( products ) { products.forEach( product => { @@ -1245,6 +1303,15 @@ export default { }, }, + async beforeCreate() { + const dbName = 'ProductsDB'; + const isExistsProductsDB = ( await window.indexedDB.databases() ).map( db => db.name ).includes( dbName ); + + if ( ! isExistsProductsDB ) { + wepos.productIndexedDb.createProductsDB(); + } + }, + async created() { this.fetchSettings(); this.fetchTaxes(); @@ -1279,6 +1346,15 @@ export default {