Create your custom cake topper
Upload your image, select size and color, and we'll create a beautiful custom topper for you.
Preview
Upload image preview
Size
Not selected
Color
Not selected
Rush
No
Total
₹0
(function() {
class CustomTopperabm1icvvrqnbhzw9yvcustomcaketoppergart3a extends HTMLElement {
constructor() {
super();
this.variantId = 52081758109990; // Your hidden product variant
this.uploadedFile = null;
this.selectedSize = null;
this.selectedPrice = 0;
this.selectedColor = null;
this.colorExtra = 0;
this.customization = '';
this.rushOrder = false;
this.finalPrice = 0;
this.isSubmitting = false;
}
connectedCallback() {
this.uploadArea = this.querySelector('[data-upload-area]');
this.fileInput = this.querySelector('[data-file-input]');
this.sizeSelect = this.querySelector('[data-size-select]');
this.colorSelect = this.querySelector('[data-color-select]');
this.customizationInput = this.querySelector('[data-customization-input]');
this.submitButton = this.querySelector('[data-submit-button]');
this.previewImage = this.querySelector('[data-preview-image]');
this.previewSize = this.querySelector('[data-preview-size]');
this.previewColor = this.querySelector('[data-preview-color]');
this.previewPrice = this.querySelector('[data-preview-price]');
this.previewRush = this.querySelector('[data-preview-rush]');
this.rushCheckbox = this.querySelector('[data-rush-order]');
this.imageError = this.querySelector('[data-image-error]');
this.sizeError = this.querySelector('[data-size-error]');
this.colorError = this.querySelector('[data-color-error]');
this.setupListeners();
}
setupListeners() {
this.uploadArea.addEventListener('click', () => this.fileInput.click());
this.fileInput.addEventListener('change', (e) => {
if (e.target.files.length > 0) {
this.handleFileUpload(e.target.files[0]);
}
});
this.sizeSelect.addEventListener('change', (e) => {
const option = e.target.selectedOptions[0];
this.selectedSize = option.value;
this.selectedPrice = parseInt(option.dataset.price || 0);
this.previewSize.textContent = this.selectedSize || 'Not selected';
this.sizeError.style.display = 'none';
this.updatePrice();
});
this.colorSelect.addEventListener('change', (e) => {
const option = e.target.selectedOptions[0];
this.selectedColor = option.value;
this.colorExtra = parseInt(option.dataset.extra || 0);
this.previewColor.textContent = this.selectedColor || 'Not selected';
this.colorError.style.display = 'none';
this.updatePrice();
});
this.customizationInput.addEventListener('input', (e) => {
this.customization = e.target.value.trim();
});
this.rushCheckbox.addEventListener('change', (e) => {
this.rushOrder = e.target.checked;
this.previewRush.textContent = this.rushOrder ? "Yes (+₹50)" : "No";
this.updatePrice();
});
this.submitButton.addEventListener('click', () => this.handleSubmit());
}
updatePrice() {
let total = this.selectedPrice;
if (this.colorExtra) total += this.colorExtra;
if (this.rushOrder) total += 50;
this.finalPrice = total;
this.previewPrice.textContent = "₹" + total;
}
handleFileUpload(file) {
if (!file.type.startsWith('image/')) {
alert('Upload a valid image file.');
return;
}
if (file.size > 10 * 1024 * 1024) {
alert('Image must be under 10MB.');
return;
}
this.uploadedFile = file;
this.imageError.style.display = 'none';
const reader = new FileReader();
reader.onload = (e) => {
this.previewImage.innerHTML =
'

';
};
reader.readAsDataURL(file);
}
async handleSubmit() {
if (this.isSubmitting) return;
let hasError = false;
if (!this.uploadedFile) {
this.imageError.style.display = 'block';
hasError = true;
}
if (!this.selectedSize) {
this.sizeError.style.display = 'block';
hasError = true;
}
if (!this.selectedColor) {
this.colorError.style.display = 'block';
hasError = true;
}
if (hasError) return;
this.isSubmitting = true;
this.submitButton.disabled = true;
this.submitButton.textContent = "Adding...";
const formData = new FormData();
formData.append('id', this.variantId);
formData.append('quantity', 1);
// Price override (in paise)
formData.append('price', this.finalPrice * 100);
formData.append('properties[Uploaded Image]', this.uploadedFile);
formData.append(
'properties[Size]',
this.selectedSize + " (₹" + this.selectedPrice + ")"
);
formData.append(
'properties[Color]',
this.selectedColor +
(this.colorExtra ? " (+₹" + this.colorExtra + ")" : "")
);
formData.append(
'properties[Rush Order]',
this.rushOrder ? "Yes (+₹50)" : "No"
);
formData.append(
'properties[Additional Customization]',
this.customization || 'None'
);
try {
await fetch('/cart/add.js', {
method: 'POST',
body: formData
});
window.location.href = '/cart';
} catch (err) {
alert("Something went wrong.");
this.submitButton.disabled = false;
this.submitButton.textContent = "Create custom topper";
this.isSubmitting = false;
}
}
}
customElements.define(
'custom-topper-abm1icvvrqnbhzw9yvcustomcaketoppergart3a',
CustomTopperabm1icvvrqnbhzw9yvcustomcaketoppergart3a
);
})();