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

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