-
Notifications
You must be signed in to change notification settings - Fork 0
/
carrito_add.php
411 lines (276 loc) · 11.1 KB
/
carrito_add.php
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
98
99
100
101
102
103
104
105
106
107
108
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<?php
ob_start();
require_once('libs.php');
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
if(!isset($_SESSION)):
@session_start();
endif;
// function redirect(){
// header('location: http://nufarm-maxx.com/marketingNetDesarrollo/carrito.php');
// }
function redirect(){
echo('<script>window.location.href="carrito.php";</script>');
}
// error_reporting(E_ALL);
// ini_set('display_errors', 'On');
//
error_reporting(0);
ini_set('display_errors', 'Off');
$tempMaxCompra = new TempMaxCompra();
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
$MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
@header("Location: ". $MM_restrictGoTo);
}
require_once('Connections/conexion.php');
// ================================= Cantida minima de producto ============================== //
$query = mysql_query("SELECT intMinCompra FROM productos WHERE idProducto = '".$_POST['idProducto']."'");
while ($row = mysql_fetch_array($query)) {
$minCantidad = $row["intMinCompra"];
}
// if ($_POST['cantidad'] < $minCantidad) {
// header("Location: index.php?activo=1&prod=1");
// }
/**
* Objetivo : Proteger por php la cantidad minima requerida de producto a comprar
**/
// =========================================================================================== //
$id_producto = $_POST['idProducto'];
$cantidad_elegida = $_POST['cantidad'];
include_once("includes/class.productos.php");
$productos= new productos();
$productos->select($id_producto);
$categoria=$productos->getintCategoria();
$StockActual=$productos->getintStock();
include_once("includes/class.categorias.php");
$cat = new categorias();
$cat->select($categoria);
$requiere_talles = $cat->gettalles();
$talles_seleccionados = $_POST['talle'];
$colores_seleccionados = $_POST['color'];
if($requiere_talles==1){
//requiere talles
$total = 0;
foreach($talles_seleccionados as $k => $v):
$total += (int)$v;
endforeach;
// echo $total;
$tempMaxCompra->storeSum($id_producto,$total);
try {
$stock = new TempStock();
$stock->setTalles($id_producto,$talles_seleccionados,$_SESSION['MM_IdUsuario']);
} catch (Exception $e) {
echo($e->getMessage());
}
#echo '<h1>SESSION USUSARIO'.$_SESSION['MM_IdUsuario'].'</h1>';
foreach($talles_seleccionados as $id_talle => $cantidad_elegida){
//prevengo insert with 0
if($cantidad_elegida > 0 ){
#echo 'HERE?';
$id_usuario = $_SESSION['MM_IdUsuario'];
//primero chequeo si el producto ya existe en el carrito del usuario.
include_once("includes/class.carrito.php");
$carr = new carrito();
$cantidad_en_carrito = $carr->chequear_producto_con_talle($id_usuario,$id_producto, $id_talle);
if($cantidad_en_carrito > 0){
//El producto ya existe en el carrito del usuario, solo actualizo la cantidad
$traigo_id = new carrito();
$traigo_id->select_by_usuario_producto_talle($_SESSION['MM_IdUsuario'],$id_producto,$id_talle );
$id_row = $traigo_id->getintContador();
//Actualizo cantidad
$update_carrito = new carrito();
$update_carrito->select($id_row);
$update_carrito->intCantidad = $cantidad_en_carrito + $cantidad_elegida;
$update_carrito->update($id_row);
@header('location: carrito.php');
exit();
}else{
//necesito guardarlo desde cero
$carr = new carrito();
$carr->idUsuario = $_SESSION['MM_IdUsuario'];
$carr->idProducto = $id_producto;
$carr->intCantidad = $cantidad_elegida;
$carr->talle = $id_talle;
$carr->insert();
@header('location: carrito.php');
exit();
}
//hay en stock y guarda la compra.
}
}
@header('location: carrito.php');
exit();
}else if($requiere_talles==2){
//requiere talles
$total = 0;
foreach($colores_seleccionados as $k => $v):
$total += (int)$v;
endforeach;
$tempMaxCompra->storeSum($id_producto,$total);
try {
$stock = new TempStock();
$stock->colores($id_producto,$colores_seleccionados);
} catch (Exception $e) {
echo($e->getMessage());
}
#echo '<h1>SESSION USUSARIO'.$_SESSION['MM_IdUsuario'].'</h1>';
foreach($colores_seleccionados as $id_color => $cantidad_elegida){
//prevengo insert with 0
if($cantidad_elegida > 0 ){
#echo 'HERE?';
$id_usuario = $_SESSION['MM_IdUsuario'];
//primero chequeo si el producto ya existe en el carrito del usuario.
include_once("includes/class.carrito.php");
$carr = new carrito();
$cantidad_en_carrito = $carr->chequear_producto_con_color($id_usuario,$id_producto, $id_color);
if($cantidad_en_carrito > 0){
//El producto ya existe en el carrito del usuario, solo actualizo la cantidad
$traigo_id = new carrito();
$traigo_id->select_by_usuario_producto_color($_SESSION['MM_IdUsuario'],$id_producto,$id_color );
$id_row = $traigo_id->getintContador();
//Actualizo cantidad
$update_carrito = new carrito();
$update_carrito->select($id_row);
$update_carrito->intCantidad = $cantidad_en_carrito + $cantidad_elegida;
$update_carrito->update($id_row);
@header('location: carrito.php');
exit();
}else{
//necesito guardarlo desde cero
include_once("includes/class.carrito.php");
$carr = new carrito();
$carr->idUsuario = $_SESSION['MM_IdUsuario'];
$carr->idProducto = $id_producto;
$carr->intCantidad = $cantidad_elegida;
$carr->color = $id_color;
$carr->insert();
}
//hay en stock y guarda la compra.
}
}
@header('location: carrito.php');
exit();
// echo "<script>window.location.href = 'mi_cuenta.php?activo=2'</script>";
}
else if($requiere_talles==3){
require_once('control/productos/classes/class.tallesColores.php');
$pedido = $_POST['pedido'];
$canTotal = 0;
foreach($pedido as $kz => $vz):
foreach($vz['talle'] as $k => $v):
$canTotal += (int)$v;
endforeach;
endforeach;
$limite = $tempMaxCompra->getMaxCompra($id_producto);
if((int)$canTotal > (int)$limite):
$_SESSION["notification"] = "Disculpe, no se encuentra disponible la cantidad seleccionada.";
@header('location: carrito.php');
exit();
endif;
$tempMaxCompra->storeSum($id_producto,$canTotal);
try {
$stock = new TempStock();
$stock->setTallesColores($id_producto,$_POST['pedido'],$_SESSION['MM_IdUsuario']);
} catch (Exception $e) {
echo($e->getMessage());
}
$id_usuario = $_SESSION['MM_IdUsuario'];
//primero chequeo si el producto ya existe en el carrito del usuario.
include_once("includes/class.carrito.php");
// $carr = new carrito();
$x = new tallesColores();
foreach($pedido as $k => $v):
foreach($v['talle'] as $kt => $vt):
if ( (int)$vt > 0 ) {
$x->usuario = $_SESSION['MM_IdUsuario'];
$x->producto = $id_producto;
$x->color = $k;
$x->talle = $kt;
$x->cantidad = $vt;
$x->insert();
}
endforeach;
endforeach;
@header('location: carrito.php');
exit();
}
else{
$tempMaxCompra->storeSum($id_producto,$cantidad_elegida);
try {
$stock = new TempStock();
$stock->setComunes($id_producto,$cantidad_elegida,$_SESSION['MM_IdUsuario']);
} catch (Exception $e) {
echo($e->getMessage());
}
//Hay stock
//No requiere talles
if($cantidad_elegida <= $StockActual){
//hay en stock y guarda la compra.
//primero chequeo si el producto ya existe en el carrito del usuario.
include_once("includes/class.carrito.php");
$carr = new carrito();
$cantidad_en_carrito = $carr->chequear_producto($_SESSION['MM_IdUsuario'],$id_producto);
if($cantidad_en_carrito > 0){
//El producto ya existe en el carrito del usuario, solo actualizo la cantidad
$traigo_id = new carrito();
$traigo_id->select_by_usuario_producto($_SESSION['MM_IdUsuario'],$id_producto);
$id_row = $traigo_id->getintContador();
//Actualizo cantidad
$update_carrito = new carrito();
$update_carrito->select($id_row);
$update_carrito->intCantidad = $cantidad_en_carrito + $cantidad_elegida;
$update_carrito->update($id_row);
@header('location: carrito.php');
exit();
}else{
//No hay de este producto en el carrito, lo ingreso como nuevo
include_once("includes/class.carrito.php");
$carr = new carrito();
$carr->idUsuario = $_SESSION['MM_IdUsuario'];
$carr->idProducto = $id_producto;
$carr->intCantidad = $cantidad_elegida;
$carr->insert();
@header('location: carrito.php');
exit();
}
}else{
//No hay stock disponible
// $_SESSION["notification"] = "Disculpe, no se encuentra disponible la cantidad seleccionada.";
@header('location: carrito.php');
exit();
}//end else stock
}//end else (requiere talles)
// header('location: http://nufarm-maxx.com/marketingNetDesarrollo/carrito.php');
@header('location: carrito.php');
exit();
?>