Skip to content
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
2 changes: 1 addition & 1 deletion core/components/blocks/Checkout/Payment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default {
currentUser: state => state.user.current
}),
...mapGetters({
paymentMethods: 'cart/paymentMethods'
paymentMethods: 'payment/paymentMethods'
})
},
created () {
Expand Down
4 changes: 2 additions & 2 deletions core/components/blocks/Checkout/Shipping.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ export default {
currentUser: state => state.user.current
}),
...mapGetters({
shippingMethods: 'cart/shippingMethods'
shippingMethods: 'shipping/shippingMethods'
})
},
mounted () {
if (!this.shipping.shippingMethod || this.notInMethods(this.shipping.shippingMethod)) {
this.shipping.shippingMethod = this.shippingMethods[0].method_code
this.shipping.shippingMethod = this.shippingMethods.find(item => item.default).method_code
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Selecting the default method instead of the first.

}
},
methods: {
Expand Down
15 changes: 8 additions & 7 deletions core/store/modules/cart/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,15 @@ export default {
load (context) {
console.log('Loading cart ...')
const commit = context.commit
const rootState = context.rootState
const state = context.state

if (!state.shipping.code) {
state.shipping = rootState.shipping.methods.find((el) => { if (el.default === true) return el }) // TODO: use commit() instead of modifying the state in actions
if (!state.shipping.method_code) {
let shippingMethod = context.rootGetters['shipping/shippingMethods'].find(item => item.default)
commit(types.CART_UPD_SHIPPING, shippingMethod)
}
if (!state.payment.code) {
state.payment = rootState.payment.methods.find((el) => { if (el.default === true) return el })
let paymentMethod = context.rootGetters['payment/paymentMethods'].find(item => item.default)
commit(types.CART_UPD_PAYMENT, paymentMethod)
}
global.db.cartsCollection.getItem('current-cart', (err, storedItems) => {
if (err) throw new Error(err)
Expand Down Expand Up @@ -265,7 +266,7 @@ export default {
silent: true
}, { root: true }).then(task => {
let backendMethods = task.result
let paymentMethods = rootStore.state.payment.methods.slice(0) // copy
let paymentMethods = context.rootGetters['payment/paymentMethods'].slice(0) // copy
let uniqueBackendMethods = []
for (let i = 0; i < backendMethods.length; i++) {
if (!paymentMethods.find(item => item.code === backendMethods[i].code)) {
Expand Down Expand Up @@ -305,8 +306,8 @@ export default {
if (config.cart.synchronize_totals && (typeof navigator !== 'undefined' ? navigator.onLine : true)) {
if (!methodsData) {
let country = rootStore.state.checkout.shippingDetails.country ? rootStore.state.checkout.shippingDetails.country : config.tax.defaultCountry
let shipping = context.getters.shippingMethods[0]
let payment = context.getters.paymentMethods[0]
let shipping = context.rootGetters['shipping/shippingMethods'].find(item => item.default)
let payment = context.rootGetters['payment/paymentMethods'].find(item => item.default)
methodsData = {
country: country,
method_code: shipping ? shipping.method_code : null,
Expand Down
14 changes: 0 additions & 14 deletions core/store/modules/cart/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,5 @@ export default {
return _.sumBy(state.cartItems, (p) => {
return p.qty
})
},
shippingMethods (state) {
if (state.shipping instanceof Array) {
return state.shipping
} else {
return [state.shipping]
}
},
paymentMethods (state) {
if (state.payment instanceof Array) {
return state.payment
} else {
return [state.payment]
}
}
}
8 changes: 4 additions & 4 deletions core/store/modules/cart/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export default {
}
state.cartSavedAt = new Date()
},
[types.CART_UPD_SHIPPING] (state, shippingMethods) {
state.shipping = shippingMethods
[types.CART_UPD_SHIPPING] (state, shippingMethod) {
state.shipping = shippingMethod
state.cartSavedAt = new Date()
},
[types.CART_LOAD_CART] (state, storedItems) {
Expand All @@ -71,8 +71,8 @@ export default {
state.platformTotalSegments = platformTotalSegments
EventBus.$emit('cart-after-updatetotals', { platformTotals: totals, platformTotalSegments: platformTotalSegments })
},
[types.CART_UPD_PAYMENT] (state, paymentMethods) {
state.payment = paymentMethods
[types.CART_UPD_PAYMENT] (state, paymentMethod) {
state.payment = paymentMethod
state.cartSavedAt = new Date()
}
}
15 changes: 15 additions & 0 deletions core/store/modules/payment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,20 @@ export default {
namespaced: true,
state: {
methods: []
},
mutations: {
addMethod (state, paymentMethod) {
state.methods.push(paymentMethod)
}
},
actions: {
addMethod ({commit}, paymentMethod) {
commit('addMethod', paymentMethod)
}
},
getters: {
paymentMethods (state) {
return state.methods
}
}
}
5 changes: 5 additions & 0 deletions core/store/modules/shipping/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ export default {
namespaced: true,
state: {
methods: shippingtMethods
},
getters: {
shippingMethods (state) {
return state.methods
}
}
}
2 changes: 1 addition & 1 deletion src/extensions/payment-cash-on-delivery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function (app, router, store, config) {
'offline': true
}

app.$store.state.payment.methods.push(paymentMethodConfig)
app.$store.dispatch('payment/addMethod', paymentMethodConfig)

// Mount the info component when required.
EventBus.$on('checkout-payment-method-changed', (paymentMethodCode) => {
Expand Down