PageSourceSearch

https://distribucionmayorista.online/themes/warehouse/modules/ps_shoppingcart/ps_shoppingcart.js

js distribucionmayorista.online collected 2026-10-04 13:26:41 UTC 5,786 bytes, 117 lines download raw bytes

1$(document).ready(function () {
2    prestashop.blockcart = prestashop.blockcart || {};
3
4    var showModal = prestashop.blockcart.showModal || function (modalHTML) {};
5
6    $(document).ready(function () {
7        $(document).on('click', '#js-cart-close', function (e) {
8            $('#blockcart, #mobile-cart-wrapper, #_mobile_blockcart-content, #_desktop_blockcart-content').removeClass('show');
9            e.stopPropagation();
10        });
11
12        $(document).on('click', '#blockcart-content', function (e) {
13            e.stopPropagation();
14        });
15
16        prestashop.on('updateCart', function (event) {
17            var refreshURL = $('#blockcart').data('refresh-url');
18            var requestData = {};
19            /* console.log("UPDATE CART", event); */
20
21            // Verificar si event.reason está definido
22            if (!event || !event.reason) {
23                console.error("Evento no definido o incompleto:", event);
24                return; // Detener la ejecución si el evento no es válido
25            }
26
27            // Obtener el producto específico que se está actualizando
28            var productId = event.reason.idProduct;
29            var productAttributeId = event.reason.idProductAttribute;
30            var newQuantity = $('.block-cart-product-quantity[data-product-id="' + productId + '"]').val();
31
32            // Obtener el stock máximo desde event.reason o event.resp (si está definido)
33            var maxStock = (event.reason.maxProductQuantity || (event.resp && event.resp.maxProductQuantity) || 0); // Valor predeterminado: 0
34            /* console.log("STOCK MÁXIMO:", maxStock); */
35
36            // Asegurarse de que la cantidad no supere el stock máximo
37            if (newQuantity > maxStock) {
38                newQuantity = maxStock;
39                $('.block-cart-product-quantity[data-product-id="' + productId + '"]').val(maxStock);
40            }
41
42            // Preparar datos a enviar
43            if (event.reason && typeof event.reason !== 'undefined') {
44                requestData = {
45                    id_customization: event.reason.idCustomization,
46                    id_product_attribute: productAttributeId,
47                    id_product: productId,
48                    quantity: newQuantity, // Enviar la nueva cantidad (ajustada al stock)
49                    action: event.reason.linkAction
50                };
51                /* console.log("NO HAY ERRORES"); */
52            }
53
54            // Guardar el estado del carrito y otros elementos
55            var isCartOpen = $('#blockcart').hasClass('show');
56            var isMobileCartOpen = $('#_mobile_blockcart-content').hasClass('show');
57            var isDesktopCartOpen = $('#_desktop_blockcart-content').hasClass('show');
58
59            // Llamada AJAX para actualizar el carrito
60            $.post(refreshURL, requestData).then(function (resp) {
61                /* console.log("LLAMADA AJAX RESP:", resp);
62                console.log("LLAMADA AJAX EVENT", event); */
63
64                // Verificar si hay un error en la respuesta
65                if (event.reason.hasError == true || (event.resp && event.resp.hasError)) {
66                    /* console.log("ERROR"); */
67
68                    // Obtener el stock máximo disponible desde la respuesta del servidor
69                    var maxAvailableQuantity = (event.reason.maxProductQuantity || (event.resp && event.resp.maxProductQuantity) || 0);
70                    /* console.log("STOCK MÁXIMO", maxAvailableQuantity); */
71
72                    // Actualizar los contadores con el stock máximo disponible
73                    $('#blockcart .cart-products-count-btn').text(maxAvailableQuantity).removeClass('d-none'); // Eliminar d-none
74                    $('#mobile-cart-products-count').text(maxAvailableQuantity).removeClass('d-none'); // Eliminar d-none
75                    $('.block-cart-product-quantity[data-product-id="' + productId + '"]').val(maxAvailableQuantity);
76
77                } else {
78                    // Si no hay errores, actualizamos el contenido del carrito
79                    $('#blockcart-content').html($(resp.preview).find('#blockcart-content').html());
80
81                    // Restaurar los estados del carrito (si estaba abierto)
82                    if (isCartOpen) {
83                        $('#blockcart').addClass('show');
84                    }
85                    if (isMobileCartOpen) {
86                        $('#_mobile_blockcart-content').addClass('show');
87                    }
88                    if (isDesktopCartOpen) {
89                        $('#_desktop_blockcart-content').addClass('show');
90                    }
91
92                    // Actualizar los contadores de productos en el carrito
93                    var updatedCartCount = $(resp.preview).find('.cart
93-products-count-btn').first().text();
94                    $('#mobile-cart-products-count').text(updatedCartCount).removeClass('d-none'); // Eliminar d-none
95                    $('#blockcart .cart-products-count-btn').text(updatedCartCount).removeClass('d-none'); // Eliminar d-none
96                }
97
98                // Emitir eventos necesarios para actualizar el carrito
99                prestashop.emit('responsive updateAjax', {
100                    mobile: prestashop.responsive.mobile
101                });
102                prestashop.emit('updatedAjaxCart', {});
103
104                // Mostrar el modal si está presente
105                if (resp.modal) {
106                    showModal(resp.modal);
107                }
108
109                // Detener cualquier animación de scroll activa
110                $('html, body').stop(true, true);
111
112            }).fail(function (resp) {
113                prestashop.emit('handleError', { eventType: 'updateShoppingCart', resp: resp });
114            });
115        });
116    });
117});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.