Blame view

frontend/web/js/basket.js 4.33 KB
550eac02   Administrator   second
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  (function($){

  

      $.fn.basket = function(callerSettings) {

  	

  	var basket_id = this;

  

  		var find_products = function(){ 

           $("a[rel~='product']").each(function (i) { 

                  $(this).bind('click',function(){ 

                  var rel = $(this).attr('rel');

                  var id = $('#product_id').val();

                  var count = 1;

                  go_product({mod_id : id,count:count});

                  return false;

                  })

           })

3f2bc3d0   Administrator   first commit
17
          }

550eac02   Administrator   second
18
19
20
21
          

  		var go_product = function(data){

  		    var product_id = data.product_id;

  			$.get("/basket/add/",  data ,

3a7e43ce   Administrator   20.07.16
22
  			function(data){

550eac02   Administrator   second
23
24
25
  				//alert_msg("Товар добавлен<br /> в корзину",product_id);

  				popup(0,'.black');

  				start_basket();

3a7e43ce   Administrator   20.07.16
26
  			});

550eac02   Administrator   second
27
28
  		}

  

444e4745   Administrator   image size
29
30
31
32
33
34
35
36
37
  

  		var update = function(data,form,w){

  			console.log(data);

  			$('.basket_items').html(data);

  			$('.basket_items .delete_button').click(function(){

  				var id =$(this).data('id');

  				$.get("/basket/items/",  {deleteID : id},function(data){

  					popup(w,form);

  					start_basket(w,form);

550eac02   Administrator   second
38
  				});

444e4745   Administrator   image size
39
40
41
42
43
44
45
46
47
48
49
50
51
  				return false;

  			});

  			$(".item_num").bind('input',function(){

  				sendformitems(w,form);

  			});

  			$(".minus").click(function(){

  				var a = $(this).parent().find(".item_num").attr("value");

  				if (a == 1) {

  					/* минимум 1 элемент */

  				}

  				else{

  					a--;

  					$(this).parent().find('.item_num').val(a);

550eac02   Administrator   second
52
  					sendformitems(w,form);

444e4745   Administrator   image size
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  				}

  			});

  			$(".plus").click(function(){

  				var a = $(this).parent().find(".item_num").attr("value");

  				if (a == 10) {

  					/* минимум 1 элемент */

  				}

  				else{

  					a++;

  					$(this).parent().find('.item_num').val(a);

  					sendformitems(w,form);

  				}

  			});

  		};

  

  		var popup = function(w,form){

  			$.get("/basket/items/", {} ,function(data){

  				update(data,form,w);

550eac02   Administrator   second
71
72
73
  			});

  			if(w==0) {

  				$(".black").removeClass("hidden");

577d7327   Administrator   image size
74
75
  				$(".black_close").click(function (event) {

  					event.preventDefault();

550eac02   Administrator   second
76
77
78
79
80
81
82
83
84
  					$(this).parent().parent().addClass("hidden");

  				});

  				$(".cont_shop").click(function () {

  					$(".black").addClass("hidden");

  				});

  			}

  		}

  

  		var sendformitems = function(w,form){

7c51adb2   Administrator   image size
85
86
87
88
  			//var data_form = $(form+' .basket_form2').serialize();

  			$.post('/basket/items/', $.param($(form+' .basket_form2').serializeArray()), function(data) {

  				update(data,form,w);

  				start_basket();

550eac02   Administrator   second
89
  			});

7c51adb2   Administrator   image size
90
91
92
93
94
95
96
97
98
  			//$.ajax({

  			//	type: 'POST',

  			//	url: "/basket/items/",

  			//	dataType: "json",

  			//	data: data_form,

  			//	done: function(data) {

              //

  			//	},

  			//});

550eac02   Administrator   second
99
  		}

3a7e43ce   Administrator   20.07.16
100
101
  

          var start_basket = function(){

550eac02   Administrator   second
102
103
104
105
  			$.get("/basket/info/",

  			function(data){

  				$(basket_id).html(data);

  			});

3f2bc3d0   Administrator   first commit
106
  

3f2bc3d0   Administrator   first commit
107
108
          }

  

550eac02   Administrator   second
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
  		var alert_msg = function(msg,product_id){ 

  		winW = document.body.offsetWidth;

  		winH = document.body.offsetHeight

  		$('.modal_box').remove();

  		$('#data_box').remove();

  		$('body').append('<div class="modal_box"></div>');

  		$('body').append('<div id="data_box"></div>');

  		$('#data_box').append('<div class="data_wrp"></div>');

                  $('#data_box').css( "left", ((winW-400)/2)+'px' );

      

  	var scrollTop = document.documentElement.scrollTop

      if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1 || navigator.userAgent.toLowerCase().indexOf('safari') > -1) {

  		scrollTop = document.body.scrollTop;

      }		

  		$('#data_box').css( "top", (scrollTop+150)+'px' );

  		

  		app = '<center>';

  		app +='<h1>'+msg+'</h1>';

  		app += '<br /><input type="submit" class="submit4" style="text-transform:none;" value="Перейти в корзину" onClick="document.location=\'/basket/\'" />&nbsp;';

  		app += '<input type="submit" class="submit4" style="text-transform:none;" id="p_close" value="Продолжить покупки" />';

  		app += '</center>';

  		$('#data_box .data_wrp').append(app);

  		

  		

  		$(".modal_box, #modal_close, #p_close").click(function() {

  			$('.modal_box').remove();

  			$('#data_box').remove();

  		});		

  		}		

  		

  		find_products();

  		start_basket();

  

  

  

  		$(".more").click(function(){

  			if($(this).hasClass("hideico")){

  				$(this).removeClass("hideico");

  				$(this).parent().addClass("open");

  				$(this).parent().removeClass("open");

  			}

  			else{

  				$(this).addClass("hideico");

  				$(this).parent().addClass("open");

  				popup(1,'.basket_hovered');

  			}

  		})

  

  

  		

  	}	

  

  })(jQuery);