WordPress

Briefly unavailable for scheduled maintenance.
Check back in a some hours.
403WebShell
403Webshell
Server IP : 38.242.244.58  /  Your IP : 216.73.216.240
Web Server : Apache/2.4.41 (Ubuntu)
System : Linux vmi1486879.contaboserver.net 5.4.0-166-generic #183-Ubuntu SMP Mon Oct 2 11:28:33 UTC 2023 x86_64
User : root ( 0)
PHP Version : 7.4.3-4ubuntu2.19
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/html/sura/public/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/sura/public/js/buy.js
// ************************************************
// Shopping Cart API
// ************************************************






var shoppingCart = (function() {
    // =============================
    // Private methods and propeties
    // =============================
    cart = [];

    // Constructor
    function Item( id,name, size, price, exclusiveLicence, count,thumb_url,isExclusive,exclusiveLicenceDuration, licenceType, suraId) {
        this.id = id;
        this.name = name;
        this.size = size;
        this.price = price;
        this.exclusiveLicence = exclusiveLicence;
        this.count = count;
        this.isExclusive = isExclusive;
        this.thumb_url = thumb_url;
        this.exclusiveLicenceDuration = exclusiveLicenceDuration;
        this.licenceType = licenceType;
        this.suraId = suraId;

        // this.size_selection='medium';
        this.exclusive_selection=false;


    }

    // Save cart
    function saveCart() {
        sessionStorage.setItem('shoppingCart', JSON.stringify(cart));
    }


    // Load cart
    function loadCart() {
        cart = JSON.parse(sessionStorage.getItem('shoppingCart'));
    }

    if (sessionStorage.getItem("shoppingCart") != null) {
        loadCart();
    }


    // =============================
    // Public methods and propeties
    // =============================
    var obj = {};

    // Add to cart
    obj.addItemToCart = function(id,name, size, price, exclusiveLicence, count,thumb_url,isExclusive,exclusiveLicenceDuration,licenceType, suraId) {
        let inCart = false;
        for(var item in cart) {

            if(cart[item].id === id) {
                // cart[item].count ++;
                // saveCart();
                //alert('Item already in cart');
                /*$('.add-to-cart-notif').text('Item already in cart!');
                $('.add-to-cart-notif').slideDown('slowly');*/
                inCart=true;

                obj.removeItemFromCart(id)

                // return;

            }
        }
        var item = new Item(id,name, size, price, exclusiveLicence, count,thumb_url,isExclusive,exclusiveLicenceDuration, licenceType, suraId);
        cart.push(item);
        saveCart();

        if (inCart){
            $('.add-to-cart-notif').text('Your shopping basket has been updated!');
            $('.add-to-cart-notif').slideDown('slowly');
        }

        return item;
    };
    // Set count from item
    obj.setCountForItem = function(id, count) {
        for(var i in cart) {
            if (cart[i].id === id) {
                cart[i].count = count;
                break;
            }
        }
    };
    // Remove item from cart
    obj.removeItemFromCart = function(id) {
        for(var item in cart) {
            if(cart[item].id === id) {
                cart[item].count --;
                if(cart[item].count === 0) {
                    cart.splice(item, 1);
                }
                break;
            }
        }
        saveCart();
    }  // Change the size selection
    obj.changeItemSizeIncart = function(id,size) {
        for(var item in cart) {
            if(cart[item].id === id) {
                //
                cart[item].size_selection=size

                break;
            }
        }
        saveCart();
    }

    // Remove all items from cart
    obj.removeItemFromCartAll = function(id) {
        for(var item in cart) {
            if(cart[item].id === id) {
                cart.splice(item, 1);
                break;
            }
        }
        saveCart();

        let offline_cart_itemz = JSON.parse(sessionStorage.getItem('offline_items'));

        let offLineItems = [];
        for (offLinrItem in offline_cart_itemz){
            if(offline_cart_itemz[offLinrItem].id !== id) {
                offLineItems.push(offline_cart_itemz[offLinrItem]);
            }
        }

        sessionStorage.setItem("offline_items", JSON.stringify(offLineItems));
        // console.log( JSON.parse(sessionStorage.getItem("offline_items")) );
        // sessionStorage.removeItem("offline_items");

        let url = $('.add-to-cart').data('remove-from-cart-url');

        $.ajax({
            url: url,
            type: "POST",
            data:{id:id},
            async: true,
            success: function (data)
            {



            }
        });


    }

    //Remove single item from basket
    obj.removeFromBasket = function(id) {
        for(var item in cart) {
            if(cart[item].id === id) {
                cart.splice(item, 1);
                break;
            }
        }
        saveCart();

        let url = $('.show-basket').data('remove-from-cart-url');

        $.ajax({
            url: url,
            type: "POST",
            data:{id:id},
            async: true,
            success: function (data)
            {
                //success
            }
        });


    }

    // Clear cart
    obj.clearCart = function() {
        cart = [];
        saveCart();
    }

    // Count cart
    obj.totalCount = function() {
        var totalCount = 0;
        for(var item in cart) {
            totalCount += cart[item].count;
        }
        return totalCount;
    };

    // Total cart
    obj.totalCart = function() {
        var totalCart = 0;
        for(var item in cart) {
            totalCart += cart[item].price * cart[item].count;
        }
        return Number(totalCart.toFixed(2));
    };

    // List cart
    obj.listCart = function() {
        var cartCopy = [];
        for(i in cart) {
            item = cart[i];
            itemCopy = {};
            for(p in item) {
                itemCopy[p] = item[p];

            }
            itemCopy.total = Number(item.price * item.count).toFixed(2);
            cartCopy.push(itemCopy)
        }
        return cartCopy;
    }

    // cart : Array
    // Item : Object/Class
    // addItemToCart : Function
    // removeItemFromCart : Function
    // removeItemFromCartAll : Function
    // clearCart : Function
    // countCart : Function
    // totalCart : Function
    // listCart : Function
    // saveCart : Function
    // loadCart : Function
    return obj;
})();


// *****************************************
// Triggers / Events
// *****************************************
// Add item
$('.add-to-cart').click(function(event) {
    event.preventDefault();

    if(!$('.price_tag:checked').val() && ! $(this).hasClass('renew_btn')){
        if($(this).hasClass('btn_royalty_free')){
            return false
        }

    }

    if($(this).hasClass('btn_right_managed') && ! $(this).hasClass('renew_btn')){
        let errors = [];

        $('.tab_pane').find('.cost_calculator').each(function () {

            if(parseInt($(this).val()) === 0)
            {
                errors.push($(this).attr('name'));

            }
        });

        if(errors.length > 0)
        {
            return false;
        }
    }

    var name = $(this).data('name');

    var id = $(this).data('id');

    var price = $(this).data('total-fee');

    if($(this).data('exclusive-licence')!==undefined)
    {
        var exclusiveLicence = $(this).data('exclusive-licence');

    }else{
        var exclusiveLicence = 'None';
    }

    if($(this).data('exclusive-licence-duration')!==undefined)
    {
        var exclusiveLicence_duration = $(this).data('exclusive-licence-duration');

    }else{
        var exclusiveLicence_duration = 'None';
    }
    //console.log( $(this).data('exclusive-licence'));
    if($(this).data('size')!==undefined)
    {
        var size = $(this).data('size');

    }else{
        var size = ' '
    }

    var licenceType=$(this).data("licence_type") !== undefined ? $(this).data("licence_type") : "Royalty Free";
    var suraId=$(this).data("sura_id");

    var thumb_url = $(this).data('thumb-url');
    // var largePrice = Number($(this).data('large-price'));
    // var smallPrice = Number($(this).data('small-price'));
    // var mediumPrice = price;
    // var exclusiveMonth1 = $(this).data('exclusive-1-month');
    // var exclusiveMonth3 = $(this).data('exclusive-3-month');
    // var exclusiveMonth6 = $(this).data('exclusive-6-month');
    // var exclusiveMonth12 = $(this).data('exclusive-12-month');
    // var exclusiveMonth24 = $(this).data('exclusive-24-month');

    var isExclusive = $(this).data('has-exclusive');

    let item = shoppingCart.addItemToCart(id,name,size, price, exclusiveLicence, 1,thumb_url,isExclusive,exclusiveLicence_duration,licenceType, suraId);

    displayCart();

    //console.log(item);

    if(item !== undefined)
    {
        $('.add-to-cart-notif').slideDown('slowly');


        $.ajax({
            url: '/membership/online',
            type: "GET",
            async: true,
            success: function (data)
            {


                let user_authenticated = data.authenticated;

                if(user_authenticated) {

                    let url = $(this).data('add-to-cart-url');

                    $.ajax({
                        url: '/cart_item/new'       ,
                        type: "POST",
                        processData: false,
                        contentType: "application/json",
                        data: JSON.stringify(item),
                        async: true,
                        success: function (data) {


                        }
                    });

                }else{
                    //alert('item added offline');
                    // alert(JSON.parse(sessionStorage.getItem('offline_items')));

                    if( JSON.parse(sessionStorage.getItem('offline_items')) == null){
                        let offline_cart_items = [];
                        offline_cart_items.push(item);
                        sessionStorage.setItem('offline_items', JSON.stringify(offline_cart_items));
                    }else{
                        let offline_cart_items =  JSON.parse(sessionStorage.getItem('offline_items'));
                        offline_cart_items.push(item);
                        sessionStorage.setItem('offline_items', JSON.stringify(offline_cart_items));
                    }



                    //console.log(offline_cart_items.length);
                }
            }
        });



    }



});


$(document).ready(function () {
    // alert(user_authenticated);

    $.ajax({
        url: '/membership/online',
        type: "GET",
        async: true,
        success: function (data)
        {
            let user_authenticated = data.authenticated;

            //alert(user_authenticated);

            if(user_authenticated)
            {
                let offline_cart_items = JSON.parse(sessionStorage.getItem('offline_items'));

                // console.log(offline_cart_items);

                if( offline_cart_items != null)
                {
                    if( offline_cart_items.length>0)
                    {
                        $.each(offline_cart_items, function (index,item) {
                            $.ajax({
                                url: '/cart_item/new',
                                type: "POST",
                                processData: false,
                                contentType: "application/json",
                                data: JSON.stringify(item),
                                async: false,
                                success: function (data) {
                                    location.reload();

                                }
                            });

                        });
                    }


                }
                offline_cart_items = [];
                sessionStorage.setItem('offline_items', JSON.stringify(offline_cart_items));

            }
        }
    });


});



// Clear items
$('.clear-cart').click(function(e) {
    shoppingCart.clearCart();
    displayCart();
});





function displayCart() {

    var cartArray = shoppingCart.listCart();
    // console.log(cartArray)
    var output = "";
    for (var i in cartArray) {
        if (cartArray[i].thumb_url != 'undefined' && cartArray[i].id != 'undefined' && cartArray[i].name != 'undefined'
            && cartArray[i].size != 'undefined' && cartArray[i].exclusiveLicence != 'undefined' && cartArray[i].price != 'undefined') {

            let durationIn = "";

            if (cartArray[i].exclusiveLicenceDuration !== 'None'){
                let exclusiveDuration = cartArray[i].exclusiveLicenceDuration;
                if (exclusiveDuration/12 >= 1){
                    if (exclusiveDuration/12 > 1){
                        durationIn = " years";
                    }else {
                        durationIn = " year";
                    }
                }else {
                    if (exclusiveDuration > 1){
                        durationIn = " months";
                    }else {
                        durationIn = " month";
                    }
                }
            }

            output += '<tr>\n' +
                '                                    <td data-label="File">\n' +
                '                                        <img src="' + cartArray[i].thumb_url + '" class="cart_thumbnail" alt="">\n' +
                '                                    </td >\n' +
                '                                    <td data-label="File ID">' + cartArray[i].suraId + '</td>\n' +
                '                                    <td data-label="Title">\n' +
                cartArray[i].name +
                '                                    </td>\n' +
                '                                    <td data-label="Licence Type">' + cartArray[i].licenceType + ' ('+ cap(cartArray[i].size)+')'+ ( cartArray[i].exclusiveLicenceDuration !=='None' ? ' - Exclusive for '+ (cartArray[i].exclusiveLicenceDuration/12 >= 1 ? cartArray[i].exclusiveLicenceDuration/12+durationIn : cartArray[i].exclusiveLicenceDuration+durationIn) : '' ) +' </td>\n' +
                '                                    <td data-label="Calculate Price">';
            var route = Routing.generate('recalculate_item_offline', {
                'id': cartArray[i].id
            });
            output +=
                '     <a href="" onclick="recalculate(event)" data-url="' + route + '"  data-id="' + cartArray[i].id + '" class="clickable_td" data-file="img_5d5127ecae376.jpeg">\n' +
                '                                       Recalculate Price    ' +
                '                                        </a>\n                                       ' +
                '                                   </td>\n' +
                '<td data-label="Price">$' + cartArray[i].price + '</td>\n' +
                '                                    <td data-label="Remove">\n' +
                '                                        <a href="" data-url=""  data-id="' + cartArray[i].id + '" class="delete_icon_cart" data-file="img_5d5127ecae376.jpeg">\n' +
                '                                            <svg class="item_svg_icon">\n' +
                '                                                <use xlink:href="#delete"></use>\n' +
                '                                            </svg>\n' +
                '                                        </a>\n' +
                '                                    </td>\n' +
                '                                </tr>';
        }
    }
    $('.show-cart').html(output);
    $('.total-cart').html(shoppingCart.totalCart());
    $('.cart_count').html(shoppingCart.totalCount());
    $('.total-count').html(shoppingCart.totalCount());
    $('.total_price').html(shoppingCart.totalCart());
}

function getBasket(){
    let cart = shoppingCart.listCart();
    let totalCart = shoppingCart.totalCart();
    let cartCount = shoppingCart.totalCount();
    let totalCount = shoppingCart.totalCount();
    let totalPrice = shoppingCart.totalCart();

    let resObj = {};
    resObj.cart = cart;
    resObj.totalCart = totalCart;
    resObj.totalCount = totalCount;
    resObj.cartCount = cartCount;
    resObj.totalPrice = totalPrice;
    return resObj;
}

function cap(str) {
    return str.replace(/([a-z])/, function (match, value) {
        return value.toUpperCase();
    })
}

function isSizeSelected(Item,size){
    if(Item.size_selection==size){
        return "selected";
    }
}

function showExclusive(Item){
    if(!Item.isExclusive){
        return "disabled";
    }
}
function isExclusiveSelected(Item,term){
    if(Item.exclusive_selection==term){
        return "selected";
    }
}

// Delete item button

$('.show-cart').on("click", ".delete_icon_cart", function(event) {
    event.preventDefault();
    var id = $(this).data('id')
    shoppingCart.removeItemFromCartAll(id);
    displayCart();

});
//change size
$('.show-cart').on("change", ".cart-image-size", function(event) {

    var size=($(this).val());
    var id = $(this).data('id')
    shoppingCart.changeItemSizeIncart(id,size);
    displayCart();

})


// -1
$('.show-cart').on("click", ".minus-item", function(event) {
    var id = $(this).data('id')
    shoppingCart.removeItemFromCart(id);
    displayCart();
});
// +1
$('.show-cart').on("click", ".plus-item", function(event) {
    var id = $(this).data('id')
    shoppingCart.addItemToCart(id);
    displayCart();
})

// Item count input
$('.show-cart').on("change", ".item-count", function(event) {
    var id = $(this).data('id');
    var count = Number($(this).val());
    shoppingCart.setCountForItem(id, count);
    displayCart();
});

//let url = $('.add-to-cart').data('load-cart-items-url');
// let url = $('[data-load-cart-items-url]').data('load-cart-items-url');
let url = Routing.generate('cart_item_index');
$.ajax({
    url: url,
    type: "GET",
    processData: false,
    contentType: "application/json",
    dataType:   "json",
    async: true,
    success: function (response)
    {

        $.ajax({
            url: '/membership/online',
            type: "GET",
            async: true,
            success: function (data) {
                let user_authenticated = data.authenticated;

                //alert(user_authenticated);

                if (user_authenticated) {

                    shoppingCart.clearCart();

                    $.each(response, function (index, value) {
                        shoppingCart.addItemToCart(value.stock_id, value.name, value.size, value.price, value.exclusive_licence, 1, value.thumbnail, value.isExclusive, value.suraID);
                    });

                    displayCart();
                }
            }
        });

    }
});


function removeCart() {
    sessionStorage.removeItem("shoppingCart");
}



displayCart();





$('#btn-order-now').click(function (e) {
    var url = $(this).data('order-url');
    //console.log(e);
    var items=shoppingCart.listCart();
    $.ajax({
        url: url,
        type: "POST",
        processData: false,
        contentType: "application/json",
        data:JSON.stringify(items),
        async: true,
        success: function (data)
        {
            alert('we ordered');
            shoppingCart.clearCart();

        }
    });
});

///////////SHOPPING BASKET ACTIONS//////////////////////
window.onload = function(){
    let cartItemDeleted = sessionStorage.getItem("cartItemDeleted");
    if (cartItemDeleted){
        sessionStorage.removeItem("cartItemDeleted");
        $(".alert-success").text("Item has been deleted successfully").show();
    }
};
//Delete
$(".show-basket").on("click", ".delete_icon_cart", function(event) {
    event.preventDefault();
    let id = $(this).data('id');
    shoppingCart.removeFromBasket(id);
    sessionStorage.setItem("cartItemDeleted", "true");
    window.location.reload();
});
//recalculate
function recalculate(e) {
    if (e.preventDefault){
        e.preventDefault();
        let elem = $(e.target);
        let stockId = elem.data("id");
        let url=elem.data("url");
        // shoppingCart.removeFromBasket(stockId);
        window.location.href=url;

    }
}
//checkout
$(".show-basket").on("click",".checkout_btn", function (e) {
    document.location.href=$(this).data("url")
});

Youez - 2016 - github.com/yon3zu
LinuXploit