Your IP : 216.73.216.14


Current Path : /var/www/magento.test.indacotrentino.com/www/pub/static/frontend/Magento/indaco/it_IT/js/
Upload File :
Current File : /var/www/magento.test.indacotrentino.com/www/pub/static/frontend/Magento/indaco/it_IT/js/qty.js

define(['jquery'], function ($) {

    $('.increaseQty, .decreaseQty').on("click", function () {

        let inputElem = $(this).parents('.qty-container').find('input').first();

        let currentQty = inputElem.val() || 0;

        if ($(this).hasClass('increaseQty')) {
            inputElem.val(parseInt(currentQty) + 1);
        } else {
            inputElem.val(
                parseInt(currentQty) - 1 > 0
                    ? parseInt(currentQty) - 1
                    : 0
            );
        }
    });

    $(document).ready(function() {
        if (typeof sku !== 'undefined' && typeof encryptedValue !== 'undefined' && sku && encryptedValue) {
            $.ajax({
                url: `/recommendations/api/selectRecommendations?sku=${sku}&encryptedvalue=${encryptedValue}`,
                type: 'GET',
                dataType: 'json',
                success: function(data) {
                    data.title !== '' && $('#block-related-heading').html(data.title);

                    const recommendations = data.recommendations;
                    const $productItems = $('.products-related .product-items');

                    const itemsArray = data.recommendations;

                    itemsArray.sort((a, b) => a.position - b.position);

                    itemsArray.forEach(function(item) {
                        const dataValue = item.related;
                        const $elementToMove = $(`[data-item="${dataValue}"]`, $productItems);
                        $productItems.prepend($elementToMove);
                    });
                    $productItems.children().slice(4).hide();
                },

                error: function() {
                    console.error('Errore durante la richiesta AJAX');
                }
            });
        }
    });
});