HEX
Server: Apache
System: Linux srv13.cpanelhost.cl 3.10.0-962.3.2.lve1.5.38.el7.x86_64 #1 SMP Thu Jun 18 05:28:41 EDT 2020 x86_64
User: cca63905 (4205)
PHP: 7.3.20
Disabled: NONE
Upload Files
File: //proc/self/cwd/nueva/modules/roja45quotationsprofree/views/js/roja45quotationspro_cart.js
/**
 * roja45ajaxcart.js.
 *
 * @author    Roja45
 * @copyright 2016 Roja45
 * @license   license.txt
 *
 * 2016 ROJA45 - All rights reserved.
 *
 * DISCLAIMER
 * Changing this file will render any support provided by us null and void.
 */

$(document).ready(function () {
    $(document).off('click', '.ajax_add_quote_button').on('click', '.ajax_add_quote_button', function (e) {
        e.preventDefault();

        var idProduct =  parseInt($(this).attr('data-id-product'));
        var idProductAttribute =  parseInt($(this).attr('data-id-product-attribute'));
        var minimalQuantity =  parseInt($(this).attr('data-minimal-quantity'));
        if (!minimalQuantity) {
            minimalQuantity = 1;
        }

        if ($(this).attr('disabled') != 'disabled') {
            roja45quotationspro_quotationscart.add(idProduct, idProductAttribute, false, this, minimalQuantity, minimalQuantity);
        }
    });
});

var roja45quotationspro_quotationscart = {
    nb_total_products: 0,

    updateQuoteInformation: function (jsonData, addedFromProductPage) {
        roja45quotationspro_quotationscart.updateQuote(jsonData);
        //reactive the button when adding has finished
        if (addedFromProductPage) {
            $('#add_to_cart button').removeProp('disabled').removeClass('disabled');
            if (!jsonData.hasError || jsonData.hasError == false)
                $('#add_to_cart button').addClass('added');
            else
                $('#add_to_cart button').removeClass('added');
        }
        else
            $('.ajax_add_to_cart_button').removeProp('disabled');
    },

    // add a product in the cart via ajax
    add: function (idProduct, idCombination, addedFromProductPage, callerElement, minimalQuantity, quantity) {
        if (addedFromProductPage) {
            $('#add_to_quote_cart button').prop('disabled', 'disabled').addClass('disabled');
            $('.filled').removeClass('filled');
        } else {
            $(callerElement).prop('disabled', 'disabled');
            $(callerElement).addClass('disabled');
        }

        $.ajax({
            url: roja45quotationspro_controller,
            headers: { "cache-control": "no-cache" },
            type: 'post',
            dataType: 'json',
            data: {
                'action' : 'addProductToRequest',
                'ajax' : 1,
                'quantity' : ((quantity && quantity != null) ? quantity : minimalQuantity),
                'id_product' : idProduct,
                'id_product_attribute' : ((idCombination && idCombination != null) ? idCombination : '0')
            },
            beforeSend: function () {
                $(this).attr('disabled', 'disabled');
                $(this).addClass('disabled');
                roja45quotationsprofree.toggleWaitDialog();
            },
            success: function (data) {
                if (data.result == 'success') {
                    roja45quotationsprofree.displaySuccessMsg([roja45quotationspro_added_success]);
                    roja45quotationspro_quotationscart.updateQuoteInformation(data);
                    $(callerElement).addClass('added');
                } else if (data.result == 'error') {
                    roja45quotationsprofree.displayErrorMsg([roja45quotationspro_added_failed]);
                    roja45quotationsprofree.displayErrorMsg(data.errors);
                } else {
                    roja45quotationsprofree.displayErrorMsg([roja45quotationspro_unknown_error]);
                }
            },
            error: function (data) {
                roja45quotationsprofree.displayErrorMsg([roja45quotationspro_sent_failed]);
            },
            complete: function (data) {
                $(callerElement).removeAttr('disabled');
                $(callerElement).removeClass('disabled');
                roja45quotationsprofree.toggleWaitDialog();
            }
        });
    },

    // Update product quantity
    updateProductQuantity: function (product, quantity) {
        $('dt[data-id=quote_block_product_' + product.id_product + '_' + (product.id_product_attribute ? product.id_product_attribute : '0') + '] .quantity').fadeTo('fast', 0, function () {
            $(this).text(quantity);
            $(this).fadeTo('fast', 1, function () {
                $(this).fadeTo('fast', 0, function () {
                    $(this).fadeTo('fast', 1, function () {
                        $(this).fadeTo('fast', 0, function () {
                            $(this).fadeTo('fast', 1);
                        });
                    });
                });
            });
        });
    },

    updateLayer: function (product) {
        $('#layer_quote_product_title').text(product.name);
        $('#layer_quote_product_attributes').text('');
        if (product.hasAttributes && product.hasAttributes == true) {
            $('#layer_quote_product_attributes').html(product.attributes);
        }

        $('#layer_quote_product_price').text(product.price);
        $('#layer_quote_product_quantity').text(product.quantity);
        $('.layer_quote_img').html('<img class="layer_quote_img img-responsive" src="' + product.image_quote + '" alt="' + product.name + '" title="' + product.name + '" />');

        var n = (parseInt($(window).scrollTop())+100) + 'px';

        $('.layer_quote_overlay').css('width', '100%');
        $('.layer_quote_overlay').css('height', '100%');
        $('.layer_quote_overlay').show();
        $('#layer_quote').css({'top': n}).fadeIn('fast');
        //crossselling_serialScroll();
    },

    //genarally update the display of the cart
    updateQuote: function (jsonData) {
        roja45quotationspro_quotationscart.updateQuoteEverywhere(jsonData);
        roja45quotationspro_quotationscart.hideOldProducts(jsonData);
        roja45quotationspro_quotationscart.displayNewProducts(jsonData);
        //update 'first' and 'last' item classes
        $('.roja45quotationspro_block .products dt').removeClass('first_item').removeClass('last_item').removeClass('item');
        $('.roja45quotationspro_block .products dt:first').addClass('first_item');
        $('.roja45quotationspro_block .products dt:not(:first,:last)').addClass('item');
        $('.roja45quotationspro_block .products dt:last').addClass('last_item');
    },

    //update general cart informations everywhere in the page
    updateQuoteEverywhere: function (jsonData) {
        this.nb_total_products = jsonData.nbTotalProducts;
        if (parseInt(jsonData.nbTotalProducts) > 0) {
            $('.ajax_quote_no_product').hide();
            $('.ajax_quote_quantity').text(jsonData.request_qty);
            $('.ajax_quote_quantity').fadeIn('slow');

            if (parseInt(jsonData.nbTotalProducts) > 1) {
                $('.ajax_quote_product_txt').each(function () {
                    $(this).hide();
                });
                $('.ajax_quote_product_txt_s').each(function () {
                    $(this).show();
                });
            }
            else {
                $('.ajax_quote_product_txt').each(function () {
                    $(this).show();
                });
                $('.ajax_quote_product_txt_s').each(function () {
                    $(this).hide();
                });
            }
        }
        else {
            $('.ajax_quote_quantity, .ajax_quote_product_txt_s, .ajax_quote_product_txt, .ajax_quote_total').each(function () {
                $(this).hide();
            });
            $('.ajax_quote_no_product').show('slow');
        }
    },
};