summaryrefslogtreecommitdiff
path: root/views/mods/mod_productvariants/frontend.js
blob: 9e50d0b2c9c0c20e7c35b06215e34fc0a318a41b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

	var wpsg_vp_vari = new Array();	
		  
	function wpsg_vp_switch(product_id, product_index, elem)
	{
			 /*
		var var_key = 'pv_' + product_id + "|";
		//alert('Länge: ' + wpsg_vp_vari[product_id].length);
		
		for (var i = 0; i < wpsg_vp_vari[product_id].length; i ++)
		{
			
			vkey1 = i + ":";
			vkey2 = '';
			
			if (wpsg_vp_vari[product_id][i] == "select")
			{				
				vkey2 = jQuery('#wpsg_produktform_' + product_index + ' .wpsg_produkt_' + product_id + " #wpsg_vpfield_" + product_id + "_" + i).val();				
			}
			else if (wpsg_vp_vari[product_id][i] == "radio")
			{
				vkey2 = jQuery('#wpsg_produktform_' + product_index + ' .wpsg_produkt_' + product_id + ' input[name="wpsg_vp[' + i + ']"]:checked').val();
			}
			else if (wpsg_vp_vari[product_id][i] == "checkbox")
			{
				vkey2 = jQuery('#wpsg_produktform_' + product_index + ' .wpsg_produkt_' + product_id + ' input[name="wpsg_vp[' + i + ']"]:checked').length;
			} 
			else if (wpsg_vp_vari[product_id][i] == "image")
			{
				vkey2 = jQuery('#wpsg_produktform_' + product_index + ' .wpsg_produkt_' + product_id + ' .wpsg_mod_productvariants_imageselect_' + i + ' .akt').attr("data-wpsg-id");
			}
			
			if (vkey2 != '') {
				if (wpsg_vp_vari[product_id][i] == "image")
					jQuery('#wpsg_vp_' + i).val(vkey2);
				var_key += vkey1 + vkey2; 
				if (i < (wpsg_vp_vari[product_id].length - 1)) var_key += "|";
			}
		}
		 */
		//console.log(jQuery('#wpsg_produktform_' + product_index).serialize());
		//console.log(var_key);
		//return;
		
		v1 = jQuery(elem).attr("data-wpsg-id");
		//v2 = jQuery(elem).parent().find('input').val();
		jQuery(elem).parent().find('input').val(v1);
		//alert('v1=' + v1 + ' v2=' + v2);
		
		jQuery('#wpsg_produktform_' + product_index).append('<div class="wpsg_product_layer"><img src="' + wpsg_ajax.img_ajaxloading + '" alt="' + wpsg_ajax.label_pleasewait + '" /></div>');
 
		jQuery.ajax( {
			'url': wpsg_ajax.ajaxurl,
			'method': 'get',
			'data': {
				'action': 'wpsg_productvariants_switch',
				'wpsg_post_id': jQuery('#wpsg_produktform_' + product_index + ' input[name="wpsg_post_id"]').val(),
				'quantity': jQuery('#wpsg_menge_' + product_index).val(),
				'template': jQuery('#wpsg_produktform_' + product_index + ' input[name="wpsg[template]"]').val(),
				'referer': jQuery('#wpsg_produktform_' + product_index + ' input[name="myReferer"]').val(),
				'form_data': jQuery('#wpsg_produktform_' + product_index).serialize(),
			//	'product_key': var_key,
				'product_index': product_index
			},
			'success': function(data) {
		 
				jQuery('#wpsg_produktform_' + product_index).replaceWith(data);
				
			}
		} );
		
	} // function wpsg_vp_switch(produkt_id)

    function wpsg_mod_productvariants_reload(event)
    {
        
        var product_index = jQuery(event.target).parents('.wpsg_mod_productvariants_product_wrap').attr('wpsg-productindex');
                 
        //jQuery('#wpsg_produktform_' + product_index).append('<div class="wpsg_product_layer"><img src="' + wpsg_ajax.img_ajaxloading + '" alt="' + wpsg_ajax.label_pleasewait + '" /></div>');
 
		jQuery.ajax( {
			'url': wpsg_ajax.ajaxurl,
			'method': 'get',
			'data': {
				'action': 'wpsg_productvariants_switch',
				'wpsg_post_id': jQuery('#wpsg_produktform_' + product_index + ' input[name="wpsg_post_id"]').val(),
				'form_data': jQuery('#wpsg_produktform_' + product_index).serialize(),				
				'product_index': product_index
			},
			'success': function(data) {
		 
				jQuery('#wpsg_produktform_' + product_index).replaceWith(data);
				
			}
		} );
        
    } // function wpsg_mod_productvariants_reload(event)