PluginProbe
Welcart e-Commerce / 1.3.9
Welcart e-Commerce v1.3.9
2.12.4 2.12.3 2.11.35 2.12.2 2.12.1 2.11.34 2.11.33 2.11.32 2.11.31 2.11.30 1.3.16 1.3.17 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 292 releases
usc-e-shop / classes / cart.class.php

cart.class.php in Welcart e-Commerce 1.3.9, at classes/cart.class.php

593 lines 17.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 //*****************************************************************************
3 //cart.class.php
4 //*****************************************************************************
5 class usces_cart {
6
7 var $serial;
8
9 function usces_cart() {
10
11 if ( !isset($_SESSION['usces_cart']) ) {
12 $_SESSION['usces_cart'] = array();
13 $_SESSION['usces_entry'] = array();
14 }
15
16 }
17 // into Cart ***************************************************************
18 function inCart() {
19 global $usces;
20 $_POST = $usces->stripslashes_deep_post($_POST);
21
22 if( $_SERVER['HTTP_REFERER'] ){
23 $_SESSION['usces_previous_url'] = $_SERVER['HTTP_REFERER'];
24 }else{
25 $_SESSION['usces_previous_url'] = str_replace('https://', 'http://', get_home_url()).'/';
26 }
27
28 $ids = array_keys($_POST['inCart']);
29 $post_id = $ids[0];
30
31 $skus = array_keys($_POST['inCart'][$post_id]);
32 $sku = $skus[0];
33
34 $this->in_serialize($post_id, $sku);
35 if( !isset($_SESSION['usces_cart'][$this->serial]['quant']) ){
36 $_SESSION['usces_cart'][$this->serial]['quant'] = 0;
37 }
38
39 if ( isset($_POST['quant'][$post_id][$sku]) && !WCUtils::is_blank($_POST['quant'][$post_id][$sku]) ) {
40
41 $post_quant = (int)$_POST['quant'][$post_id][$sku];
42 $_SESSION['usces_cart'][$this->serial]['quant'] = apply_filters('usces_filter_post_quant', $post_quant, $_SESSION['usces_cart'][$this->serial]['quant']);
43
44 } else {
45
46 if ( isset($_SESSION['usces_cart'][$this->serial]) )
47 $_SESSION['usces_cart'][$this->serial]['quant'] = apply_filters('usces_filter_post_quant', 1, $_SESSION['usces_cart'][$this->serial]['quant']);
48 else
49 $_SESSION['usces_cart'][$this->serial]['quant'] = 1;
50
51 $_SESSION['usces_cart'][$this->serial]['quant'] = apply_filters('usces_filter_inCart_quant', $_SESSION['usces_cart'][$this->serial]['quant']);
52
53 }
54
55
56 if ( isset($_POST['skuPrice']) && !WCUtils::is_blank($_POST['skuPrice'][$post_id][$sku]) ) {
57 $price = $this->get_realprice($post_id, $sku, $_SESSION['usces_cart'][$this->serial]['quant']);
58 $price = apply_filters('usces_filter_inCart_price', $price, $this->serial);
59 $_SESSION['usces_cart'][$this->serial]['price'] = $price;
60 }
61
62 if ( isset($_POST['advance']) ) {
63 $_SESSION['usces_cart'][$this->serial]['advance'] = $this->wc_serialize($_POST['advance']);
64 }
65
66 do_action('usces_action_after_inCart', $this->serial);
67 }
68
69 // update Cart ***************************************************************
70 function upCart() {
71
72 if(!isset($_POST['quant'])) return false;
73
74 global $usces;
75 $_POST = $usces->stripslashes_deep_post($_POST);
76
77 foreach($_POST['quant'] as $index => $vs){
78
79 $ids = array_keys($vs);
80 $post_id = $ids[0];
81
82 $skus = array_keys($vs[$post_id]);
83 $sku = $skus[0];
84
85 $this->up_serialize($index, $post_id, $sku);
86
87 if ( !WCUtils::is_blank($_POST['quant'][$index][$post_id][$sku]) ) {
88
89 $_SESSION['usces_cart'][$this->serial]['quant'] = (int)$_POST['quant'][$index][$post_id][$sku];
90 $_SESSION['usces_cart'][$this->serial]['advance'] = isset($_POST['advance'][$index][$post_id][$sku]) ? $this->wc_unserialize($_POST['advance'][$index][$post_id][$sku]) : array();
91 if( isset($_POST['order_action']) ){
92 $price = (int)$_POST['skuPrice'][$index][$post_id][$sku];
93 }else{
94 $price = $this->get_realprice($post_id, $sku, $_SESSION['usces_cart'][$this->serial]['quant']);
95 $price = apply_filters('usces_filter_upCart_price', $price, $this->serial, $index);
96 }
97 $_SESSION['usces_cart'][$this->serial]['price'] = $price;
98
99 }
100 }
101
102 unset( $_SESSION['usces_entry']['order']['usedpoint'] );
103 do_action('usces_action_after_upCart');
104 }
105
106 // inCart_advance ****************************************************************
107 function inCart_advance( $serial, $name, $key, $value ){
108 $_SESSION['usces_cart'][$serial]['advance'][$name][$key] = $value;
109 }
110
111 // serialize ****************************************************************
112 function wc_serialize( $value ){
113 $out = NULL;
114 if( !empty($value) )
115 // $out = urlencode(serialize($value));
116 $out = serialize($value);
117 return $out;
118 }
119
120 function wc_unserialize( $str ){
121 $out = array();
122 if( !empty($str) )
123 // $out = unserialize(urldecode($str));
124 $out = unserialize($str);
125 return $out;
126 }
127
128 // get data by index ****************************************************************
129 // function get_row($index) {
130 //
131 // if ( !isset($_SESSION['usces_cart']['post_id'][$index]) ) {
132 // return false;
133 //
134 // } else {
135 // $post_id = $_SESSION['usces_cart']['post_id'][$index];
136 // $item_quantity = $_SESSION['usces_cart']['item_quantity'][$index];
137 //
138 // $rows = compact('post_id', 'item_quantity');
139 // return $rows;
140 // }
141 // }
142
143 // delete data by index ***************************************************************
144 function del_row() {
145
146 $indexs = array_keys($_POST['delButton']);
147 $index = $indexs[0];
148 $ids = array_keys($_POST['delButton'][$index]);
149 $post_id = $ids[0];
150 $skus = array_keys($_POST['delButton'][$index][$post_id]);
151 $sku = $skus[0];
152
153 $this->up_serialize($index, $post_id, $sku);
154 do_action('usces_cart_del_row', $index);
155
156 if(isset($_SESSION['usces_cart'][$this->serial]))
157 unset($_SESSION['usces_cart'][$this->serial]);
158
159 unset( $_SESSION['usces_entry']['order']['usedpoint'] );
160 do_action('usces_action_after_cart_del_row', $index);
161 }
162
163 // number of data in cart ***********************************************************
164 function num_row() {
165 if( !isset($_SESSION['usces_cart']) )
166 return false;
167
168 $num = count($_SESSION['usces_cart']);
169
170 if( $num > 0 ) {
171 return $num;
172 } else {
173 return false;
174 }
175 }
176
177 // clear cart ****************************************************************
178 function crear_cart() {
179 $_SESSION['usces_cart'] = array();
180 $_SESSION['usces_entry'] = array();
181 }
182
183 // cart associative array ***********************************************************
184 function get_cart() {
185
186 if(!isset($_SESSION['usces_cart'])) return false;
187
188 $rows = array();
189
190 $i = 0;
191 foreach($_SESSION['usces_cart'] as $serial => $qua) {
192 $array = $this->key_unserialize($serial);
193
194 $rows[$i] = $array;
195
196 $i++;
197 }
198
199 return $rows;
200 }
201
202 // insert serialize **************************************************************
203 function in_serialize($id, $sku){
204
205 global $usces;
206 $_POST = $usces->stripslashes_deep_post($_POST);
207
208 if(isset($_POST['itemOption'])){
209 foreach( $_POST['itemOption'][$id][$sku] as $key => $value ){
210 //20110629ysk start 0000190
211 //$pots[$key] = urlencode($value);
212 if( is_array($value) ) {
213 foreach( $value as $k => $v ) {
214 $pots[$key][urlencode(trim($v))] = urlencode(trim($v));
215 }
216 } else {
217 $pots[$key] = urlencode($value);
218 }
219 //20110629ysk end
220 }
221 $sels[$id][$sku] = $pots;
222 }else{
223 $sels[$id][$sku] = 0;
224 }
225 $sels = apply_filters('usces_filter_in_serialize', $sels, $id, $sku);
226 $this->serial = serialize($sels);
227 }
228
229 // update serialize **************************************************************
230 function up_serialize($index, $id, $sku){
231
232 global $usces;
233 $_POST = $usces->stripslashes_deep_post($_POST);
234
235 if(isset($_POST['itemOption'][$index])){
236 foreach( $_POST['itemOption'][$index][$id][$sku] as $key => $value ){
237 //20110629ysk start 0000190
238 //$pots[$key] = $value;
239 if( is_array($value) ) {
240 foreach( $value as $k => $v ) {
241 $pots[$key][$v] = $v;
242 }
243 } else {
244 $pots[$key] = $value;
245 }
246 //20110629ysk end
247 }
248 $sels[$id][$sku] = $pots;
249 }else{
250 $sels[$id][$sku] = 0;
251 }
252 $sels = apply_filters('usces_filter_up_serialize', $sels, $index, $id, $sku);
253 $this->serial = serialize($sels);
254 }
255
256 // key unserialize **************************************************************
257 function key_unserialize($serial){
258
259 $array = unserialize($serial);
260 $ids = array_keys($array);
261 $skus = array_keys($array[$ids[0]]);
262
263 $row['serial'] = $serial;
264 $row['post_id'] = $ids[0];
265 $row['sku'] = $skus[0];
266 $row['options'] = apply_filters('usces_filter_key_unserialize_options', $array[$ids[0]][$skus[0]], $ids[0], $skus[0]);
267 $row['price'] = isset($_SESSION['usces_cart'][$serial]['price']) ? $_SESSION['usces_cart'][$serial]['price'] : 0;
268 $row['quantity'] = $_SESSION['usces_cart'][$serial]['quant'];
269 $row['advance'] = isset($_SESSION['usces_cart'][$serial]['advance']) ? $_SESSION['usces_cart'][$serial]['advance'] : array();
270
271 return $row;
272 }
273
274 // is order condition ***************************************************************
275 function is_order_condition() {
276 if ( isset($_SESSION['usces_entry']['condition']) )
277 return true;
278 else
279 return false;
280 }
281
282 // set order condition ***************************************************************
283 function set_order_condition( $conditions ) {
284 foreach( $conditions as $key => $value )
285 $_SESSION['usces_entry']['condition'][$key] = $value;
286 }
287
288 // get order condition ***************************************************************
289 function get_order_condition() {
290 if(isset($_SESSION['usces_entry']['condition']))
291 return $_SESSION['usces_entry']['condition'];
292 else
293 return NULL;
294 }
295
296 // entry information ***************************************************************
297 function set_order_entry( $array ) {
298 foreach ( $array as $key => $value )
299 $_SESSION['usces_entry']['order'][$key] = $value;
300 }
301 //20110203ysk start
302 // get entry information ***************************************************************
303 function get_order_entry( $key ) {
304 return $_SESSION['usces_entry']['order'][$key];
305 }
306 //20110203ysk end
307 // entry information ***************************************************************
308 function entry() {
309 global $usces;
310 $_POST = $usces->stripslashes_deep_post($_POST);
311
312 if(isset($_SESSION['usces_member']['ID']) && !empty($_SESSION['usces_member']['ID'])) {
313 //20110126ysk start
314 if($usces->page !== 'confirm') {
315 foreach( $_SESSION['usces_member'] as $key => $value ){
316 //20100818ysk start
317 if($key === 'custom_member') {
318 //20101008ysk start
319 unset($_SESSION['usces_entry']['custom_member']);
320 //20101008ysk end
321 foreach( $_SESSION['usces_member']['custom_member'] as $mbkey => $mbvalue ) {
322 if(empty($_SESSION['usces_entry']['custom_customer'][$mbkey])) {
323 if( is_array($mbvalue) ) {
324 foreach( $mbvalue as $k => $v ) {
325 $_SESSION['usces_entry']['custom_customer'][$mbkey][$v] = $v;
326 }
327 } else {
328 $_SESSION['usces_entry']['custom_customer'][$mbkey] = $mbvalue;
329 }
330 }
331 }
332 } else {
333 //if(empty($_SESSION['usces_entry']['customer'][$key])) {
334 if( 'country' == $key && empty($value) ){
335 $_SESSION['usces_entry']['customer'][$key] = usces_get_base_country();//20110513ysk
336 }else{
337 $_SESSION['usces_entry']['customer'][$key] = trim($value);
338 }
339 //}
340 }
341 //20100818ysk end
342 }
343 }
344 }
345 //} else if(isset($_POST['customer'])) {
346 if(isset($_POST['customer'])) {
347 foreach( $_POST['customer'] as $key => $value ){
348 if( 'country' == $key && empty($value) ){
349 $_SESSION['usces_entry']['customer'][$key] = usces_get_base_country();//20110513ysk
350 }else{
351 $_SESSION['usces_entry']['customer'][$key] = trim($value);
352 }
353 }
354 }
355 //20110126ysk end
356
357 if(isset($_POST['delivery'])) {
358 foreach( $_POST['delivery'] as $key => $value )
359 if( 'country' == $key && empty($value) ){
360 $_SESSION['usces_entry']['delivery'][$key] = usces_get_base_country();//20110513ysk
361 }else{
362 $_SESSION['usces_entry']['delivery'][$key] = trim($value);
363 }
364 }
365
366 if(isset($_POST['delivery']['delivery_flag']) && $_POST['delivery']['delivery_flag'] == 0) {
367 foreach( $_SESSION['usces_entry']['customer'] as $key => $value )
368 if( 'country' == $key && empty($value) ){
369 $_SESSION['usces_entry']['delivery'][$key] = usces_get_base_country();//20110513ysk
370 }else{
371 $_SESSION['usces_entry']['delivery'][$key] = trim($value);
372 }
373 }
374
375 if(isset($_POST['offer'])) {
376 foreach( $_POST['offer'] as $key => $value )
377 $_SESSION['usces_entry']['order'][$key] = trim($value);
378 }
379
380 if(isset($_POST['reserve'])) {
381 foreach( $_POST['reserve'] as $key => $value )
382 $_SESSION['usces_entry']['reserve'][$key] = trim($value);
383 }
384 //20100809ysk start
385 if(isset($_POST['custom_order'])) {
386 //20101008ysk start
387 unset($_SESSION['usces_entry']['custom_order']);
388 //20101008ysk end
389 foreach( $_POST['custom_order'] as $key => $value )
390 if ( is_array($value) ) {
391 foreach( $value as $k => $v ) {
392 $_SESSION['usces_entry']['custom_order'][$key][trim($v)] = trim($v);
393 }
394 } else {
395 $_SESSION['usces_entry']['custom_order'][$key] = trim($value);
396 }
397 }
398 //20100809ysk end
399 //20110106ysk start
400 if( isset($_SESSION['usces_entry']['delivery']['delivery_flag']) && $_SESSION['usces_entry']['delivery']['delivery_flag'] == 0 ) {//20131009ysk
401 $this->set_custom_customer_delivery();
402 }
403 //20110106ysk end
404 //20100818ysk start
405 if(isset($_POST['custom_customer'])) {
406 //20101008ysk start
407 unset($_SESSION['usces_entry']['custom_customer']);
408 //20101008ysk end
409 foreach( $_POST['custom_customer'] as $key => $value )
410 if ( is_array($value) ) {
411 foreach( $value as $k => $v ) {
412 $_SESSION['usces_entry']['custom_customer'][$key][trim($v)] = trim($v);
413 }
414 } else {
415 $_SESSION['usces_entry']['custom_customer'][$key] = trim($value);
416 }
417 }
418 if(isset($_POST['custom_delivery'])) {
419 //20101008ysk start
420 unset($_SESSION['usces_entry']['custom_delivery']);
421 //20101008ysk end
422 foreach( $_POST['custom_delivery'] as $key => $value )
423 if ( is_array($value) ) {
424 foreach( $value as $k => $v ) {
425 $_SESSION['usces_entry']['custom_delivery'][$key][trim($v)] = trim($v);
426 }
427 } else {
428 $_SESSION['usces_entry']['custom_delivery'][$key] = trim($value);
429 }
430 }
431 //20110106ysk start
432 if(isset($_POST['delivery']['delivery_flag']) && $_POST['delivery']['delivery_flag'] == 0) {
433 $this->set_custom_customer_delivery();
434 }
435 //20110106ysk end
436 }
437
438 // get entry information ***************************************************************
439 function get_entry() {
440
441 $res['customer'] = array(
442 'mailaddress1' => '',
443 'mailaddress2' => '',
444 'password1' => '',
445 'password2' => '',
446 'name1' => '',
447 'name2' => '',
448 'name3' => '',
449 'name4' => '',
450 'zipcode' => '',
451 'address1' => '',
452 'address2' => '',
453 'address3' => '',
454 'tel' => '',
455 'fax' => '',
456 'country' => '',
457 'pref' => ''
458 );
459 if(isset($_SESSION['usces_entry']['customer'])){
460 foreach((array)$_SESSION['usces_entry']['customer'] as $key => $val){
461 $res['customer'][$key] = $val;
462 }
463 }
464
465 $res['delivery'] = array(
466 'name1' => '',
467 'name2' => '',
468 'name3' => '',
469 'name4' => '',
470 'zipcode' => '',
471 'address1' => '',
472 'address2' => '',
473 'address3' => '',
474 'tel' => '',
475 'fax' => '',
476 'country' => '',
477 'pref' => '',
478 'delivery_flag' => ''
479 );
480 if(isset($_SESSION['usces_entry']['delivery'])){
481 foreach((array)$_SESSION['usces_entry']['delivery'] as $key => $val){
482 $res['delivery'][$key] = $val;
483 }
484 }
485
486 $res['order'] = array(
487 'usedpoint' => '',
488 'total_items_price' => '',
489 'discount' => '',
490 'shipping_charge' => '',
491 'cod_fee' => '',
492 'shipping_charge' => '',
493 'payment_name' => '',
494 'delivery_method' => '',
495 'delivery_date' => '',
496 'delivery_time' => '',
497 'total_full_price' => '',
498 'note' => '',
499 'tax' => '',
500 'payment_name' => '',
501 'delidue_date' => ''
502 );
503 if(isset($_SESSION['usces_entry']['order'])){
504 foreach((array)$_SESSION['usces_entry']['order'] as $key => $val){
505 $res['order'][$key] = $val;
506 }
507 }
508
509 if(isset($_SESSION['usces_entry']['reserve']))
510 $res['reserve'] = $_SESSION['usces_entry']['reserve'];
511 else
512 $res['reserve'] = NULL;
513
514 if(isset($_SESSION['usces_entry']['condition']))
515 $res['condition'] = $_SESSION['usces_entry']['condition'];
516 else
517 $res['condition'] = NULL;
518
519 //20100809ysk start
520 if(isset($_SESSION['usces_entry']['custom_order']))
521 $res['custom_order'] = $_SESSION['usces_entry']['custom_order'];
522 else
523 $res['custom_order'] = NULL;
524 //20100809ysk end
525 //20100818ysk start
526 if(isset($_SESSION['usces_entry']['custom_customer']))
527 $res['custom_customer'] = $_SESSION['usces_entry']['custom_customer'];
528 else
529 $res['custom_customer'] = NULL;
530 if(isset($_SESSION['usces_entry']['custom_delivery']))
531 $res['custom_delivery'] = $_SESSION['usces_entry']['custom_delivery'];
532 else
533 $res['custom_delivery'] = NULL;
534 //20100818ysk end
535 return $res;
536
537 }
538 // get realprice ***************************************************************
539 function get_realprice($post_id, $sku, $quant, $price = NULL) {
540 global $usces;
541 $sku = urldecode($sku);
542 $skus = $usces->get_skus( $post_id, 'code' );
543
544 if($price === NULL) {
545 $p = $skus[$sku]['price'];
546 } else {
547 $p = $price;
548 }
549 //20110905ysk start 0000251
550 $p = apply_filters('usces_filter_realprice', $p, $this->serial);
551 //20110905ysk end
552 if( !$skus[$sku]['gp'] ) return $p;
553
554 $realprice = usces_get_gp_price($post_id, $p, $quant);
555
556 return $realprice;
557 }
558
559 function set_pre_order_id($id){
560 $_SESSION['usces_entry']['reserve']['pre_order_id'] = $id;
561 }
562
563 //20110106ysk start
564 function set_custom_customer_delivery() {
565 if(isset($_SESSION['usces_entry']['custom_customer'])) {
566 $delivery = array();
567 $csde_meta = usces_has_custom_field_meta('delivery');
568 if(!empty($csde_meta) and is_array($csde_meta)) {
569 foreach($csde_meta as $key => $entry) {
570 $delivery[$key] = $key;
571 }
572 }
573 foreach( $_SESSION['usces_entry']['custom_customer'] as $mbkey => $mbvalue ) {
574 if(array_key_exists($mbkey, $delivery)) {
575 //20110126ysk start
576 if(empty($_SESSION['usces_entry']['custom_delivery'][$mbkey])) {
577 if( is_array($mbvalue) ) {
578 foreach( $mbvalue as $k => $v ) {
579 $_SESSION['usces_entry']['custom_delivery'][$mbkey][$v] = $v;
580 }
581 } else {
582 $_SESSION['usces_entry']['custom_delivery'][$mbkey] = $mbvalue;
583 }
584 }
585 //20110126ysk end
586 }
587 }
588 }
589 }
590 //20110106ysk end
591 }
592 ?>
593