HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/deensekroon.komma-mediadesign.nl/wwwroot/js/checkout.js
// Define objects
var $opc = $('#opc');
var $shippingForm = $('.shipping_form');
var $accountForm = $('.account_form');
var $loginForm = $('.opc_login_holder');

var $billingCountry = $("#country");
var $shippingCountry = $("#shipping_country");

var $shippingMethod = $('input[name="shippingMethod"]');


// if we are on the checkout page
if($opc.size() > 0)
{
    opc_init();
}

// Initialize
function opc_init()
{
    // Toggle forms
    opc_initHiddenForms();

    // Update shipping costs
    opc_updateShippingCosts();

    // Summary
    opc_postOrderSummary();

    // Init discount section
    opc_postDiscount();

    // Init submit login
    opc_initSubmitLogin();

    // Controler enter button
    opc_controlEnterButton();
}

/*
 * Toggle Shipping form and account form
 */
function opc_initHiddenForms()
{
    var iso, country;

    // Toggle Shipping
    $shippingMethod.change(function()
    {
        if($(this).val() != 'shipToShippingAddress')
        {
            $shippingForm.stop().animate({ height: 0 },200);

            if($(this).val() == 'shipToBillingAddress')
            {
                // Update shipping costs -> set to billing country
                iso = $billingCountry.val();
                country = $('#country option:selected').text();
            }
            else if($(this).val() == 'pickUpFromShopEindhoven')
            {
                iso = 'shop';
                country = 'eindhoven';
            }

            opc_postShippingCountry(iso,country);
        }
        else
        {
            var h = $('.inner',$shippingForm).height();
            $shippingForm.stop().animate({ height: h + 'px' },200);

            // Update shipping costs -> set to shipping country
            iso = $shippingCountry.val();
            country = $('#shipping_country option:selected').text();
            opc_postShippingCountry(iso,country);
        }
    });

    $('#create_account').change(function()
    {
        if($(this).prop('checked'))
        {
            var h = $('.inner',$accountForm).height();
            $accountForm.stop().animate({ height: h + 'px' },200);
        }
        else
        {
            $accountForm.stop().animate({ height: 0 },200);
        }
    });

    $('.open_login').click(function()
    {
        if($loginForm.height() == 0)
        {
            var h = $('.inner',$loginForm).outerHeight();
            $loginForm.stop().animate({ height: h + 'px' },200);
        }
        else
        {
            $loginForm.stop().animate({ height: 0 },200);
        }
    });
}

/*
 *
 */
function opc_updateShippingCosts()
{
    var iso, country;
    switch($('input[name="shippingMethod"]:checked').val())
    {
        case 'shipToBillingAddress':
            // Update shipping costs -> set to billing country
            iso = $billingCountry.val();
            country = $billingCountry.children('option:selected').text();
            break;

        case 'shipToShippingAddress':
            // Update shipping costs -> set to shipping country
            iso = $shippingCountry.val();
            country = $shippingCountry.children('option:selected').text();
            break;

        case 'pickUpFromShopEindhoven':
            iso = 'shop';
            country = 'eindhoven';
            break;
    }
    opc_postShippingCountry(iso,country);

    // Shipping Country
    $billingCountry.change(function()
    {
        var iso = $(this).val();
        var country = $('#country option:selected').text();

        // Make sure where shipping to billing address
        if($('input[name="shippingMethod"]:checked').val() == 'shipToBillingAddress')
        {
            opc_postShippingCountry(iso,country);
        }
    });

    // Shipping Country
    $shippingCountry.change(function()
    {
        var iso = $(this).val();
        var country = $('#shipping_country option:selected').text();

        console.log($('input[name="shippingMethod"]:checked').val());

        // Make sure where not shipping to billing address
        if($('input[name="shippingMethod"]:checked').val() == 'shipToShippingAddress')
        {
            opc_postShippingCountry(iso,country);
        }
    });
}

// Update Shipping cost
function opc_postShippingCountry(iso,country)
{
    // Make AJAX call
    $.ajax({
        url: "/toont-uw-winkelwagen/uw-gegevens/updateShipping",
        type: "post",
        data: { iso: iso, country: country },
        success: function(data)
        {
            $('.transport_holder').html(data);
            opc_postOrderSummary();
        },
        error:function(){
        }
    });
}

// Update order summary
function opc_postOrderSummary()
{
    // Make AJAX call
    $.ajax({
        url: "/toont-uw-winkelwagen/uw-gegevens/updateSummary",
        type: "post",
        data: { },
        success: function(data)
        {
            $('.order_holder').html(data);
        },
        error:function(){
        }
    });
}

// Update discount section
function opc_postDiscount()
{
    // Make AJAX call
    $.ajax({
        url: "/toont-uw-winkelwagen/uw-gegevens/updateDiscount",
        type: "post",
        data: { },
        success: function(data)
        {
            // Create form
            $('.discount_holder').html(data);

            // Set on click
            $('#checkDiscountCode').click(function()
            {
                // Check for discount
                $.ajax({
                    url: "/toont-uw-winkelwagen/uw-gegevens/checkDiscount",
                    type: "post",
                    data: { code : $('#discountCode').val() },
                    success: function(){ },
                    error:function(){ }
                });

                // Update discount output
                opc_postDiscount();

                // Update order summary
                opc_postOrderSummary();

            });

            // Set remove click
            $('.remove_discount').click(function()
            {
                $.ajax({
                    url: "/toont-uw-winkelwagen/uw-gegevens/removeDiscount",
                    type: "post",
                    data: { },
                    success: function(){ },
                    error:function(){ }
                });

                // Update discount output
                opc_postDiscount();

                // Update order summary
                opc_postOrderSummary();

            });
        /*
            // Set remove click
            $('.remove_gift_card').click(function()
            {
                $.ajax({
                    url: "/toont-uw-winkelwagen/uw-gegevens/removeGiftCard",
                    type: "post",
                    data: { id : $(this).attr('id') },
                    success: function(){  },
                    error:function(){ }
                });

                // Update discount output
                opc_postDiscount();

                // Update order summary
                opc_postOrderSummary();
            })
        */
            //
            $('#open_discount_box').click(function()
            {
                var $discountForm = $('.discount_box');

                if($discountForm.height() == 0)
                {
                    var h = $('.inner',$discountForm).outerHeight();
                    $discountForm.stop().animate({ height: h + 'px' },200);
                }
                else
                {
                    $discountForm.stop().animate({ height: 0 },200);
                }
            });
        },
        error:function(){
        }
    });
}

function opc_initSubmitLogin()
{
    $('#login_submit').click(function()
    {
        // Check for discount
        $.ajax({
            url: "/toont-uw-winkelwagen/uw-gegevens/login",
            type: "post",
            data: { login_user : $('#login_user').val(),
                    login_password : $('#login_password').val() },
            success: function(){
                window.location.href = '/toont-uw-winkelwagen/uw-gegevens';
            },
            error:function(){
                window.location.href = '/toont-uw-winkelwagen/uw-gegevens';
            }
        });
    });
}



function opc_controlEnterButton()
{
    $(document.body).delegate('#discountCode', 'keypress', function(e) {
        console.log(e.which );
        if (e.which === 13 || e.which === 0  || e.which === 9) { // if is enter or tab
            e.preventDefault(); // don't submit form

            // Check for discount
            $.ajax({
                url: "/toont-uw-winkelwagen/uw-gegevens/checkDiscount",
                type: "post",
                data: { code : $('#discountCode').val() },
                success: function(){ },
                error:function(){ }
            });

            // Update discount output
            opc_postDiscount();

            // Update order summary
            opc_postOrderSummary();

        }
    });


    $(document.body).delegate('#login_user', 'keypress', function(e) {
        console.log(e.which );
        if (e.which === 13) { // if is enter or tab
            e.preventDefault(); // don't submit form

            // Check for discount
            $.ajax({
                url: "/toont-uw-winkelwagen/uw-gegevens/login",
                type: "post",
                data: { login_user : $('#login_user').val(),
                    login_password : $('#login_password').val() },
                success: function(){
                    window.location.href = '/toont-uw-winkelwagen/uw-gegevens';
                },
                error:function(){
                    window.location.href = '/toont-uw-winkelwagen/uw-gegevens';
                }
            });
        }
    });

    $(document.body).delegate('#login_password', 'keypress', function(e) {
        console.log(e.which );
        if (e.which === 13) { // if is enter or tab
            e.preventDefault(); // don't submit form

            // Check for discount
            $.ajax({
                url: "/toont-uw-winkelwagen/uw-gegevens/login",
                type: "post",
                data: { login_user : $('#login_user').val(),
                    login_password : $('#login_password').val() },
                success: function(){
                    window.location.href = '/toont-uw-winkelwagen/uw-gegevens';
                },
                error:function(){
                    window.location.href = '/toont-uw-winkelwagen/uw-gegevens';
                }
            });
        }
    });

}