<script>
document.addEventListener('DOMContentLoaded', function() {
function parsePrice(price) {
return parseInt(price.replace(',', ''))
}
{% if Product is defined %}
$('.open-one-touch').on('click', function(event){
const customer = "{{ Customer }}";
const postal_code = "{{ Customer.postal_code ?? '' }}"
if(!customer){
window.location.replace("{{ url('shopping_login') }}")
$('.background_popup').css('display','none');
}
else if(postal_code == "0000000"){
let product_id = $('#product_id_change').val();
window.location.replace(`{{ url('mypage_change') }}?product=${product_id}`)
$('.background_popup').css('display','none');
console.log("pref is null");
}else{
const formatPrice = Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' });
loadingPayment();
$('.content').text('注文確認中');
$form = $('#form1');
var stripe_payment_method_id = "{{ PaymentDefault ? PaymentDefault.id : null }}"
var stripe_customer_id = "{{ StripeCustomer ? StripeCustomer.getStripeCustomerId : null }}"
let paymentData = $form.serialize()
/// hotfix 20240122 quantity
var newQuantity = document.getElementById("quantity").value;
var params = paymentData.split("&");
for (var i = 0; i < params.length; i++) {
if (params[i].startsWith("quantity=")) {
params[i] = "quantity=" + newQuantity;
}
}
paymentData = params.join("&");
let isloading = false
paymentData += `&is_one_touch_payment=1`
$.ajax({
url: $('.open-one-touch').attr('data-url'),
type: $form.attr('method'),
data: paymentData,
success: function (data) {
if (data.done) {
let order = data.Order
let ordertId = order.order_id;
let shipping = order.shipping;
$('.modal_onetouch_payment').attr("data-form",'1');
$('#ec-price__price').text(formatPrice.format(order.price));
$('#ec-productTitle').text(order.product_name);
$('.product-image-order').attr('src',order.main_image);
if (order.discount != 0) {
$('.has-discount').show();
$('#ec-price__price').text(formatPrice.format(order.price - (order.price * order.discount_rate)/100));
$('#discount_rate').text("初回 " + order.discount_rate + " %OFF");
$('#price').text(formatPrice.format(order.price));
$('#ec-price__tax-point').text("(Pt" + order.pt + ")");
}else{
$('.has-discount').hide();
}
$('#onetouch_discount').text(formatPrice.format( 880 + parsePrice(order.pt_family_benefits) ));
$('#bg_detail_discount').text(formatPrice.format( 880 + parsePrice(order.pt_family_benefits) ));
$('#pt_normal').text(parseInt(order.pt) );
$('#pt_family_benefits').text(parseInt(order.pt) + parsePrice(order.pt_family_benefits) );
$('#bg_detail_bonus').text(parsePrice(order.pt_family_benefits));
$('#bg_detail_bonus_y').text(formatPrice.format( parsePrice(order.pt_family_benefits) ));
$('.normal-bonus-value').text(order.pt);
$('.kg-bonus-value').text(order.pt_family_benefits);
let full_price = order.subtotal - order.discount;
$('#productRole_totalPayment').text(formatPrice.format(order.payment_total));
$('#productRole_totalPayment').attr("total",order.payment_total);
$('#productRole_totalPayment').attr("delivery",order.delivery_fee_total);
$('#full_total').text(formatPrice.format(full_price));
$('#delivery_total').text(formatPrice.format(order.delivery_fee_total));
$('#payment_total').text(formatPrice.format(order.payment_total));
$('#add_pt').text(order.add_point);
/// hotfix 20240122 quantity
if(order.sale_type)
$('.promo_code_box').css("display","none")
else
$('.promo_code_box').css("display","block")
{% if Product.regular_product_id == 522 or Product.regular_product_id == 814 %}
$('.no-member-info').css("display", "none");
{% endif %}
$('#productRole_quantity').text(order.quantity);
if(shipping.name01 != 'ゲスト'){
$('.ec-addressCustomer').text(shipping.name01+shipping.name02+' ('+shipping.kana01+shipping.kana02+') 様'+' 〒'+shipping.postal_code+ ' ' + shipping.pref +shipping.addr01+shipping.addr02+' '+shipping.phone_number);
$('.show_update_shipping').attr("data-id", shipping.id)
}else{
$('.ec-addressCustomer').text("固定お届け先がありません。")
}
$('#order_id').val(ordertId);
$('#order_id').attr("data-regular",'0');
showModal();
closeLoading();
closePopup()
isloading = false
} else {
closePopup()
showError();
window.location.replace("{{ url('shopping_error') }}")
}
},
error: function () {
showError();
window.location.replace("{{ url('shopping_error') }}")
}
})
$('.background_popup').css('display','block');
/// hotfix 20240122 quantity
let quantity = newQuantity;
}
})
const regular_product_id = "{{ Product.regular_product_id ?? 'null' }}";
const regular_variant = "{{ Product.is_variant ? 1 : 0}}";
if (regular_product_id != 'null' || regular_variant == 1) {
$('.open-one-touch-related-product').on('click', function(event){
const customer = "{{ Customer }}";
const postal_code = "{{ Customer.postal_code ?? '' }}"
if(!customer){
window.location.replace("{{ url('shopping_login') }}")
$('.background_popup').css('display','none');
}else if(postal_code == '0000000'){
let regular_product_id = this.getAttribute('data-id');
let product_id = $('#product_id_change').val();
window.location.replace(`{{ url('mypage_change') }}?product=${product_id}®ular_product_id=${regular_product_id}`)
$('.background_popup').css('display','none');
console.log("pref is null");
}
else{
const formatPrice = Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' });
loadingPayment();
$('.content').text('注文確認中');
$form = $('#form2');
var stripe_payment_method_id = "{{ PaymentDefault ? PaymentDefault.id : null }}"
var stripe_customer_id = "{{ StripeCustomer ? StripeCustomer.getStripeCustomerId : null }}"
if($('#product_relate_id')){
let product_id = $('#product_relate_id').val()
}
let formToString = $form.serialize()
let paymentId = $(this).attr('data-id');
let urlForm;
let newQuantity;
var params = formToString.split("&");
var paymentData;
if(regular_variant == 1){
const url = '{{ url('one_touch_payment', {id:Product.regular_product_id ?? 1}) }}';
const newUrl = url.split('/', 5).join('/') + '/' + paymentId;
urlForm = newUrl;
newQuantity = document.querySelector(".variant_regular_"+ paymentId +" #regular-quantity").value;
params = params.filter(param => !param.startsWith("quantity=") && !param.startsWith("direct_shopping="));
paymentData = params.join("&");
paymentData += `&quantity=`+ newQuantity;
}else{
urlForm = '{{ url('one_touch_payment', {id:Product.regular_product_id ?? 1}) }}'
newQuantity = document.getElementById("{{ Product.regular_product_id ? 'regular-quantity' : 'quantity' }}").value;
for (var i = 0; i < params.length; i++) {
if (params[i].startsWith("quantity=")) {
params[i] = "quantity=" + newQuantity;
break;
}
}
paymentData = params.join("&");
}
/// hotfix 20240122 quantity
let isloading = false
paymentData += `&is_one_touch_payment=1&direct_shopping=1`;
$.ajax({
url: urlForm,
type: $form.attr('method'),
data: paymentData,
success: function (data) {
if (data.done) {
$('.modal_onetouch_payment').attr("data-form",'2');
let order = data.Order;
let ordertId = order.order_id;
let shipping = order.shipping;
$('#ec-price__price').text(formatPrice.format(order.price));
$('#ec-productTitle').text(order.product_name);
$('.product-image-order').attr('src',order.main_image);
if (order.discount != 0) {
$('#ec-price__price').text(formatPrice.format(order.price - (order.price * order.discount_rate)/100));
$('.has-discount').show();
$('#discount_rate').text("初回 " + order.discount_rate + " %OFF");
$('#price').text(formatPrice.format(order.price));
$('#ec-price__tax-point').text("(Pt" + order.pt + ")");
} else {
$('.has-discount').hide();
}
$('#onetouch_discount').text(formatPrice.format( 880 + parsePrice(order.pt_family_benefits) ));
$('#bg_detail_discount').text(formatPrice.format( 880 + parsePrice(order.pt_family_benefits) ));
$('#pt_normal').text(parseInt(order.pt) );
$('#pt_family_benefits').text(parseInt(order.pt) + parsePrice(order.pt_family_benefits) );
$('#bg_detail_bonus').text(parsePrice(order.pt_family_benefits) );
$('#bg_detail_bonus_y').text(formatPrice.format( parsePrice(order.pt_family_benefits) ));
$('.normal-bonus-value').text(order.pt);
$('.kg-bonus-value').text(order.pt_family_benefits);
$('#productRole_totalPayment').text(formatPrice.format(order.payment_total));
$('#productRole_totalPayment').attr("total",order.payment_total);
$('#productRole_totalPayment').attr("delivery",order.delivery_fee_total);
let full_price = order.subtotal - order.discount;
$('#full_total').text(formatPrice.format(full_price));
$('#delivery_total').text(formatPrice.format(order.delivery_fee_total));
$('#payment_total').text(formatPrice.format(order.payment_total));
$('#add_pt').text(order.add_point);
$('#productRole_quantity').text(order.quantity);
if(order.sale_type)
$('.promo_code_box').css("display","none")
else
$('.promo_code_box').css("display","block")
{% if Product.regular_product_id == 522 or Product.regular_product_id == 814 %}
$('.no-member-info').css("display", "none");
{% endif %}
if(shipping.name01 != 'ゲスト'){
$('.ec-addressCustomer').text(shipping.name01+shipping.name02+' ('+shipping.kana01+shipping.kana02+') 様'+' 〒'+shipping.postal_code+ ' ' +shipping.addr01+shipping.addr01+' '+shipping.phone_number);
$('.show_update_shipping').attr("data-id", shipping.id)
}else{
$('.ec-addressCustomer').text("固定お届け先がありません。")
}
$('#order_id').val(ordertId);
$('#order_id').attr("data-regular",'1');
showModal();
closeLoading();
closePopup()
isloading = false
} else {
closePopup()
showError();
window.location.replace("{{ url('shopping_error') }}")
}
},
error: function () {
showError();
window.location.replace("{{ url('shopping_error') }}")
}
})
$('.background_popup').css('display','block');
let quantity = document.getElementById("quantity").value;
}
})
}
{% endif %}
$('.open-one-touch-ambassador-yearly').on('click', function(event){
const customer = "{{ Customer }}";
const postal_code = "{{ Customer.postal_code ?? '' }}"
if(!customer){
window.location.replace("{{ url('shopping_login') }}")
$('.background_popup').css('display','none');
}
else if(postal_code == "0000000"){
let product_id = $('#product_id_change').val();
window.location.replace(`{{ url('mypage_change') }}?product=${product_id}`)
$('.background_popup').css('display','none');
console.log("pref is null");
}else{
const formatPrice = Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' });
loadingPayment();
$('.content').text('注文確認中');
$form = $('#formAmabssador');
var stripe_payment_method_id = "{{ PaymentDefault ? PaymentDefault.id : null }}"
var stripe_customer_id = "{{ StripeCustomer ? StripeCustomer.getStripeCustomerId : null }}"
let paymentData = $form.serialize()
let isloading = false
paymentData += `&is_one_touch_payment=1`
$.ajax({
url: $('.open-one-touch-ambassador-yearly').attr('data-url'),
type: $form.attr('method'),
data: paymentData,
success: function (data) {
if (data.done) {
let order = data.Order
let ordertId = order.order_id;
let shipping = order.shipping;
$('.modal_onetouch_payment').attr("data-form",'1');
$('#ec-price__price').text(formatPrice.format(order.price));
$('#ec-productTitle').text(order.product_name);
$('.product-image-order').attr('src',order.main_image);
if (order.discount != 0) {
$('.has-discount').show();
$('#ec-price__price').text(formatPrice.format(order.price - (order.price * order.discount_rate)/100));
$('#discount_rate').text("初回 " + order.discount_rate + " %OFF");
$('#price').text(formatPrice.format(order.price));
$('#ec-price__tax-point').text("(Pt" + order.pt + ")");
}else{
$('.has-discount').hide();
}
$('#onetouch_discount').text(formatPrice.format( 880 + parsePrice(order.pt_family_benefits) ));
$('#bg_detail_discount').text(formatPrice.format( 880 + parsePrice(order.pt_family_benefits) ));
$('#pt_normal').text(parseInt(order.pt) );
$('#pt_family_benefits').text(parseInt(order.pt) + parsePrice(order.pt_family_benefits) );
$('#bg_detail_bonus').text(parsePrice(order.pt_family_benefits));
$('#bg_detail_bonus_y').text(formatPrice.format( parsePrice(order.pt_family_benefits) ));
$('.normal-bonus-value').text(order.pt);
$('.kg-bonus-value').text(order.pt_family_benefits);
let full_price = order.subtotal - order.discount;
$('#productRole_totalPayment').text(formatPrice.format(order.payment_total));
$('#productRole_totalPayment').attr("total",order.payment_total);
$('#productRole_totalPayment').attr("delivery",order.delivery_fee_total);
$('#full_total').text(formatPrice.format(full_price));
$('#delivery_total').text(formatPrice.format(order.delivery_fee_total));
$('#payment_total').text(formatPrice.format(order.payment_total));
$('#add_pt').text(order.add_point);
$('#productRole_quantity').text(order.quantity);
/// hotfix 20240122 quantity
if(order.sale_type)
$('.promo_code_box').css("display","none")
else
$('.promo_code_box').css("display","block")
if(shipping.name01 != 'ゲスト'){
$('.ec-addressCustomer').text(shipping.name01+shipping.name02+' ('+shipping.kana01+shipping.kana02+') 様'+' 〒'+shipping.postal_code+ ' ' + shipping.pref +shipping.addr01+shipping.addr02+' '+shipping.phone_number);
$('.show_update_shipping').attr("data-id", shipping.id)
}else{
$('.ec-addressCustomer').text("固定お届け先がありません。")
}
$('#order_id').val(ordertId);
$('#order_id').attr("data-regular",'0');
showModal();
closeLoading();
closePopup()
isloading = false
} else {
closePopup()
showError();
window.location.replace("{{ url('shopping_error') }}")
}
},
error: function () {
showError();
window.location.replace("{{ url('shopping_error') }}")
}
})
$('.background_popup').css('display','block');
}
})
$('.ec-icon').click(function(){
$('.update_shipping').addClass("hidden");
$('.modal_onetouch_payment').css('display','none');
$('.background_popup').css('display','none');
$('.modal_loading_payment').css('display','none');
$('.coundown-dialog-create-shipping').css('display','none')
$('.update_shipping').addClass("hidden");
$('.update_card').addClass("hidden");
$('.modal-order').css('display','block');
$('.coundown-dialog-create-card').css('display','none')
$('.coundown-dialog-update-card').css('display','none')
$('.modal-order').css('top','20%');
$('.modal_kg_family').addClass("hidden");
$('.modal_payment_kg').addClass("hidden");
});
function closePopup(){
$('.background_popup').click(function(){
if(isloading==false){
$('.update_shipping').addClass("hidden");
$('.modal_onetouch_payment').css('display','none');
$('.background_popup').css('display','none');
$('.modal_loading_payment').css('display','none');
$('.modal-order').css('top','20%');
$('.modal_kg_family').addClass("hidden");
$('.modal_payment_kg').addClass("hidden");
}
}
);
}
function showSuccess(){
$('.modal_loading_payment').css('display','block');
$('.loading').css('display','none');
$('.complete').css('display','block');
$('.loading').css('display','none');
$('.content').text('決済は完了しました。');
}
function showError(){
$('.modal_loading_payment').css('display','block');
$('.loading').css('display','none');
$('.error').css('display','block');
$('.complete').css('display','none');
$('.content').text('決済が失敗しました。');
isloading = true;
}
function loadingPayment(){
$('.modal_loading_payment').css('display','block');
$('.loading').css('display','block');
$('.error').css('display','none');
$('.complete').css('display','none');
$('.content').text('決済中');
}
function closeLoading(){
$('.loading').css('display','none');
$('.error').css('display','none');
$('.complete').css('display','none');
}
function showModal(){
$('.modal_onetouch_payment').css('display','block');
$('.modal_loading_payment').css('display','none');
$('.update_shipping').addClass("hidden");
$('.modal-order').css('display','block');
$('.modal-order').css('top','20%');
$('.modal_kg_family').addClass("hidden");
$('.modal_payment_kg').addClass("hidden");
}
});
</script>