PageSourceSearch

https://24hrs.es/modules/render_google/views/js/rg_cart.js

js 24hrs.es collected 2026-10-04 16:12:49 UTC 3,129 bytes, 72 lines download raw bytes

1$(function(){
2	//Si el carrito se le pasa sin ningun producto, Prestashop realiza la conversion de 'products' a Array, lo queremos de tipo Object para poder trabajar mejor con el 
3	if(rg_cart.products.length == 0)
4		rg_cart.products = new Object();
5
6	// Cuando se introduce un producto desde la pagina de inicio, listado de categoria o productos relacionados en ficha de producto
7	$("#index #content div.products div.product div.information div.buy button, #product-list li.product div.information div.buy button, #product div.product-footer div.products div.product div.information div.buy button").on("click", function(e){
8		let size = $(this).prev().find('.selected');
9		if($(size).length){
10			let id_product_attribute = String($(size).data('id-product-attribute'));
11			if(!rg_cart.products.hasOwnProperty(id_product_attribute)){ //Si el array del carrito aun no tiene el producto, lo metemos
12				let product = $(this).parents('.product');
13				rg_cart.products[id_product_attribute] = {
14					id_product: $(product).data('id-product'),
15					name: $(product).data('name'),
16					category: $(product).data('category'),
17					price: $(product).data('price'),
18					quantity: 1,
19					color: $(product).data('color'),
20				};
21			}
22			else{ //Si ya tiene el producto, entonces solo aumentamos su cantidad
23				rg_cart.products[id_product_attribute].quantity += 1;
24			}
25			sendAddToCartAnalytics(id_product_attribute);
26		}
27	});
28	
29	// Cuando 
30	$(document).on("click", "#header div.main-header div.main div.icons #cart .products div.remove_link a", function(e){
31		let id_product_attribute = String($(e.target).attr("href").split("ipa=")[1].split("&")[0]);
32		sendRemoveFromCartAnalytics(id_product_attribute, rg_cart.products[id_product_attribute].quantity);
33		delete rg_cart.products[id_product_attribute];
34	});
35
36	//Funcion para mandar el evento add_to_cart de Analytics
37	function sendAddToCartAnalytics(id_product_attribute){	
38		gtag('event', 'add_to_cart', {
39			currency: 'EUR',
40			items: [{
41				item_id: rg_cart.products[id_product_attribute].id_product,
42				item_name: rg_cart.products[id_product_attribute].name,
43				item_brand: '24hrs',
44				item_category: rg_cart.products[id_product_attribute].category,
45				item_variant: rg_cart.products[id_product_attribute].color,
46				price: rg_cart.products[id_product_attribute].price,
47				currency: 'EUR',
48				quantity: 1,
49			}],
50			value: rg_cart.products[id_product_attribute].price
51		});
52	}
53
54	//Funcion para mandar el evento remove_from_cart de Analytics
55	function sendRemoveFromCartAnalytics(id_product_attribute, qty){
56		let product_id = rg_cart.products[id_product_attribute].id_product;
57		gtag('event', 'remove_from_cart', {
58			currency: 'EUR',
59			items: [{
60				item_id: parseInt(product_id),
61				item_name: rg_cart.products[id_product_attribute].name,
62				item_brand: '24hrs',
63				item_category: rg_cart.products[id_product_attribute].category,
64				item_variant: rg_cart.products[id_product_attribute].color,
65				price: rg_cart.products[id_product_attribute].price,
66				currency: 'EUR',
67				quantity: qty,
68			}],
69			value: rg_cart.products[id_product_attribute].price * qty
70		});
71	}
72});

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.