-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1581 from qiqqq/feature/offline-orders-confirmation
Issue #1430 Offline orders confirmation
- Loading branch information
Showing
21 changed files
with
641 additions
and
312 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Functionality for cancelling orders placed offline | ||
* | ||
* #### Methods | ||
* - **`cancelOrder()`** removes not transmitted orders from Local Storage | ||
* | ||
* Part of [Offline order API Module](https://github.com/DivanteLtd/vue-storefront/tree/master/doc/api-modules) | ||
*/ | ||
import * as localForage from 'localforage' | ||
import config from 'config' | ||
|
||
import EventBus from '@vue-storefront/core/plugins/event-bus' | ||
import UniversalStorage from '@vue-storefront/store/lib/storage' | ||
import { currentStoreView } from '@vue-storefront/store/lib/multistore' | ||
|
||
export const cancelOrder = { | ||
methods: { | ||
cancelOrder () { | ||
const storeView = currentStoreView() | ||
const dbNamePrefix = storeView.storeCode ? storeView.storeCode + '-' : '' | ||
|
||
const ordersCollection = new UniversalStorage(localForage.createInstance({ | ||
name: dbNamePrefix + 'shop', | ||
storeName: 'orders', | ||
driver: localForage[config.localForage.defaultDrivers['orders']] | ||
})) | ||
|
||
ordersCollection.iterate((order, id, iterationNumber) => { | ||
if (!order.transmited) { | ||
ordersCollection.removeItem(id) | ||
} | ||
}).catch(err => { | ||
console.log(err) | ||
console.log('Not transmitted orders was deleted') | ||
}) | ||
|
||
EventBus.$emit('modal-hide', 'modal-order-confirmation') | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Functionality for confirming orders placed offline | ||
* | ||
* #### Methods | ||
* - **`confirmOrder()`** emits event to send orders placed offline to server | ||
* | ||
* Part of [Offline order API Module](https://github.com/DivanteLtd/vue-storefront/tree/master/doc/api-modules) | ||
*/ | ||
import EventBus from '@vue-storefront/core/plugins/event-bus' | ||
import config from 'config' | ||
|
||
export const confirmOrder = { | ||
methods: { | ||
confirmOrder () { | ||
EventBus.$emit('order/PROCESS_QUEUE', { config: config }) | ||
EventBus.$emit('sync/PROCESS_QUEUE', { config: config }) | ||
this.$store.dispatch('cart/load') | ||
EventBus.$emit('modal-hide', 'modal-order-confirmation') | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as localForage from 'localforage' | ||
import config from 'config' | ||
|
||
import EventBus from '@vue-storefront/core/plugins/event-bus' | ||
|
||
import UniversalStorage from '@vue-storefront/store/lib/storage' | ||
import { currentStoreView } from '@vue-storefront/store/lib/multistore' | ||
|
||
export function onNetworkStatusChange (store) { | ||
console.log('Are we online: ' + navigator.onLine) | ||
|
||
if (typeof navigator !== 'undefined' && navigator.onLine) { | ||
if (config.orders.offline_orders.automatic_transmission_enabled || store.getters['checkout/isThankYouPage']) { | ||
EventBus.$emit('order/PROCESS_QUEUE', { config: config }) // process checkout queue | ||
EventBus.$emit('sync/PROCESS_QUEUE', { config: config }) // process checkout queue | ||
// store.dispatch('cart/serverPull', { forceClientState: false }) | ||
store.dispatch('cart/load') | ||
} else { | ||
const ordersToConfirm = [] | ||
const storeView = currentStoreView() | ||
const dbNamePrefix = storeView.storeCode ? storeView.storeCode + '-' : '' | ||
|
||
const ordersCollection = new UniversalStorage(localForage.createInstance({ | ||
name: dbNamePrefix + 'shop', | ||
storeName: 'orders', | ||
driver: localForage[config.localForage.defaultDrivers['orders']] | ||
})) | ||
|
||
ordersCollection.iterate((order, id, iterationNumber) => { | ||
if (!order.transmited) { | ||
ordersToConfirm.push(order) | ||
} | ||
}).catch(err => { | ||
console.log(err) | ||
}) | ||
|
||
if (ordersToConfirm.length > 0) { | ||
EventBus.$emit('offline-order-confirmation', ordersToConfirm) | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { confirmOrder } from './confirmOrder' | ||
import { cancelOrder } from './cancelOrder' | ||
|
||
export { | ||
confirmOrder, | ||
cancelOrder | ||
} |
Oops, something went wrong.