PluginProbe
Welcart e-Commerce / 1.4.10
Welcart e-Commerce v1.4.10
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.4.10, at classes/cart.class.php

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