`
}
}
})
customElements.define('mix-pack-subitem', class extends CartMixin(LitElement) {
createRenderRoot() {
return this
}
render() {
const { id, name, joinPrice } = this
return html`
${name}
`
}
})
customElements.define('mix-pack-subitem-added', class extends CartMixin(LitElement) {
createRenderRoot() {
return this
}
render() {
const { id, name, joinPrice } = this
return html`
${unsafeHTML(name)}
$${joinPrice}
`
}
})
customElements.define('included-addon', class extends ProductMixin(LitElement) {
createRenderRoot() {
return this
}
render() {
const { id, joinPrice, name } = this
return html`
${unsafeHTML(name)}
$${joinPrice}
`
}
})
customElements.define('included-addon-by-default', class extends ProductMixin(LitElement) {
createRenderRoot() {
return this
}
render() {
const { joinPrice, name } = this
return html`
${unsafeHTML(name)}
${joinPrice}
`
}
})
customElements.define('optional-addon', class extends ProductMixin(LitElement) {
createRenderRoot() {
return this
}
render() {
const { joinPrice, image, name, addonGroupParentName } = this
return html`
${name}
$${joinPrice}
`
}
})
customElements.define('shopping-cart', class extends CartMixin(LitElement) {
createRenderRoot() {
return this
}
getPacks() {
const myPacks = optionalSort(Object.values(this.products)).filter(({type,selected}) => type == 'pack' && selected)
//console.log("GET PACKS ASDF");
//console.log(myPacks);
return myPacks;
}
getIncludedAddons() {
return optionalSort(Object.values(this.products)).filter(({type,selected}) => type == 'includedAddon' && selected)
}
getIncludedByDefaultAddons(packs) {
return optionalSort(Object.values(this.products)).filter(({type, includedIn}) => { let selectedPacks = packs.map(p => p.id); return type === 'includedAddon' && includedIn.filter(value => selectedPacks.includes(value)).length > 0 });
}
getOptionalAddons() {
return optionalSort(Object.values(this.products))
.filter(({type,selected}) => type == 'optionalAddon' && selected)
.map(
({addonGroupParent,...p}) => ({
addonGroupParent,
...p,
image: this.products[addonGroupParent].image,
addonGroupParentName: this.products[addonGroupParent].name
})
)
}
getTax() {
return 0;
}
getTotal () {
return this.getSubTotal() + this.getTax() - this.getPaymentTypeDiscount();
}
getPaymentTypeDiscount() {
if (document.forms['JOIN'].elements['PAYMENT_TYPE'].value == 15 && (this.products[2008].selected || this.products[2026].selected || this.products[29].selected || this.products[2047].selected)) { return 0;
} else {
return 0;
}
}
getSubTotal() {
return Object.values(this.products).filter(({selected}) => selected).map(({joinPrice}) => joinPrice).map(parseFloat).reduce((a,x) => a + x, 0)
}
getDiscount() {
return this.getFullPrice() - this.getSubTotal()
}
getFullPrice() {
return Object.values(this.products).filter(({selected}) => selected).map(({joinPrice}) => joinPrice).map(parseFloat).reduce((a,x) => a + x, 0)
}
getNextPayment() {
if(this.products[2049].selected){
const notIncludedList = [2067,2068,2092];
return Object.values(this.products).filter(({id, selected}) => selected && notIncludedList.indexOf(id) == -1).map(({monthlyPrice}) => monthlyPrice).map(parseFloat).reduce((a,x) => a + x, 0)
} else {
return Object.values(this.products).filter(({selected}) => selected).map(({monthlyPrice}) => monthlyPrice).map(parseFloat).reduce((a,x) => a + x, 0)
}
}
shouldBeExpanded() {
return Object.values(this.products).some(({type,selected}) => type == 'pack' && selected)
}
isExpanded() {
return ['#cart-sidebar','.wizard-sidebar'].map(document.querySelector.bind(document)).every(t => t.classList.contains('expanded'))
}
expand() {
['#cart-sidebar','.wizard-sidebar'].map(document.querySelector.bind(document)).forEach(t => t.classList.add('expanded'))
document.getElementById("wizard-cart-fixed").classList.add("expanded-fixed");
}
unExpand() {
['#cart-sidebar','.wizard-sidebar'].map(document.querySelector.bind(document)).forEach(t => t.classList.remove('expanded'))
}
render() {
const cartAvalara = false;
if (cartAvalara) {
var packs = this.getPacks();
isAvalaraDataValid().then(isValid => {
if (isValid){
getTaxResult(false, packs).then(result => {
if (result >= 0) {
let taxesIncluded = document.querySelector('.tax-info');
if (result > 0){
taxesIncluded.hidden = false;
} else
{
taxesIncluded.hidden = true;
}
let taxes = document.getElementById("count-taxes");
taxes.hidden = false;
let taxesTax = document.getElementById("count-taxes-tax");
taxesTax.innerHTML = "$" + result;
let dollar = '$';
let countTotal = this.getTotal().toFixed(2);
countTotal = parseFloat(countTotal) + result;
document.querySelector('.count-total').innerText = dollar + countTotal.toFixed(2);
let shouldPay = this.getTotal().toFixed(2);
shouldPay = parseFloat(shouldPay) + result;
document.querySelector('.count-should-pay').innerText = dollar + shouldPay.toFixed(2);
document.getElementById('agree1').innerText = (parseFloat(this.getTotal().toFixed(2)) + result).toFixed(2);
}
else {
result = 0;
let taxesIncluded = document.querySelector('.tax-info');
taxesIncluded.hidden = true;
let taxes = document.getElementById("count-taxes");
taxes.hidden = true;
let dollar = '$';
let countTotal = this.getTotal().toFixed(2);
countTotal = parseFloat(countTotal) + result;
document.querySelector('.count-total').innerText = dollar + countTotal.toFixed(2);
let shouldPay = this.getTotal().toFixed(2);
shouldPay = parseFloat(shouldPay) + result;
document.querySelector('.count-should-pay').innerText = dollar + shouldPay.toFixed(2);
document.getElementById('agree1').innerText = (parseFloat(this.getTotal().toFixed(2)) + result).toFixed(2);
}
});
getTaxResult(true, packs).then(result => {
if (result >= 0) {
let dollar = '$';
let nextPayment = this.getNextPayment().toFixed(2);
nextPayment = parseFloat(nextPayment) + result;
document.querySelector('.count-next-payment').innerText = dollar + nextPayment.toFixed(2);
document.getElementById('agree1Monthly').innerText = (parseFloat(this.getNextPayment().toFixed(2)) + result).toFixed(2);
}
else {
result = 0;
let dollar = '$';
let nextPayment = this.getNextPayment().toFixed(2);
nextPayment = parseFloat(nextPayment) + result;
document.querySelector('.count-next-payment').innerText = dollar + nextPayment.toFixed(2);
document.getElementById('agree1Monthly').innerText = (parseFloat(this.getNextPayment().toFixed(2)) + result).toFixed(2);
}
});
}
});
}
if (this.shouldBeExpanded()) {
if (!this.isExpanded()) {
this.expand()
}
} else {
if (this.isExpanded) {
this.unExpand()
}
}
document.querySelector('.count-total').innerText = `$${this.getTotal().toFixed(2)}`
document.getElementById('agree1').innerText = this.getTotal().toFixed(2);
document.getElementById('agree1Monthly').innerText = this.getNextPayment().toFixed(2);
return html`
shopping cart
${this.getPacks().filter(({id})=> (id !=2049)).map(({ joinPrice, id, name }) => html``)}
${this.getPacks().filter(({id})=> (id ==2049)).map(({ joinPrice, id, name }) => html``)}