// Initialize SDK
shoppex.init('your-store');
// Load products
async function loadProducts() {
const { data: products } = await shoppex.getProducts();
const container = document.getElementById('products');
products.forEach(product => {
const card = document.createElement('div');
card.className = 'product';
card.innerHTML = `
<img src="${product.images[0]?.url || '/placeholder.jpg'}" alt="${product.title}">
<h3>${product.title}</h3>
<p class="price">${shoppex.formatPrice(product.price, product.currency)}</p>
<button class="btn" data-id="${product.uniqid}">Add to Cart</button>
`;
container.appendChild(card);
});
container.querySelectorAll('button').forEach(btn => {
btn.addEventListener('click', () => addToCart(btn.dataset.id));
});
}
// Cart functions
function addToCart(productId) {
shoppex.addToCart(productId, '', 1);
updateCartCount();
}
function updateCartCount() {
document.getElementById('count').textContent = shoppex.getCartItemCount();
}
async function goToCheckout() {
if (shoppex.getCart().length === 0) {
alert('Your cart is empty');
return;
}
await shoppex.checkout();
}
// Initialize
loadProducts();
updateCartCount();