Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
filrak committed Dec 20, 2017
2 parents e80c10a + ff03ba4 commit b762faf
Show file tree
Hide file tree
Showing 21 changed files with 210 additions and 164 deletions.
18 changes: 11 additions & 7 deletions installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ class Backend extends Abstract {
if (shell.exec(`docker-compose up -d > /dev/null 2>&1`).code !== 0) {
reject('Can\'t start docker in background.')
}

resolve()
// Adding 20sec timer for ES to get up and running
// before starting restoration and migration processes
setTimeout(() => { resolve() }, 20000)
})
}

Expand Down Expand Up @@ -336,13 +337,16 @@ class Storefront extends Abstract {
let backendPath

if (Abstract.wasLocalBackendInstalled) {
backendPath = 'localhost:8080'
backendPath = 'http://localhost:8080'
} else {
backendPath = STOREFRONT_REMOTE_BACKEND_URL
}

config.elasticsearch.host = `${backendPath}/api/catalog`
config.orders.endpoint = `${backendPath}/api/order/create`
config.orders.endpoint = `${backendPath}/api/order`
config.users.endpoint = `${backendPath}/api/user`
config.stock.endpoint = `${backendPath}/api/stock`
config.mailchimp.endpoint = `${backendPath}/api/ext/mailchimp-subscribe/subscribe`
config.images.baseUrl = this.answers.images_endpoint

config.install = {
Expand Down Expand Up @@ -456,8 +460,8 @@ class Manager extends Abstract {
return this.backend.cloneRepository()
.then(this.backend.goToDirectory.bind(this.backend))
.then(this.backend.npmInstall.bind(this.backend))
.then(this.backend.dockerComposeUp.bind(this.backend))
.then(this.backend.createConfig.bind(this.backend))
.then(this.backend.dockerComposeUp.bind(this.backend))
.then(this.backend.restoreElasticSearch.bind(this.backend))
.then(this.backend.migrateElasticSearch.bind(this.backend))
.then(this.backend.cloneMagentoSampleData.bind(this.backend))
Expand Down Expand Up @@ -543,8 +547,8 @@ let questions = [
{
type: 'input',
name: 'git_path',
message: 'Please provide Git path',
default: '/usr/bin/git',
message: 'Please provide Git path (if it\'s not globally installed)',
default: 'git',
when: function (answers) {
return answers.is_remote_backend === false
},
Expand Down
24 changes: 23 additions & 1 deletion src/client-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ EventBus.$on('order/PROCESS_QUEUE', event => {
})

// Process the background tasks
const mutex = {}
EventBus.$on('sync/PROCESS_QUEUE', data => {
console.log('Executing task queue')
// event.data.config - configuration, endpoints etc
Expand All @@ -136,7 +137,8 @@ EventBus.$on('sync/PROCESS_QUEUE', data => {
const fetchQueue = []
console.log('Current token = ' + currentToken)
syncTaskCollection.iterate((task, id, iterationNumber) => {
if (!task.transmited) { // not sent to the server yet
if (!task.transmited && !mutex[id]) { // not sent to the server yet
mutex[id] = true // mark this task as being processed
fetchQueue.push(() => {
const taskData = task
const taskId = id
Expand All @@ -149,9 +151,11 @@ EventBus.$on('sync/PROCESS_QUEUE', data => {
return response.json()
} else {
console.error('Error with response - bad content-type!')
mutex[id] = false
}
} else {
console.error('Bad response status: ' + response.status)
mutex[id] = false
}
}).then((jsonResponse) => {
if (jsonResponse) {
Expand All @@ -168,6 +172,7 @@ EventBus.$on('sync/PROCESS_QUEUE', data => {
}
} else {
console.error('Unhandled error, wrong response format!')
mutex[id] = false
}
})
})
Expand All @@ -186,3 +191,20 @@ EventBus.$on('sync/PROCESS_QUEUE', data => {

EventBus.$emit('order/PROCESS_QUEUE', { config: config }) // process checkout queue
EventBus.$emit('sync/PROCESS_QUEUE', { config: config }) // process checkout queue

/**
* Process order queue when we're back onlin
*/
function checkiIsOnline () {
EventBus.$emit('network.status', { online: navigator.onLine })
console.log('Are we online: ' + navigator.onLine)

if (navigator.onLine) {
EventBus.$emit('order/PROCESS_QUEUE', { config: config }) // process checkout queue
EventBus.$emit('sync/PROCESS_QUEUE', { config: config }) // process checkout queue
}
}

window.addEventListener('online', checkiIsOnline)
window.addEventListener('offline', checkiIsOnline)

10 changes: 5 additions & 5 deletions src/components/core/Loader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@ import { mapState } from 'vuex'
export default {
name: 'loader',
data: function () {
data () {
return {
message: null
}
},
computed: mapState({
isVisible: state => state.ui.loader
}),
methods: {
show (message = null) {
this.message = message
Expand All @@ -42,7 +39,10 @@ export default {
this.$store.commit('ui/setLoader', false)
}
},
mounted: function () {
computed: mapState({
isVisible: state => state.ui.loader
}),
mounted () {
this.$bus.$on('notification-progress-start', (message) => {
this.show(message)
})
Expand Down
7 changes: 0 additions & 7 deletions src/components/core/NewsletterPopup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@
</div>
</template>
<script>
import { mapState } from 'vuex'
export default {
name: 'newsletter-popup',
computed: {
...mapState({
isOpen: state => state.ui.newsletterPopup
})
},
methods: {
closeNewsletter () {
this.$store.commit('ui/setNewsletterPopup', false)
Expand Down
7 changes: 1 addition & 6 deletions src/components/core/Overlay.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
<template>
<div class="overlay" @click="onClick" v-if="isVisible">
<div class="overlay" @click="onClick">
</div>
</template>

<script>
import { mapState } from 'vuex'
export default {
name: 'overlay',
computed: mapState({
isVisible: state => state.ui.overlay
}),
methods: {
onClick () {
this.$store.commit('ui/setOverlay', false)
Expand Down
7 changes: 0 additions & 7 deletions src/components/core/blocks/Auth/SignUp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,13 @@ import Login from './Login.vue'
import Register from './Register.vue'
import ForgotPass from './ForgotPass.vue'
import { mapState } from 'vuex'
export default {
name: 'sign-up',
components: {
Login,
Register,
ForgotPass
},
computed: {
...mapState({
isOpen: state => state.ui.signUp
})
},
methods: {
closeSignUp () {
this.$store.commit('ui/setSignUp', false)
Expand Down
3 changes: 2 additions & 1 deletion src/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"demomode": true,
"tax": {
"defaultCountry": "PL",
"defaultRegion": ""
"defaultRegion": "",
"calculateServerSide": false
},
"i18n": {
"defaultCountry": "US",
Expand Down
5 changes: 3 additions & 2 deletions src/extensions/mailchimp-subscribe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ const EXTENSION_KEY = 'mailchimp-subscribe'

import extensionStore from './store'
import extensionRoutes from './router'
import EventBus from 'src/event-bus'

export default function (app, router, store, config) {
router.addRoutes(extensionRoutes) // add custom routes
store.registerModule(EXTENSION_KEY, extensionStore) // add custom store

app.$on('newsletter-after-subscribe', (payload) => {
console.log('Mailchimp extension registered')
EventBus.$on('newsletter-after-subscribe', (payload) => {
store.dispatch('sync/queue', { url: config.mailchimp.endpoint,
payload: {
method: 'POST',
Expand Down
11 changes: 10 additions & 1 deletion src/lib/entities.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
export function guid () {
function s4 () {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1)
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4()
}
/**
* Return unique entity.id
* @param {Object} entity
*/
export function uniqueEntityId (entity) {
return new Date().getTime()
return new Date().getTime() + '-' + guid()
}

/**
Expand Down
85 changes: 85 additions & 0 deletions src/lib/taxcalc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
export function calculateProductTax (product, taxClasses, taxCountry = 'PL', taxRegion = '') {
let rateFound = false
let taxClass = taxClasses.find((el) => el.product_tax_class_ids.indexOf(parseInt(product.tax_class_id) >= 0))
if (taxClass) {
for (let rate of taxClass.rates) { // TODO: add check for zip code ranges (!)
if (rate.tax_country_id === taxCountry && (rate.region_name === taxRegion || rate.tax_region_id === 0 || !rate.region_name)) {
product.price = parseFloat(product.price)
product.priceInclTax = (product.price + product.price * (parseFloat(rate.rate) / 100))
product.priceTax = (product.price * (parseFloat(rate.rate) / 100))

product.special_price = parseFloat(product.special_price)
product.specialPriceInclTax = (parseFloat(product.special_price) + parseFloat(product.special_price) * (parseFloat(rate.rate) / 100))
product.specialPriceTax = (parseFloat(product.special_price) * (parseFloat(rate.rate) / 100))

if (product.special_price && (product.special_price < product.price)) {
product.originalPrice = product.price
product.originalPriceInclTax = product.priceInclTax
product.originalPriceTax = product.priceTax

product.price = parseFloat(product.special_price)
product.priceInclTax = product.specialPriceInclTax
product.priceTax = product.specialPriceTax
} else {
product.special_price = 0 // the same price as original; it's not a promotion
}

if (product.configurable_children) {
for (let configurableChild of product.configurable_children) {
for (let opt of configurableChild.custom_attributes) {
configurableChild[opt.attribute_code] = opt.value
}
configurableChild.price = parseFloat(configurableChild.price)
configurableChild.priceInclTax = (configurableChild.price + configurableChild.price * (parseFloat(rate.rate) / 100))
configurableChild.priceTax = (configurableChild.price * (parseFloat(rate.rate) / 100))

configurableChild.specialPriceInclTax = (parseFloat(configurableChild.special_price) + parseFloat(configurableChild.special_price) * (parseFloat(rate.rate) / 100))
configurableChild.specialPriceTax = (parseFloat(configurableChild.special_price) * (parseFloat(rate.rate) / 100))

if (configurableChild.special_price && (configurableChild.special_price < configurableChild.price)) {
configurableChild.originalPrice = parseFloat(configurableChild.price)
configurableChild.originalPriceInclTax = configurableChild.priceInclTax
configurableChild.originalPriceTax = configurableChild.priceTax

configurableChild.price = parseFloat(configurableChild.special_price)
configurableChild.priceInclTax = configurableChild.specialPriceInclTax
configurableChild.priceTax = configurableChild.specialPriceTax
} else {
configurableChild.special_price = 0
}

if (configurableChild.priceInclTax < product.priceInclTax || product.price === 0) { // always show the lowest price
product.priceInclTax = parseFloat(configurableChild.priceInclTax)
product.priceTax = parseFloat(configurableChild.priceTax)
product.price = parseFloat(configurableChild.price)
product.special_price = parseFloat(configurableChild.special_price)
product.specialPriceInclTax = configurableChild.specialPriceInclTax
product.specialPriceTax = configurableChild.specialPriceTax
product.originalPrice = configurableChild.originalPrice
product.originalPriceInclTax = configurableChild.originalPriceInclTax
product.originalPriceTax = configurableChild.originalPriceTax
}
}
}
rateFound = true
console.debug('Tax rate ' + rate.code + ' = ' + rate.rate + '% found for ' + taxCountry + ' / ' + taxRegion)
break
}
}
}
if (!rateFound) {
console.log('No such tax class id: ' + product.tax_class_id + ' or rate not found for ' + taxCountry + ' / ' + taxRegion)
product.priceInclTax = product.price
product.priceTax = 0
product.specialPriceInclTax = 0
product.specialPriceTax = 0
if (product.configurable_children) {
for (let configurableChildren of product.configurable_children) {
configurableChildren.priceInclTax = configurableChildren.price
configurableChildren.priceTax = 0
configurableChildren.specialPriceInclTax = 0
configurableChildren.specialPriceTax = 0
}
}
}
}
23 changes: 0 additions & 23 deletions src/service-worker-registration.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import config from './config.json'
import * as types from './store/mutation-types'
import EventBus from 'src/event-bus'

if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js', { scope: '/' }).then(function () {
if (navigator.serviceWorker.controller) {
Expand All @@ -11,22 +7,3 @@ if ('serviceWorker' in navigator) {
}
})
}

/**
* Process order queue when we're back onlin
*/
function checkiIsOnline () {
EventBus.$emit('network.status', { online: navigator.onLine })
console.log('Are we online: ' + navigator.onLine)

if (navigator.onLine) {
if ('serviceWorker' in navigator && navigator.serviceWorker.controller) {
navigator.serviceWorker.controller.postMessage({ config: config, command: types.ORDER_PROCESS_QUEUE })
navigator.serviceWorker.controller.postMessage({ config: config, command: types.SYNC_PROCESS_QUEUE })
}
}
}

window.addEventListener('online', checkiIsOnline)
window.addEventListener('offline', checkiIsOnline)

Loading

0 comments on commit b762faf

Please sign in to comment.