Skip to content

HOW TO ADD POPUP CART

Just add the following code into Custom JS

document.addEventListener("DOMContentLoaded", function() {
    var e = document.getElementById('snakebar')
    var observer = new MutationObserver(function (events) {
        for(let event of events){
            let target = event.target;
            if(target.classList.contains('show')) return;
            let modalOptions = {
                id:'add-to-cart-modal',
                title:'Item Added to Cart',
                body:'',
                button:'Continue Shopping'
            }
            window.edokan.getCart(function(err,cart){
                let cartHtml = cart.map((item)=>{
                    let html = '<tr>';
                    html += '<td><img width="32px" src="' + item.product.photo.src + '"></td>';
                    html += '<td>'+ item.product.name + '<br><small>' + item.product.sku + '</small></td>';
                    html += '<td>' + item.quantity + "</td>";
                    html += '<td>' + (item.quantity*item.product.actualPrice) + "</td>";
                    html += "</tr>";
                    return html;
                }).join('');
                cartHtml = '<table class="table">' + cartHtml + "</table>";
                modalOptions.body = cartHtml;
                _showModal(modalOptions);
                let closeBtn = document.querySelector('#add-to-cart-modal .modal-footer button');
                let checkout = document.createElement('a');
                checkout.className = 'btn btn-primary';
                checkout.href = "/checkout";
                checkout.innerText = "Checkout";
                document.querySelector('#add-to-cart-modal .modal-footer').appendChild(checkout);
                closeBtn.classList.remove('btn-primary');
                closeBtn.classList.add('btn-outline-primary');
            })
        }
    })

    observer.observe(e, {
    attributes: true, 
    attributeFilter: ['class'],
    childList: false, 
    characterData: false
    })
});

Powered by BetterDocs