QH88 Menjelajahi dunia virtual terasa sangat mengasyikkan berkat kehadiran monster unik dan berbagai misi dengan alur dinamis yang selalu memberikan kejutan menarik.
Show More →
`
html.push(body)
}
}
$("#itemAddons .row").html(html.length === 0 ? '
No Item available
' : html)
$("#itemAddons").attr("data-length", products.length)
// $('#itemAddons')[0].swiper.update();
});
})
async function isAddon(){
let ids = []
$("#itemAddons .item-card.selected").each(function(i, e){
const id = $(this).data("id")
ids.push(id)
})
console.log(ids)
return ids
}
$("#itemAddons").delegate(".item-card > div:not(.card-qty)", "click", async function(){
const t = $(this).parent()
const id = t.data("id")
const btn = t.parents(".purchaseAddon").find(".next-purchase-button")
t.toggleClass("selected");
//$(this).next("input").toggleAttr('name', 'id[]');
if (t.hasClass('selected')) {
t.find("input").val(1)
t.find("input").attr('name', 'id[]');
} else {
t.find("input").val(0)
t.find("input").removeAttr('name');
}
$("#properties-addons").val(addons)
const is = await isAddon()
if(is.length === 0) {
btn.text("continue without add-ons")
return
}
if(is.includes(8835692069079)) {
btn.text("personalize acrylic frame")
} else {
btn.text("Continue")
}
})
async function myAddon(data) {
const c = $(".addonsPurchase .addons")
let items = []
const spotifyAddons = $(".spotifyAddons").find("[data-index]")
// if(spotifyAddons.length > 0) {
// $(spotifyAddons).each(function(i, e){
// const spotifyLink = $(this).find(".spotifyLink").val()
// const spotifySong = $(this).find(".spotifySong").val()
// const spotifyArtist = $(this).find(".spotifyArtist").val()
// const spotifyFotoAddon = $(this).find(".resultPhotoSpotify").val()
// if(spotifyLink !== '') {
// spotifyAddon = `
//
//
//
//
// [US] Outerbloom Acrylic Frame 4R
//
//
// Rp 99.000
//
//
//
//
//
//
// spotify link
// ${spotifyLink}
//
//
// uploaded photo
// ${spotifyFotoAddon}
//
//
// song / playlist name
// ${spotifySong}
//
//
// artist name
// ${spotifyArtist}
//
//
//
`
// items.push(spotifyAddon)
// }
// })
// }
for(let i = 0; i < data.length; i++) {
if(data[i].title !== '[US] Outerbloom Acrylic Frame 4R' ) {
const img = data[i].image
const title = data[i].title
const qty = data[i].qty
const price = data[i].price
const total = Number(qty) * Number(price)
let addons = `
${title}
${rupiah.format(price)}
${data[i].title == '[US] Outerbloom Acrylic Frame 4R' ? '' : `x${qty} `}
${rupiah.format(total)}
`
items.push(addons)
}
}
c.html(items)
const parent = $(".purchaseAddon")
const next = parent.next(".sectionPurchase")
parent.addClass("hide")
next.removeClass("hide")
// if(items2.length === 0) return $("#popupCart").addClass("no-addon-cart")
// $(".itemAddonCart").find("h4").text(`add-ons (${items2.length})`)
}
async function listAddon() {
const data = $("#itemAddons").find(".selected")
let ids = []
$(data).each(function(){
const id = $(this).data("variant")
const image = $(this).find(".card-image img").attr("src")
const title = $(this).find(".card-meta h5").text()
const qty = $(this).find(".card-qty input").val()
const price = $(this).find(".card-qty input").data("price")
ids.push({
id: Number(id),
image,
title,
qty,
price
})
})
myAddon(ids)
}
async function customSpotify(idx, length, type){
let isCard = false
let p = $(".purchasePopupSpotify")
const preLink = $(".spotifyLinkFirst").val()
$("[data-index]").hide()
p.find(".headerPurchase h3").text(`personalize spotify photo print${length > 1 ? ` - ${idx}` : ''}`)
p.find(".regulerAddons, .purchase-button").hide()
p.find(".spotifyAddons").show()
const data = await trackUrl(preLink)
const html = `
${data?.song ? `
${data?.song} ` : '
'}${data?.artist ? ` ${data?.artist}
` : '
'}
`
// console.log(html)
$(".spotifyAddons").append(html)
$(`[data-index=${idx}]`).show()
if (preLink !== '') {
$(".btn-action .btn").attr("disabled", false)
} else {
$(".btn-action .btn").attr("disabled", true)
}
return html
}
$(".spotifyLinkFirst").keyup(async function(){
const v = $(this).val()
if(v.includes('spotify:user:spotify')) {
const correct = v.split('user:spotify:')[1]
console.log(correct, 'BNER')
$(this).val(correct)
return
}
if(v.includes("spotify:") || v.includes("https://open.spotify.com/")){
const data = await trackUrl(v)
if(!data || !data.status) {
$(this).parent().addClass("error")
// $(this).parent().append(`
Make sure you copy the complete and correct link from Spotify. Ex: https://open.spotify.com/track/0C3xZJueyBvvMSsl0cETA6
`)
$("#personalizeBtnSpotify .btn").attr("disabled", true)
return
}
$(this).parent().removeClass("error")
// $(this).parent().remove("txt-error")
$("#personalizeBtnSpotify .btn").attr("disabled", false)
} else {
$("#personalizeBtnSpotify .btn").attr("disabled", true)
}
})
$(".purchaseAddon").delegate(".next-addon", "click", function(){
const parent = $(this).parents(".purchaseAddon")
const next = parent.next(".sectionPurchase")
if(next.hasClass("purchaseAddress")) {
if(productType !== '') {
console.log("clarity event " + productType + ' purchaseDelivery')
window.clarity("event", `${productType} purchaseDelivery`)
// window.clarity("set", productType, `purchaseDelivery - ${productDate}`)
}
}
const data = $("#itemAddons").find(".selected")
const length = $(".quantity-cart-46067682607319").val()
const checked = data.length;
if(checked > 0) {
if(length > 0) {
$(".purchaseAddon").addClass("purchaseAddonSpotify")
customSpotify(1, length, 'addon')
} else {
listAddon()
}
} else {
parent.addClass("hide")
next.removeClass("hide")
}
})
$("#personalizeBtnSpotify .btn").click(async function(){
const isCity = $("#cities[required]")
const isDate = $("#propDeliveryDate[required]")
if((isDate.length > 0 && isCity.length > 0) && (isCity.val() === '' || isDate.val() === '')) {
alert('Please choose Delivery City & Delivery Date')
return
}
const data = await customSpotify(1, 1, 'product')
if(data) {
$("#backgroundPopup").fadeIn("slow");
$(".purchasePopupSpotify").fadeIn("slow");
if(productType !== '') {
console.log("clarity event " + productType + ' spotify')
window.clarity("event", `${productType} spotify`)
// window.clarity("set", productType, `purchaseDelivery - ${productDate}`)
}
}
})
function formatBytes(bytes, decimals = 2) {
if (!+bytes) return '0 Bytes'
const k = 1024
const dm = decimals < 0 ? 0 : decimals
const sizes = ['B', 'KB', 'MB']
const i = Math.floor(Math.log(bytes) / Math.log(k))
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`
}
async function trackUrl(link){
try {
let trackId = link.split('/').pop().split('?')[0];
let type = ''
if(link.includes("spotify:")) {
const uri = link.split('spotify:')[1]
trackId = uri.split(':')[1]
type = uri.split(':')[0] + 's'
} else {
if(link.match('track')){
type = 'tracks'
} else if(link.match('playlist')) {
type = 'playlists'
} else if(link.match('artist')) {
type = 'artists'
} else if(link.match('album')) {
type = 'albums'
}
}
console.log(`${host}/api/spotify/${type}/${trackId}`)
const data = await getFetch(`${host}/api/spotify/${type}/${trackId}`)
console.log(data, 'DATA')
const song = data?.data?.name
const artist = data?.data?.artist
return {
song, artist, type, trackId, status: data.status
}
} catch(err) {
console.log(err)
}
}
$(".spotifyAddons").delegate(".uploadPhotoSpotify", "change", async function(){
const parent = $(this).parents("[data-index]")
const preview = parent.find(".previewImage")
const file = $(this)[0].files[0];
if (file) {
const reader = new FileReader();
reader.onload = async function(e) {
parent.find(".uploadResult label").hide()
parent.find(".uploadedResult").remove()
parent.find(".uploadResult").append(`
${file.name} (${formatBytes(file.size)}) is uploaded
`)
parent.find(".frameImageUploaded svg").hide()
parent.find(".frameImage").addClass("uploaded")
preview.attr("src", e.target.result);
preview.show();
let formData = new FormData();
formData.append("file", file);
const response = await fetch(`${host}/api/upload?name=${file.name}&type=image/jpeg&r=${Date.parse(new Date)}`, {
method: "POST",
body: formData
})
const result = await response.json();
if(result){
parent.find(".resultPhotoSpotify").val(result.url)
}
}
reader.readAsDataURL(file);
} else {
preview.hide();
}
});
$(".spotifyAddons").delegate(".uploadResult", "click", function(){
$(this).next("input[type=file]").trigger("click")
})
$(".spotifyAddons").delegate(".changeUpload", "click", function(){
$(this).parents("input[type=file]").trigger("click")
})
$(".spotifyAddons").delegate(".removeUpload", "click", function(){
const parent = $(this).parents("[data-index]")
parent.find(".uploadPhotoSpotify").val("")
parent.find(".uploadResult label").show()
parent.find(".uploadedResult").remove()
parent.find(".frameImageUploaded svg").show()
parent.find(".previewImage").hide()
parent.find(".frameImage").removeClass("uploaded")
})
$(".spotifyAddons").delegate("label.checkbox", "click", function(){
const parent = $(this).parents("[data-index]")
parent.toggleClass("checked")
})
$(".spotifyAddons").delegate(".spotifyLink", "change", async function(){
const parent = $(this).parents("[data-index]")
const link = $(this).val()
const data = await trackUrl(link)
console.log(data)
if(data.song) {
parent.find(".spotifySong").val(data.song)
parent.find(".spotifyData").find("h3").text(data.song)
}
if(data.artist) {
parent.find(".spotifyArtist").val(data.artist)
parent.find(".spotifyData").find("p").text(data.artist)
}
parent.find(".spotifyCode img").attr("src", `https://scannables.scdn.co/uri/plain/png/FFFFFF/black/640/spotify:${data.type.slice(0, -1)}:${data.trackId}`)
// https://scannables.scdn.co/uri/plain/png/FFFFFF/black/640/spotify:track:1er51HCEBhIAtoEemKuC3M
if (data.status === true) {
parent.find(".btn-action .btn").attr("disabled", false)
} else {
parent.find(".btn-action .btn").attr("disabled", true)
}
})
$(".spotifyAddons").delegate(".spotifySong", "keyup", async function(){
const parent = $(this).parents("[data-index]")
const v = $(this).val()
parent.find(".spotifyData h3").text(v)
})
$(".spotifyAddons").delegate(".spotifyArtist", "keyup", async function(){
const parent = $(this).parents("[data-index]")
const v = $(this).val()
parent.find(".spotifyData p").text(v)
})
$(".spotifyAddons").delegate(".btn-action .btn:not(.no-addon)", "click", async function(){
const parent = $(this).parents("[data-index]")
const length = parent.data("length")
const index = parent.data("index")
const indexNext = Number(index) + 1
customSpotify(indexNext, length, 'addon')
})
$(".spotifyAddons").delegate(".btn-action .btn.finished", "click", async function(){
const parent = $(this).parents(".purchaseAddon")
const next = parent.next(".sectionPurchase")
parent.addClass("hide")
next.removeClass("hide")
next.find(".purchase-button").show()
listAddon()
})
$(".spotifyAddons").delegate(".back-spotify", "click", async function(){
const t = $(this).parents("[data-index]")
const parent = $(this).parents(".sectionPurchase")
const current = t.data("index")
const prevCurrent = Number(current) - 1
if(current == 1) {
parent.removeClass("purchaseAddonSpotify")
parent.find(".purchase-button").show()
parent.find(".headerPurchase h3").text("Make It More Special with Add-Ons!")
$(".spotifyAddons").empty()
$(".regulerAddons").show()
return
}
t.hide()
t.prev("[data-index]").show()
t.remove()
parent.find(".headerPurchase h3").text(`personalize spotify photo print - ${prevCurrent}`)
})
$("#personalizeBtn .btn").click(async function() {
loadPopupPersonalize()
});
$(".sectionPurchaseSpotify").delegate(".btn[data-type=card]", "click", function(){
$(".sectionPurchaseSpotify").hide()
loadPopupPersonalize()
})
$(".close-purchase-popup").click(function() {
disablePopup();
});
$("#backgroundPopup").click(function() {
// disablePopup();
});
$("#popupCart .close-purchase-popup").click(function() {
location.reload()
});
$('#popupCart').on('hide.bs.modal', function (e) {
location.reload()
})
$(".next-card").click(function(){
const parent = $(this).parents(".sectionPurchase")
const next = parent.next(".sectionPurchase")
parent.addClass("hide")
next.removeClass("hide")
})
$(".back-purchase-button").click(function(){
const parent = $(this).parents(".sectionPurchase")
const prev = parent.prev(".sectionPurchase")
parent.addClass("hide")
prev.removeClass("hide")
})
$(document).keypress(function(e) {
if (e.keyCode == 27 && popupStatus == 1) {
disablePopup();
}
});
const parentImg = $(".case-img-preview")
const parentVid = $(".case-video-preview")
function readURL(input) {
if (input.files && input.files[0]) {
let reader = new FileReader();
let type = 'image/jpeg'
const size = input.files[0].size
if(input.files[0].type.match('video/')){
type = 'video/mp4'
if(size > 15728640) {
alert('File size exceeds maximum limit 15 MB')
return
}
} else {
if(size > 5242880) {
alert('File size exceeds maximum limit 5 MB')
return
}
}
reader.onload = function (e) {
$(".nextBtn").attr("disabled", true)
if(type === 'image/jpeg') {
$('.placeholder-image').hide();
$('.preview-image').show()
$('.preview-image').attr('src', e.target.result);
} else {
// parentVid.find(".ajax-loader").show();
$(".steps-card-preview").addClass("loading")
}
}
reader.readAsDataURL(input.files[0]);
}
}
async function readURLPapan(input) {
if (input.files && input.files[0]) {
let reader = new FileReader();
reader.onload = function (e) {
$('.btn-upload-papan').siblings('label').hide();
$('.btn-upload-papan img').attr('src', e.target.result);
$('.btn-upload-papan img').show();
$('.svgLogoPapan').hide();
}
const type = 'image/jpeg'
const name = `logo-8359546319899-${Date.parse(new Date())}`
let formData = new FormData();
formData.append("file", input.files[0]);
const response = await fetch(`${host}/api/upload?name=${name}&type=${type}&r=${randomString(3, '0123456789')}`, {
method: "POST",
body: formData
})
const result = await response.json();
if(result) {
const url = result.url
$("[data-properties=papan-logo]").val(url)
}
reader.readAsDataURL(input.files[0]);
}
}
async function readURLAddress(input) {
console.log(input, 'readURLAddress')
if (input.files && input.files[0]) {
let reader = new FileReader();
reader.onload = function (e) {
$('.photo-address').attr('src', e.target.result);
$('.photo-address').show();
}
const type = 'image/jpeg'
const name = input.files[0].name?.split('.')[0]
let formData = new FormData();
formData.append("file", input.files[0]);
const response = await fetch(`${host}/api/upload?name=${name}&type=${type}&r=${randomString(3, '0123456789')}`, {
method: "POST",
body: formData
})
const result = await response.json();
reader.readAsDataURL(input.files[0]);
return result
}
}
async function addToCartUang() {
var productAddOnId1 = 42122101162199;
var productAddOnId2 = 42122101194967;
var product_id = 8359546319899
const data = {
items: [
{
quantity: $("#Quantity-" + productAddOnId1).val(),
id: productAddOnId1,
"properties": { "Time": $("#properties-time").val() }
},
{
quantity: $("#Quantity-" + productAddOnId2).val(),
id: productAddOnId2,
"properties": { "Time": $("#properties-time").val() }
}
]
}
await fetch(window.Shopify.routes.root + 'cart/add.js', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => {
console.error('Sukses Buket Uang:', response);
$(".form-flower").submit()
})
.catch((error) => {
console.error('Error Buket Uang:', error);
$(".form-flower").submit()
});
}
async function saveCard(){
let isCard = true
const kartu_penerima = $("[data-properties=penerima]").val() !== '' ? $("[data-properties=penerima]").val() : ''
const kartu_pengirim = $("[data-properties=pengirim]").val() !== '' ? $("[data-properties=pengirim]").val() : ''
const kartu_ucapan = $("[data-properties=ucapan]").val() !== '' ? $("[data-properties=ucapan]").val() : ''
const foto = $("#properties-photo").val()
const video = $("#properties-video").val()
const data = JSON.stringify({
"id": qrID,
"penerima": $("#properties-nama-penerima").val(),
"kartu_penerima": kartu_penerima,
"kartu_ucapan": kartu_ucapan,
"kartu_pengirim": kartu_pengirim,
"foto": foto,
"video": video,
"productId": "8359546319899",
"order_name": "",
"status": "Cart"
})
}
async function additem(items){
try {
let formData = items
if(items?.length) {
formData = {
'items': items
};
}
const add = await fetch(window.Shopify.routes.root + 'cart/add.js', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Requested-With':'xmlhttprequest' /* XMLHttpRequest is ok too, it's case insensitive */
},
body: JSON.stringify(formData)
})
const data = await add.json();
return data
} catch(err){
console.log('Error additem', err)
}
}
async function addons(){
let items = []
$(".addon-item").each(function(){
const p = $(this)
const props = p.next(".propsAddonSpotify")
const id = $(this).data("id")
const quantity = $(this).data("qty")
const propId = $("#properties-time").val()
let properties = {}
if(id === 46067682607319) {
const link = props.find(".spotifyLinkAddon").text()
const photo = props.find(".spotifyFotoAddon").text()
const song = props.find(".spotifySongAddon").text()
const artist = props.find(".spotifyArtistAddon").text()
properties = {
id: propId,
"Spotify Link": link !== '' ? link : '-',
"Spotify Photo": photo !== '' ? photo : '-',
"Spotify Song": song !== '' ? song : '-',
"Spotify Artist": artist !== '' ? artist : '-',
type: 'addon'
}
} else {
properties = {
"id": propId,
"type": "addon"
}
}
items.push({
id,
quantity,
properties
})
})
return items
}
async function propItems() {
let props = {}
$("[data-properties]").each(function(e){
let elementType = this.tagName;
const k = $(this).data("properties")
if(k !== 'penerima' && k !== 'ucapan' && k !== 'pengirim' && k !== 'nama-penerima' && k !== 'alamat-penerima' && k !== 'telepon-penerima' && k !== 'company' && k !== 'province' && k !== 'foto-alamat' && k !== 'papan-logo') {
const v = elementType === 'SELECT' ? $(this).find(":selected").val() : $(this).val();
if(v !== '') {
props[k] = v?.replace(/[\s\n]/g, '');
}
}
})
return props
}
async function showPopupCart(items){
if(productType !== '') {
console.log("clarity event " + productType + ' completeOrder')
window.clarity("event", `${productType} completeOrder`)
// window.clarity("set", productType, `completeOrder - ${productDate}`)
}
$("#popupCart").show()
$(".propDeliveryCity").text($("#cities").val())
$(".propDeliveryDate").text($("#propDeliveryDate").val())
$(".propDeliveryTime").text($("#propDeliveryTime").val())
$(".propDeliveryName").text($("[data-properties=nama-penerima]").val())
$(".propDeliveryAddress").text($("[data-properties=alamat-penerima]").val())
$(".propDeliveryPhone").text($("[data-properties=telepon-penerima]").val())
$(".propDeliveryProv").text($("#province").val())
$(".propDeliveryZip").text($("#zip").val())
const addons = []
if(items && items.length > 0) {
for(let i = 1; i < items.length; i++) {
const spotifyLink = items[i].properties['Spotify Link']
const spotifyPhoto = items[i].properties['Spotify Photo']
const spotifySong = items[i].properties['Spotify Song']
const spotifyArtist = items[i].properties['Spotify Artist']
const price = items[i].price / 100
const props = spotifyLink ? `
spotify link
${spotifyLink}
Upload Photo
${spotifyPhoto}
song / playlist name
${spotifySong}
artist name
${spotifyArtist}
` : '';
addons.push(`
${items[i].title}
${rupiah.format(price)}
${props}`)
}
}
// console.log(addons)
if(addons.length === 0) {
$(".itemAddonCart").hide()
return
}
$(".toggleAddonCart h4").text(`add-ons (${items.length - 1})`)
$(".wrapperItemAddonCart").html(addons)
}
const money = (money) => {
return new Intl.NumberFormat('id-ID',
{ style: 'currency', currency: 'IDR', minimumFractionDigits: 0 }
).format(money);
}
async function showNoteMoney() {
let qty50k = $("[data-properties='Uang 50k']").val()
let qty100k = $("[data-properties='Uang 100k']").val()
const total50k = Number(qty50k) * 50000
const total100k = Number(qty100k) * 100000
const total_all = total50k + total100k
$(".prop50k").html(`
${qty50k} Lembar: ${money(total50k)} `)
$(".prop100k").html(`
${qty100k} Lembar: ${money(total100k)} `)
$(".itemMoney").html(`
For the money arrangement, please transfer IDR ${money(total_all)} to Bank Mandiri 1020001234522 (PT Modern Mekar Abadi) and contact our Customer Service to confirm with proof of payment.
`)
}
async function removeImage() {
const data = JSON.stringify({
"ID": $("#properties-properties-qrId").val(),
"Kartu Nama Penerima": $("#properties-kartu-nama-penerima").val(),
"Kartu Nama Pengirim": $("#properties-kartu-nama-pengirim").val(),
"Kartu Ucapan": $("[data-properties=ucapan]").val(),
"Nama Penerima": $("#properties-nama-penerima").val(),
"Order Number":"",
"Status":"Product",
"Foto": "",
"Media": $("#properties-video").val(),
"Image": "8359546319899"
})
const remove = updateCard(data)
if(remove) {
$(this).hide()
$("#properties-photo").val("-")
$(".placeholder-image").show()
$(".preview-image").attr("src", "")
}
}
async function removeVideo() {
const data = JSON.stringify({
"ID": $("#properties-properties-qrId").val(),
"Kartu Nama Penerima": $("#properties-kartu-nama-penerima").val(),
"Kartu Nama Pengirim": $("#properties-kartu-nama-pengirim").val(),
"Kartu Ucapan": $("[data-properties=ucapan]").val(),
"Nama Penerima": $("#properties-nama-penerima").val(),
"Order Number":"",
"Status":"Product",
"Foto": $("#properties-photo").val(),
"Media": "",
"Image": "8359546319899"
})
const remove = updateCard(data)
if(remove) {
$("#properties-video").val("-")
$(this).find("img").hide()
$(this).hide()
$(this).prev("p").text("Add video to make it more special (optional)")
$("#label-input-video").show()
$("#label-input-video span").text("Upload Video")
$(".case-video-preview p span").remove()
}
}
async function loadItemOccasion(t, occasion) {
const name = occasion?.replace('greeting-card-', '')
$("#kartu-ucapan").val("")
$("[data-occassion]").removeClass("selected")
$("[data-properties=ucapan]").val("")
$("#save-card").attr("disabled", true)
t.addClass("selected")
$("#show_note").attr("data-card-occassion", name)
$.get(`https://outerbloom.com/collections/${occasion}/products.json`, function(data, status){
const products = data.products
const html = []
for(let i = 0; i < products.length; i++) {
const id = products[i].id
const variantId = products[i].variants[0].id
const img = products[i].images[0].src
const title = products[i].title
const price = products[i].variants[0].price
const qty = products[i].variants[0].inventory_quantity
const body = `
`
html.push(body)
}
const withoutCard = `
`
$("#itemCards .items-card").html(html.length === 0 ? '
No Item available
' : html.join(""))
});
}
$(document).ready(function(){
// Observer to auto-trigger addon loading when addon section becomes visible
const addonObserver = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
const target = $(mutation.target)
if(target.hasClass('purchaseAddon') && mutation.type === 'attributes' && mutation.attributeName === 'class') {
if(!target.hasClass('hide')) {
// Addon section just became visible, ensure items are loaded
setTimeout(function() {
if($("#itemAddons .row").children().length === 0 || $("#itemAddons .row").text().includes("No Item available")) {
console.log("Auto-triggering addon load...")
$("[data-addon=upsell-all]").trigger("click")
}
}, 150)
}
}
})
})
// Start observing addon section
const addonSection = document.querySelector('.purchaseAddon')
if(addonSection) {
addonObserver.observe(addonSection, {
attributes: true,
attributeFilter: ['class']
})
}
$(".purchasePopup").delegate("#addtocart-card", "click", async function(){
$(this).find("span").addClass("loading")
let isValid = true
$(".formAddressPurchase [required]").each(function(){
const t = $(this)
const input = t.val()
const p = t.parent()
if(input === '') {
p.addClass("error")
isValid = false
}
})
if(!isValid) {
$(this).find("span").removeClass("loading")
return
}
let items = []
const mainProps = {
"Delivery Date": $("#propDeliveryDate").val(),
"Delivery Time": $("#propDeliveryTime").val() !== '' ? $("#propDeliveryTime").val() : '-' ,
"Kota Pengiriman": $("#cities").val(),
"Nama Penerima": $("[data-properties=nama-penerima]").val() !== '' ? $("[data-properties=nama-penerima]").val() : '-' ,
"Alamat Penerima": $("[data-properties=alamat-penerima]").val() !== '' ? $("[data-properties=alamat-penerima]").val() : '-' ,
"Kodepos": $("#zip").val() !== '' ? $("#zip").val() : '-' ,
"Telepon Penerima": $("[data-properties=telepon-penerima").val() !== '' ? $("[data-properties=telepon-penerima").val() : '-' ,
"Papan Nama Penerima": $("[data-properties=penerima]").val() !== '' ? $("[data-properties=penerima]").val() : '-' ,
"Papan Ucapan": $("[data-properties=ucapan]").val() !== '' ? $("[data-properties=ucapan]").val() : '-' ,
"Papan Nama Pengirim": $("[data-properties=pengirim]").val() !== '' ? $("[data-properties=pengirim]").val() : '-' ,
"Papan Logo": $("[data-properties=papan-logo]").val() !== '' ? $("[data-properties=papan-logo]").val() : '-' ,
"Foto Alamat": $("[data-properties=foto-alamat]").val() !== '' ? $("[data-properties=foto-alamat]").val() : '-' ,
"Province": $("#province").val() !== '' ? $("#province").val() : '-' ,
"Country": $("#properties-kota-pengiriman-country").val() !== '' ? $("#properties-kota-pengiriman-country").val() : '-' ,
"Shipping": $("#properties-shipping").val() !== '' ? $("#properties-shipping").val() : '-' ,
"Company": $("[data-properties=company]").val() !== '' ? $("[data-properties=company]").val() : '-' ,
"id": $("#properties-time").val() !== '' ? $("#properties-time").val() : '-',
"type": 'product'
}
const props = await propItems()
properties = {...mainProps, ...props };
const id = $("#productSelect").find('option:selected').val()
console.log(id, 'main ID')
const mainItem = {
id: Number(id),
quantity: 1,
properties
}
items.push(mainItem)
const cardId = $("#itemCards").find(".selected input").val()
const cardItem = {
id: Number(cardId),
quantity: 1,
properties: { "id": $("#properties-time").val() !== '' ? $("#properties-time").val() : '-', type: 'card' }
}
console.log(cardId, 'cardId')
if(cardId) {
items.push(cardItem)
}
const addon = await addons()
if(addon) {
for(let i = 0; i < addon.length; i++){
items.push({
id: addon[i].id,
quantity: addon[i].quantity,
properties: addon[i].properties
})
}
}
const addItems = await additem(items)
console.log(addItems.items, 'add items')
if(addItems) {
$(this).find("span").removeClass("loading")
disablePopup()
showPopupCart(addItems.items)
localStorage.setItem("items", JSON.stringify(addItems.items))
}
})
$("#addtocart-cart .btn").click(async function(){
const id = $("#productSelect").find('option:selected').val()
const mainProps = {
id: $("#properties-time").val() !== '' ? $("#properties-time").val() : '-',
type: 'product'
}
const props = await propItems()
const properties = { ...mainProps, ...props };
const items = {
id: Number(id),
quantity: 1,
properties
}
const addItems = await additem(items)
if(addItems) {
showPopupCart(addItems.items)
localStorage.setItem("items", JSON.stringify(addItems))
}
})
$(".formAddressPurchase [required]").change(function(){
const t = $(this)
const p = t.parent()
const v = t.val()
if(v !== '') {
p.removeClass("error")
}
})
$("#save-card").click(async function(){
const parent = $(this).parents(".sectionPurchase")
const next = parent.next(".sectionPurchase")
$(this).find("span").addClass("loading")
const card = await saveCard()
console.log(card, 'ssaveCCC')
if(card?.status === 200 || card?.status === 201) {
$(".scanCard").removeClass("hide")
$(this).find("span").removeClass("loading")
parent.addClass("hide")
next.removeClass("hide")
if(next.hasClass("purchaseAddon")) {
$("[data-addon=upsell-all]").click()
console.log("clarity event addons")
window.clarity("event", `${productType} add-ons`)
// Ensure addon items are loaded when entering addon popup
setTimeout(function() {
if($("#itemAddons .row").children().length === 0 || $("#itemAddons .row").text().includes("No Item available")) {
$("[data-addon=upsell-all]").trigger("click")
}
}, 100)
}
if(next.hasClass("purchaseAddress")) {
$("#zip").select2()
}
}
})
$("#skip-card").click(async function(){
$("#greetingCard [data-properties]").val("")
$("#properties-photo").val("")
$("#properties-video").val("")
const parent = $(this).parents(".sectionPurchase")
const next = parent.next(".sectionPurchase")
parent.addClass("hide")
next.removeClass("hide")
// $("#itemCards").html("")
removeImage()
removeVideo()
if(next.hasClass("purchaseAddon")) {
$("[data-addon='upsell-all']").click()
console.log("clarity event addons")
window.clarity("event", `${productType} add-ons`)
// Ensure addon items are loaded when entering addon popup
setTimeout(function() {
if($("#itemAddons .row").children().length === 0 || $("#itemAddons .row").text().includes("No Item available")) {
$("[data-addon='upsell-all']").trigger("click")
}
}, 100)
}
if(next.hasClass("purchaseAddress")) {
$("#zip").select2()
}
})
$("#msgCard").click(async function(){
$(this).parent().addClass("loading")
let occasion = $(".selected[data-occassion]").data("occassion")
occasion = occasion?.replace("greeting-card-", "")
const { data } = await getFetch(`${host}/api/card/template/occasion?name=${occasion}`);
const d = data?.data
for(let i = 0; i < d.length; i++) {
const num = Math.floor(Math.random() * (d.length - 1 + 1) + 1);
const greeting = d[num]?.Greeting
$(".greetingCard textarea").val(greeting)
$(this).parent().removeClass("loading")
}
$("#save-card").attr("disabled", false)
})
$(".sectionPurchaseBoard .next-purchase-button").click(function(){
const parent = $(this).parents(".sectionPurchase")
const next = parent.next(".sectionPurchase")
parent.addClass("hide")
next.removeClass("hide")
})
$("#editCard").click(function(){
$(".custom-card").show()
$(".preview-card").hide()
})
$("#first_name, #last_name").change(function(){
const v = $(this).val()
const first_name = $("#first_name").val()
const last_name = $("#last_name").val() !== '' ? ' ' + $("#last_name").val() : ''
$("[data-properties=nama-penerima]").val(first_name+last_name)
})
$("[data-occassion]").click(function(){
const t = $(this)
const p = t.parents(".sectionPurchase")
// $(".greetingCard").addClass("disabled")
const occasion = t.data("occassion")
loadItemOccasion(t, occasion)
})
$("#itemCards").delegate(".item-card:not(.item-without-card) label", "click", function(){
const id = $(this).parent(".item-card").data("id")
const t = $(this).parent(".item-card")
const target = t.find("input")
const v = $('.item-card input[type="radio"]:checked').val();
$("#itemCards .item-card").removeClass("selected")
t.addClass("selected")
$("#itemCards .item-card").find("input").attr("name", "")
if(target.length > 0) {
target.attr("name", "id[]")
$("#properties-card").val(id)
$(".greetingCard").removeClass("disabled")
$("#skip-card").attr("disabled", false)
} else {
$("#properties-card").val("")
}
})
$("#itemCards").delegate(".item-without-card label", "click", function(){
const parent = $(this).parents(".sectionPurchase")
const next = parent.next(".sectionPurchase")
$(".greetingCard").addClass("disabled")
parent.addClass("hide")
next.removeClass("hide")
$("[data-addon=upsell-all]").click()
$("#zip").select2()
})
$("[data-properties=ucapan]").keyup(function(){
const v = $(this).val()
const p = $(this).parents(".sectionPurchase")
$(".purchaseAddress").find(".greetingCard textarea").val(v)
if(v.length > 3) {
p.find(".next-purchase-button").attr("disabled", false)
} else {
p.find(".next-purchase-button").attr("disabled", true)
}
})
$("[data-properties=penerima]").keyup(function(){
const v = $(this).val()
$(".purchaseAddress").find("[data-properties=penerima]").val(v)
})
$("[data-properties=pengirim]").keyup(function(){
const v = $(this).val()
$(".purchaseAddress").find("[data-properties=pengirim]").val(v)
})
$(document).click(function(e){
if($(e.target).closest('.wrapperPopupCart').length != 0) return false;
// $('#popupCart').fadeOut('slow');
// location.reload()
});
$(".toggleAddonCart").click(function(){
const p = $(this).parent(".itemAddonCart")
p.toggleClass("open")
})
$(".btnViewCart").click(function(){
window.location.href = "https://outerbloom.com/cart";
})
$(".btnViewCheckout").click(async function(){
$(this).find("span").addClass("loading")
let zip = $("#zip").val()
const first_name = $("#first_name").val()
const last_name = $("#last_name").val()
const company = $("#company").val() !== '' ? $("#company").val() : ''
const address1 = $("#delivery_address").val()
const address2 = zip && zip !== '' ? zip?.split(' - ')[1] : ''
zip = zip && zip !== '' ? zip?.split(' - ')[0] : ''
const phone = $("#recipient_number").val()
const city = $("#cities").val()
const province = $("#province").val()
const country = 'Indonesia'
const ver = Date.parse(new Date())
const params = `checkout[email]=&checkout[shipping_address][first_name]=${first_name}&checkout[shipping_address][last_name]=${last_name}&checkout[shipping_address][company]=${company}&checkout[shipping_address][address1]=${address1}&checkout[shipping_address][address2]=${address2}&checkout[shipping_address][city]=${city}&checkout[shipping_address][country]=${country}&checkout[shipping_address][province]=${province}&checkout[shipping_address][zip]=${zip}&checkout[shipping_address][phone]=${phone}&v=${ver}`
const clear = await fetch(`/cart/clear.js`, {method: 'POST'})
if(clear.status === 200) {
const savedItem = window.localStorage.getItem("items");
const items = JSON.parse(savedItem)
const addItems = await additem(items)
console.log(addItems, 'new addItems')
if(addItems) {
window.location.href = `https://outerbloom.com/checkout?${params}`;
}
}
})
$(".btnContinueShopping").click(function(){
window.location.href = "https://outerbloom.com/";
})
if (isIOS) {
$(".empty-state-card").click(function(){
$("#input-foto").trigger("click")
})
$(".btn-upload-image").click(function(){
$("#input-foto").trigger("click")
})
$("[for=input-video]").click(function(){
$("#input-video").trigger("click")
})
$(".btn-upload-papan").click(function(){
$("#logoPapan").trigger("click")
})
}
$("[data-properties]").each(function(){
const select = $(this).parents(".form-group").find("select")
$(this).change(function(){
const name = $(this).data("properties")
const v = $(this).val()
if (name == 'telepon-penerima') {
let phone = v.replace(/[^0-9]/g, '')
$(this).val(phone);
$("#properties-telepon-penerima").val(phone)
$('.iti__search-input').val('-')
} else {
$("#properties-" + name).val(v)
}
})
select.on("change", function(){
const name = $(this).data("properties")
const v = $(this).val()
$("#properties-" + name).val(v)
})
})
$("#show_note").click(function(){
nameq = $("#properties-nama-penerima").val()
dear = $("#properties-kartu-nama-penerima").val()
card = $("[data-properties=ucapan]").val()
sender = $("#properties-kartu-nama-pengirim").val()
photo = $("#properties-photo").val()
video = $("#properties-video").val()
updateCard(nameq, dear, card, sender, photo, video, status)
})
$(".remove-image").click(function(e){
e.preventDefault()
$(this).find("img").show()
removeImage()
})
$(".remove-media").click(function(e){
e.preventDefault()
$(this).find("img").show()
removeVideo()
})
$("[data-delivery_method]").click(function(e){
e.preventDefault()
const t = $(this)
const data = t.data("delivery_method")
$("[data-delivery_method]").removeClass("selected")
t.addClass("selected")
$("#cities").val("")
$("#properties-delivery-date").val("-")
$("#deliveryDate button").removeClass("selected")
$("#full-date").val("Full Calendar →")
$("#propDeliveryDate").val("")
const step3 = $("#step-3")
if(data.match('PickUp')) {
$(".selfpickup-point").show()
step3.find("[data-finished=false]").hide()
$("#panel-4").hide()
step3.find("[data-finished=true]").show()
$("#cities").attr("required", false)
$("#form-group-city").hide()
$("#row-delivery-time").hide()
$("#propDeliveryTime, #properties-delivery-time, #properties-nama-penerima, #properties-alamat-penerima, #properties-kodepos, #properties-kodepos, #properties-telepon-penerima").val("-")
$("#propDeliveryTime").attr("required", false)
// $("#deliveryDate").find("button:first-child").addClass("stop")
$(".form-selfpickup").show()
$(".form-delivery").hide()
$(".form-delivery").find("input, textarea, select").val("")
$(".form-delivery").find("input, textarea, select").attr("required", false)
$("#properties-shipping").val("0")
$("#noteDeliveryDate").hide()
$(".form-delivery .form-control").attr("required", false)
$("#stepNav4").hide()
$("#deliveryDate").find("button:nth-child(1)").addClass("stop")
if(timeOfDay >= 16.01){
$("#deliveryDate").find("button:nth-child(2)").addClass("stop")
}
} else {
$("#deliveryDate").find("button:nth-child(1)").removeClass("stop")
step3.find("[data-finished=false]").show()
$("#panel-4").show()
step3.find("[data-finished=true]").hide()
$("#cities").attr("required", true)
$(".selfpickup-point").hide()
$("#form-group-city").show()
$("#cities").val('').trigger('change');
$("#properties-kota-pengiriman").val("-")
$("#row-delivery-date, #row-delivery-time").show()
$("#propDeliveryDate, #propDeliveryTime").attr("required", true)
$("#deliveryDate").find("button").removeClass("stop")
$(".form-selfpickup").hide()
$(".form-delivery").show()
$(".form-delivery").find("input, textarea, select").attr("required", true)
$(".form-delivery [data-properties]").attr("readonly", false)
$("#properties-kodepos").val("-")
$("#properties-alamat-penerima").val("-")
$(".form-delivery .form-control").attr("required", true)
$(this).parents(".setup-content").attr("id", "step-1")
$("#stepNav4").show()
}
})
$("[name=selfpickup]").click(function(){
const p = $(this).parents(".row-pickup")
const pickupCity = $("input[name='selfpickup']:checked").val();
const pickupAddress = $("input[name='selfpickup']:checked").data("address");
const pickupZip = $("input[name='selfpickup']:checked").data("zip");
$(".row-pickup").removeClass("selected")
p.addClass("selected")
$("#properties-kota-pengiriman").val(pickupCity)
$("#province").val("Jakarta")
$("#properties-alamat-penerima").val(pickupAddress)
$("#properties-kodepos").val(pickupZip)
})
$("#cities").change(function(e){
e.preventDefault()
$(this).parent(".row").find("p.error").remove()
$("#full-date").val("Full Calendar")
$("#deliveryDate, #deliveryDateFull label ").show()
$("#deliveryDateFull").removeClass("filled")
$(".btnChangeDeliveryDate").addClass("hide")
$("#full-date").prop('disabled', false);
$("#stepNav2, #stepNav3, #stepNav4").removeClass("btn-success")
$("#stepNav2, #stepNav3, #stepNav4").find("a").attr("disabled", true)
const step3 = $("#step-3")
$("#cityNote").remove()
$("#noteDeliveryDate").hide()
$("#noteDeliveryDate").empty()
let v = $(this).val()
let v2 = $('option:selected', this).attr('data-city');
let v3 = $('option:selected', this).attr('data-province');
let price = $('option:selected', this).attr('data-price');
$("#country").val(v)
$("#properties-kota-pengiriman").val(v)
$("#properties-shipping").val(price)
$("#deliveryDate button, #deliveryTime button, .calendarseasonal .button").removeClass("selected")
$("#properties-delivery-date, #properties-delivery-time").val("-")
$("#propDeliveryDate, #propDeliveryTime").val("")
let note = $('option:selected', this).attr('data-note');
if(v === 'Kota Lainnya') {
$("#noteDeliveryDate").show()
$("#noteDeliveryDate").text("Order akan segera dikirim. Estimasi tanggal diterima akan disesuaikan dengan waktu pengiriman oleh pihak ekspedisi ke lokasi Anda.")
$("#zip").attr("required", false)
$("#zip").hide()
$("#propDeliveryDate, #propDeliveryTime").attr("required", false)
$("#propDeliveryDate, #properties-delivery-date, #propDeliveryTime, #properties-delivery-time").val("-")
$("#row-delivery-date, #row-delivery-time").hide()
$("#properties-shipping").val("")
// $(this).parents(".setup-content").attr("id", "step-2")
} else {
$("#noteDeliveryDate").hide()
$("#zip").attr("required", true)
$("#zip").show()
$("#row-delivery-date, #row-delivery-time").show()
$("#propDeliveryDate, #propDeliveryTime").attr("required", true)
$("#deliveryDate").find("button").removeClass("stop")
// $(this).parents(".setup-content").attr("id", "step-1")
}
// if(v !== 'Jakarta') {
// $("[data-type=upsell]").hide()
// } else {
// $("[data-type=upsell]").show()
// }
// $('.collection-addons')[0].swiper.update();
getProvince(v)
$("#zip").html(`
Choose Postal Code `)
renderZip(v, v2, v3)
disabledSameDay()
if(v !== 'Jakarta' && v !== 'Depok' && v !== 'Bekasi' && v !== 'Tangerang') {
$("#cardOccasion, #navAddon, .collection-addons").hide()
$("[data-addon=giftcard]").show()
$("[data-addon=giftcard]").click()
$("#itemAddons").show()
$("#flower-step").addClass("nonjadetabek")
} else {
$("#cardOccasion, #navAddon, .collection-addons").show()
$("[data-addon=all]").click()
$("#flower-step").removeClass("nonjadetabek")
}
if(v !== '') {
$("#personalizeBtn .btn").attr("disabled", false)
} else {
$("#personalizeBtn .btn").attr("disabled", true)
}
})
$("#zip").change(function(e){
let v = $(this).val()
var city = $("#cities").find('option:selected');
$("#properties-kodepos").val(v)
if(city === 'Kota Lainnya') {
$(this).attr("required", true)
$("#recipient-address").val("")
}
})
var minDate = +7
$("#full-date").datepicker({
minDate,
dateFormat: 'Mdd_yy', //Nop22_2021,
beforeShowDay: disabledays,
onSelect: function (date) {
$("#deliveryDate, #deliveryDateFull label ").hide()
$("#deliveryDateFull").addClass("filled")
$(".btnChangeDeliveryDate").removeClass("hide")
$("#full-date").prop('disabled', true);
$('#propDeliveryDate, #properties-delivery-date').val('Kirim_'+date);
$(".date-full").addClass("selected")
$(".date-single, .calendar-group").removeClass("selected")
$("#propDeliveryTime").val('')
$("#properties-delivery-time").val('-')
$(".time-single").removeClass("selected")
}
});
$(".btnChangeDeliveryDate").click(function(){
$("#deliveryDate, #deliveryDateFull label ").show()
$("#deliveryDateFull").removeClass("filled")
$(".btnChangeDeliveryDate").addClass("hide")
$("#full-date").prop('disabled', false);
})
$("#deliveryDate").delegate(".calendarbutton:not(.date-full)", "click", function(e){
e.preventDefault()
$(this).parents("#row-delivery-date").find("p.error").remove()
const fulldate = $(this).data("fulldate")
const day = $(this).data("day")
const date = $(this).data("date")
const month = $(this).data("month")
const year = $(this).data("year")
const off_pagi = $(this).data("offpagi")
const off_siang = $(this).data("offsiang")
const off_Malam = $(this).data("offMalam")
$(".calendarbutton").removeClass("selected")
$(this).addClass("selected")
$("#propDeliveryDate, #properties-delivery-date").val(`Kirim_${month}${date}_${year}`)
$("#propDeliveryTime").val('')
$("#properties-delivery-time").val('-')
$(".calendarbutton2").removeClass("selected")
$("#full-date").val("Full Calendar")
if(off_pagi && timeOfDay > off_pagi) {
$("[data-time=Morning]").attr("disabled", true)
} else {
$("[data-time=Morning]").attr("disabled", false)
}
if(off_siang && timeOfDay > off_siang) {
$("[data-time=Afternoon]").attr("disabled", true)
} else {
$("[data-time=Afternoon]").attr("disabled", false)
}
})
if(today === 14 && timeOfDay > 17.00) {
$("#deliveryDate button:first-child").attr("disabled", true)
}
$("#deliveryTime").delegate(".calendarbutton2", "click", function(e){
e.preventDefault()
const time = $(this).data("time")
const date = $("#propDeliveryDate").val()
if(date == '') {
return alert('Silakan pilih tanggal terlebih dahulu')
}
$(".calendarbutton2").removeClass("selected")
$(this).addClass("selected")
$("#propDeliveryTime, #properties-delivery-time").val(`KirimJam_${date.replace('Kirim_','')}_${time}`)
})
$('textarea.has-limit, input.has-limit').keyup(function () {
max = this.getAttribute("maxlength");
let len = $(this).val().length;
let limit = $(this).siblings(".limit");
if (len > max) {
alert('you have reached the limit');
} else {
limit.text(`${len}/${max}`);
}
});
$("#button-action-step .btn").click(function(){
$(this).find("span").text("Processing...");
});
$(".finishBtn").on('click', function() {
$(this).addClass("is-adding");
// $(this).click();
});
$('.setup-panel .nav-item a.btn-success').trigger('click');
$("#button-action .btn").click(function(){
$("#flower-step").addClass("block");
$("#button-action").hide();
});
$(".close-how-order").click(function(){
$("#flower-step").removeClass("block");
$("#button-action").show();
});
$("#input-foto, #input-video").change(function(e){
readURL(this);
});
$("#logoPapan").change(function(){
readURLPapan(this);
});
$("#address-upload").change(async function(){
const upload_address = await readURLAddress(this)
if(upload_address) {
const url = upload_address.url
$(".props-address-upload").val(url)
$(".form-address").addClass("address-uploaded")
$(".form-address-upload").addClass("uploaded")
$(this).parents(".form-group").siblings(".form-group").find("[required]").attr("required", false)
}
})
$(".address-manualy").click(function(){
$(".form-address-upload").removeClass("uploaded");
$(".photo-address").hide();
$(".form-address").removeClass("address-uploaded")
$("#formAddressPurchase").find(".form-control").attr("required", true)
});
$(".case-video-preview").delegate(".replace-video", "click", function(){
$("#input-video").trigger("click")
})
$('.date-single').click(function(e) {
e.preventDefault();
$('.date-single').removeClass('selected');
$('#full-date').removeClass('selected');
$(this).addClass('selected');
$('#full-date').html('Full' + '
' + 'Calendar');
});
$('#full-date').click(function(e){
e.preventDefault();
$('.date-single').removeClass('selected');
$(this).addClass('selected');
});
// $("tr").each(function(){
// if($(this).text().match('SKU')) {
// $(".sku-product").html($(this).parents("table").html())
// }
// })
$("#product-image").scroll(function(){
$(".desc-add").each(function(){
const img = $(this).find("img")
const src = img.data("src")
img.attr("src", src)
})
})
$(".product-fixed").hide()
let target = $("#personalizeBtn")
$(".product-meta").scroll(function() {
if ($(window).scrollTop() >= target.offset().top ) {
$(".product-fixed").addClass("show")
} else {
$(".product-fixed").removeClass("show")
}
});
$(window).scroll(function() {
if ($(window).scrollTop() >= target.offset().top ) {
$(".product-fixed").addClass("show")
} else {
$(".product-fixed").removeClass("show")
}
});
});