2021-06-01 21:33:49 +00:00
|
|
|
import { CartBaseController } from './cart_base_controller'
|
|
|
|
|
|
|
|
export default class extends CartBaseController {
|
|
|
|
static targets = [ 'order' ]
|
|
|
|
|
|
|
|
async connect () {
|
2021-10-27 18:58:32 +00:00
|
|
|
if (this.clear) {
|
|
|
|
this.storage.clear()
|
|
|
|
window.dispatchEvent(new CustomEvent('cart:counter', { detail: { item_count: 0 }}))
|
|
|
|
}
|
2021-06-01 21:33:49 +00:00
|
|
|
|
|
|
|
if (!this.template) return
|
|
|
|
|
2021-10-27 18:58:51 +00:00
|
|
|
if (this.storage.cart) {
|
|
|
|
const order = this.cart.data.attributes
|
|
|
|
const products = this.products
|
|
|
|
const site = await this.site()
|
|
|
|
const shipping_address = JSON.parse(this.storage.getItem('shipping_address'))
|
|
|
|
|
|
|
|
const data = { order, products, site, shipping_address }
|
|
|
|
|
|
|
|
this.storage.setItem('confirmation', JSON.stringify(data))
|
|
|
|
} else {
|
|
|
|
data = JSON.parse(this.storage.getItem('confirmation'))
|
2021-06-01 21:33:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.render(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
render (data = {}) {
|
2021-10-28 13:00:00 +00:00
|
|
|
this.engine.parseAndRender(this.template, data).then(html => this.orderTarget.innerHTML = html)
|
2021-06-01 21:33:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get clear () {
|
|
|
|
return this.element.dataset.clear
|
|
|
|
}
|
2021-10-28 13:00:00 +00:00
|
|
|
|
|
|
|
get template () {
|
|
|
|
return window.templates[this.element.dataset.template]
|
|
|
|
}
|
2021-06-01 21:33:49 +00:00
|
|
|
}
|