pricing->addtocart->login|register->checkout page OK

This commit is contained in:
Bachir Soussi Chiadmi 2019-11-06 12:16:33 +01:00
parent c3a26a709e
commit eb6cb2db27
8 changed files with 151 additions and 92 deletions

View File

@ -117,6 +117,7 @@ module:
path: 0
path_alias_xt: 0
pathologic: 0
permissions_filter: 0
persistent_login: 0
profile: 0
recurring_period: 0

View File

@ -1 +1,2 @@
label: Client
display_label: 'Informations sur le client'

View File

@ -1250,6 +1250,10 @@ header[role="banner"] {
margin: 0; }
header[role="banner"] #block-userlogin .item-list ul li a {
font-size: 0.756em; }
header[role="banner"] #block-userblock h2 {
display: none; }
header[role="banner"] #block-userblock a {
margin-right: 1em; }
header[role="banner"] #block-header {
margin-right: 1em;
padding-left: 1em;

File diff suppressed because one or more lines are too long

View File

@ -61,11 +61,11 @@ import 'theme/assets/styles/main.scss'
initVRouter();
initVSiteBrandingBlock()
initVPagetitleBlock()
initVUserBlock()
initVHeaderMenu()
initVMainContent()
initVSearchBlock()
}
initVUserBlock()
}
function initVRouter(){

View File

@ -125,6 +125,18 @@ header[role="banner"]{
}
}
// non-vue userblock
#block-userblock{
h2{display:none;}
a{
margin-right: 1em;
}
}
// vue userblock
#user-tools{
}
// menu
#block-header{
margin-right: 1em;

View File

@ -31,7 +31,7 @@
:styles="{width:'500px', height:'100%'}"
>
<h2>Please login or register before continue.</h2>
<LoginRegister @onLogedIn="logedIn" @onRegistered="registered" />
<LoginRegister @onLogedIn="onLogedIn" @onRegistered="onRegistered" />
</Modal>
</article>
@ -74,41 +74,82 @@ export default {
console.log('checkaddtocart');
if(!this.isloggedin){
// TODO: show popup login or register
// show popup for login or register
// login or register event will be catched by onLogedin or onRegistered
this.showLoginModal = true
// TODO: rest login or register
// TODO: rest login
// TODO: this.addtocart()
}else{
// if already logedin directly goes to cart operations
this.addtocart()
}
},
logedIn () {
console.log('Product: logedIn');
// event bubbled from modal login form
onLogedIn () {
console.log('Product: onLogedIn');
this.addtocart()
},
registered () {
console.log('Product: registered');
// event bubbled from modal register form
onRegistered () {
console.log('Product: onRegistered');
this.addtocart()
},
getCarts () {
return REST.get(`/cart?_format=json`)
// .then(({ data }) => {
// console.log('current user carts: data', data)
// })
.catch(( error ) => {
console.warn('Issue with get cart', error)
Promise.reject(error)
})
},
deleteCart (order_id) {
console.log('deleting cart ', order_id);
return REST.delete(`/cart/${order_id}/items?_format=json`)
.then(({ data }) => {
console.log(`product cart ${order_id} deleted: data`, data)
})
.catch(( error ) => {
console.warn(`Issue with cart ${order_id} deleting`, error)
Promise.reject(error)
})
},
clearCarts (data) {
let promises = [];
// clear each cart as a promise
for (var i = 0; i < data.length; i++) {
promises.push(this.deleteCart(data[i].order_id))
}
// return all the promises as one
return Promise.all(promises)
},
addtocart () {
console.log("addtocart")
REST.post(`/cart/add?_format=json`, [{
"purchased_entity_type": "commerce_product_variation",
"purchased_entity_id": this.product.variation_id,
"quantity": this.quantity
}])
.then(({ data }) => {
console.log('product add to cart REST: data', data)
this.closeModal()
// TODO: redirect to /cart
this.getCarts()
.then(({data}) => {
console.log('current user carts: data', data)
this.clearCarts(data)
.then(() => {
console.log('all carts cleared');
// fill the cart with new product
REST.post(`/cart/add?_format=json`, [{
"purchased_entity_type": "commerce_product_variation",
"purchased_entity_id": this.product.variation_id,
"quantity": this.quantity
}])
.then(({ data }) => {
console.log('product added to cart: data', data)
this.closeModal()
// redirect to /cart
// window.location.href = "/cart"
// TODO: redirect to checkout instead of cart
window.location.href = `/checkout/${data[0].order_id}/order_information`
})
.catch(( error ) => {
console.warn('Issue with product add to cart', error)
Promise.reject(error)
})
})
})
.catch(( error ) => {
console.warn('Issue with product add to cart', error)
Promise.reject(error)
})
}
},
components: {

View File

@ -66,7 +66,7 @@ export default {
state.isloggedin = false
state.logout_token = null
if (state.isAdmin){
// TODO: what if on a page where login is needed (as commerce checkout and cart)
window.location.reload(true);
}
state.asAdmin = false