PluginProbe
Welcart e-Commerce / 2.11.35
Welcart e-Commerce v2.11.35
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 2.11.35, at classes/cart.class.php

788 lines 22.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Cart class
4 */
5 class usces_cart {
6
7 /**
8 * Serial key
9 *
10 * @var string
11 */
12 var $serial;
13
14 /**
15 * Constructor
16 */
17 public function __construct() {
18
19 if ( ! isset( $_SESSION['usces_cart'] ) ) {
20 $_SESSION['usces_cart'] = array();
21 $_SESSION['usces_entry'] = array();
22 }
23 }
24
25 /**
26 * Create instance
27 *
28 * @param string $serial Serial key.
29 * @return object
30 */
31 public static function create( $serial ) {
32 $instance = new self();
33 $instance->serial = $serial;
34
35 return $instance;
36 }
37
38 /**
39 * Add to Cart
40 */
41 public function inCart() {
42 global $usces;
43
44 $_POST = $usces->stripslashes_deep_post( $_POST );
45 if ( $_SERVER['HTTP_REFERER'] ) {
46 $_SESSION['usces_previous_url'] = esc_url( $_SERVER['HTTP_REFERER'] );
47 } else {
48 $_SESSION['usces_previous_url'] = str_replace( 'https://', 'http://', get_home_url() ) . '/';
49 }
50
51 $ids = array_keys( $_POST['inCart'] );
52 $post_id = (int) $ids[0];
53
54 $skus = array_keys( $_POST['inCart'][ $post_id ] );
55 $sku = $skus[0];
56
57 $zaiko_id = $usces->getItemZaikoStatusId( $post_id, urldecode( $sku ) );
58 if ( false === $zaiko_id ) {
59 header( 'HTTP/1.0 400 Bad request' );
60 die();
61 }
62
63 $this->in_serialize( $post_id, $sku );
64 if ( ! isset( $_SESSION['usces_cart'][ $this->serial ]['quant'] ) ) {
65 $_SESSION['usces_cart'][ $this->serial ]['quant'] = 0;
66 }
67
68 if ( isset( $_POST['quant'][ $post_id ][ $sku ] ) && ! WCUtils::is_blank( $_POST['quant'][ $post_id ][ $sku ] ) ) {
69
70 $post_quant = (int) $_POST['quant'][ $post_id ][ $sku ];
71 $_SESSION['usces_cart'][ $this->serial ]['quant'] = apply_filters( 'usces_filter_post_quant', $post_quant, $_SESSION['usces_cart'][ $this->serial ]['quant'] );
72
73 } else {
74
75 if ( isset( $_SESSION['usces_cart'][ $this->serial ] ) ) {
76 $_SESSION['usces_cart'][ $this->serial ]['quant'] = apply_filters( 'usces_filter_post_quant', 1, $_SESSION['usces_cart'][ $this->serial ]['quant'] );
77 } else {
78 $_SESSION['usces_cart'][ $this->serial ]['quant'] = 1;
79 }
80 $_SESSION['usces_cart'][ $this->serial ]['quant'] = apply_filters( 'usces_filter_inCart_quant', $_SESSION['usces_cart'][ $this->serial ]['quant'] );
81
82 }
83
84 $price = $this->get_realprice( $post_id, $sku, $_SESSION['usces_cart'][ $this->serial ]['quant'], null, $unit_price );
85 $price = apply_filters( 'usces_filter_inCart_price', $price, $this->serial );
86
87 $_SESSION['usces_cart'][ $this->serial ]['price'] = $price;
88 $_SESSION['usces_cart'][ $this->serial ]['unit_price'] = $unit_price;
89
90 if ( isset( $_POST['advance'] ) ) {
91 $_SESSION['usces_cart'][ $this->serial ]['advance'] = $this->wc_serialize( $_POST['advance'] );
92 }
93
94 unset( $_SESSION['usces_entry']['order']['usedpoint'] );
95 do_action( 'usces_action_after_inCart', $this->serial );
96 }
97
98 /**
99 * Update Cart
100 */
101 public function upCart() {
102
103 if ( ! isset( $_POST['quant'] ) ) {
104 return false;
105 }
106
107 global $usces;
108 $_POST = $usces->stripslashes_deep_post( $_POST );
109 $keys = array_keys( $_SESSION['usces_cart'] );
110
111 $serial_option = apply_filters( 'usces_filter_upcart_serial_option', false );
112
113 $index = 0;
114 foreach ( $_POST['quant'] as $vs ) {
115
116 if ( ! is_array( $vs ) ) {
117 break;
118 }
119
120 if ( ! isset( $_POST['quant'][ $index ] ) ) {
121 continue;
122 }
123
124 $res = apply_filters( 'usces_filter_upCart_check', '', $index, $vs );
125 if ( '' !== $res ) {
126 return $res;
127 }
128
129 $ids = array_keys( $vs );
130 $post_id = $ids[0];
131
132 $skus = array_keys( $vs[ $post_id ] );
133 $sku = $skus[0];
134
135 $sku_decode = urldecode( $sku );
136
137 $skus = $usces->get_skus( $post_id, 'code' );
138
139 if ( ! $skus || ! isset( $skus[ $sku_decode ] ) ) {
140 continue;
141 }
142
143 if ( $serial_option ) {
144 $this->up_serialize( $index, $post_id, $sku );
145 } else {
146 $this->serial = $keys[ $index ];
147 }
148
149 if ( ! WCUtils::is_blank( $_POST['quant'][ $index ][ $post_id ][ $sku ] ) ) {
150
151 $_SESSION['usces_cart'][ $this->serial ]['quant'] = (int) $_POST['quant'][ $index ][ $post_id ][ $sku ];
152 $_SESSION['usces_cart'][ $this->serial ]['advance'] = isset( $_POST['advance'][ $index ][ $post_id ][ $sku ] ) ? $_POST['advance'][ $index ][ $post_id ][ $sku ] : array();
153
154 // if ( isset( $_POST['order_action'] ) ) {
155 // $price = (int) $_POST['skuPrice'][ $index ][ $post_id ][ $sku ];
156 // } else {
157 $price = $this->get_realprice( $post_id, $sku, $_SESSION['usces_cart'][ $this->serial ]['quant'] );
158 $price = apply_filters( 'usces_filter_upCart_price', $price, $this->serial, $index );
159 // }
160 $_SESSION['usces_cart'][ $this->serial ]['price'] = $price;
161
162 }
163
164 $index++;
165 }
166
167 unset( $_SESSION['usces_entry']['order']['usedpoint'] );
168 do_action( 'usces_action_after_upCart' );
169
170 return false;
171 }
172
173 /**
174 * Add to Cart additional information
175 *
176 * @param string $serial Serial key.
177 * @param string $name Advance name.
178 * @param string $key Advance key.
179 * @param mixed $value Advance value.
180 */
181 public function inCart_advance( $serial, $name, $key, $value ) {
182 $_SESSION['usces_cart'][ $serial ]['advance'][ $name ][ $key ] = $value;
183 }
184
185 /**
186 * Serialize value
187 *
188 * @param array $value Value.
189 * @return string
190 */
191 public function wc_serialize( $value ) {
192 $out = null;
193 if ( ! empty( $value ) ) {
194 $out = urlencode( json_encode( $value ) );
195 }
196 return $out;
197 }
198
199 /**
200 * Unserialize value
201 *
202 * @param string $str Value.
203 * @return array
204 */
205 public function wc_unserialize( $str ) {
206 $out = array();
207 if ( ! empty( $str ) ) {
208 $out = json_decode( urldecode( $str ), true );
209 }
210 return $out;
211 }
212
213 /**
214 * Remove Cart
215 */
216 public function del_row() {
217 $indexs = array_keys( $_POST['delButton'] );
218 $index = $indexs[0];
219 $ids = array_keys( $_POST['delButton'][ $index ] );
220 $post_id = $ids[0];
221 $skus = array_keys( $_POST['delButton'][ $index ][ $post_id ] );
222 $sku = $skus[0];
223
224 $this->up_serialize( $index, $post_id, $sku );
225 do_action( 'usces_cart_del_row', $index );
226
227 if ( isset( $_SESSION['usces_cart'][ $this->serial ] ) ) {
228 unset( $_SESSION['usces_cart'][ $this->serial ] );
229 }
230 unset( $_SESSION['usces_entry']['order']['usedpoint'] );
231 do_action( 'usces_action_after_cart_del_row', $index );
232 }
233
234 /**
235 * Number of rows in cart
236 *
237 * @return int|bool
238 */
239 public function num_row() {
240 if ( ! isset( $_SESSION['usces_cart'] ) ) {
241 return false;
242 }
243
244 $num = ( is_array( $_SESSION['usces_cart'] ) ) ? count( $_SESSION['usces_cart'] ) : 0;
245
246 if ( $num > 0 ) {
247 return $num;
248 } else {
249 return false;
250 }
251 }
252
253 /**
254 * Clear Cart
255 * alias crear_cart()
256 */
257 public function clear_cart() {
258 $this->crear_cart();
259 }
260 /**
261 * Clear Cart
262 */
263 public function crear_cart() {
264 $_SESSION['usces_cart'] = array();
265 $_SESSION['usces_entry'] = array();
266 do_action( 'usces_action_after_clear_cart' );
267 }
268
269 /**
270 * Get Cart
271 *
272 * @return array
273 */
274 public function get_cart() {
275 if ( ! isset( $_SESSION['usces_cart'] ) ) {
276 return array();
277 }
278
279 $rows = array();
280
281 $i = 0;
282 foreach ( (array) $_SESSION['usces_cart'] as $serial => $qua ) {
283 $rows[ $i ] = $this->key_unserialize( $serial );
284 $i++;
285 }
286
287 return $rows;
288 }
289
290 /**
291 * Serial key creation
292 *
293 * @param int $id Post ID.
294 * @param string $sku SKU code.
295 */
296 public function in_serialize( $id, $sku ) {
297 global $usces;
298
299 $_POST = $usces->stripslashes_deep_post( $_POST );
300 $pots = array();
301 $option_field = usces_get_opts( $id, 'name' );
302
303 foreach ( $option_field as $opkey => $opval ) {
304 if ( ! isset( $_POST['itemOption'][ $id ][ $sku ][ urlencode( $opkey ) ] ) ) {
305 if ( 3 === (int) $opval['means'] || 4 === (int) $opval['means'] ) {
306 $pots[ urlencode( $opkey ) ] = '';
307 }
308 }
309 }
310
311 if ( isset( $_POST['itemOption'][ $id ][ $sku ] ) ) {
312 foreach ( $_POST['itemOption'][ $id ][ $sku ] as $key => $value ) {
313 if ( ! isset( $option_field[ urldecode( $key ) ] ) ) {
314 continue;
315 }
316
317 $option = $option_field[ urldecode( $key ) ];
318 if ( 3 === (int) $option['means'] || 4 === (int) $option['means'] ) {
319 if ( is_array( $value ) ) {
320 foreach ( $value as $k => $v ) {
321 $v = trim( wel_safe_text_serialize( $v ) );
322 $pots[ $key ][ $v ] = $v;
323 }
324 } else {
325 $pots[ $key ] = wel_safe_text_serialize( $value );
326 }
327 } else {
328 if ( is_array( $value ) ) {
329 foreach ( $value as $k => $v ) {
330 $pots[ $key ][ urlencode( trim( $v ) ) ] = urlencode( trim( $v ) );
331 }
332 } else {
333 $pots[ $key ] = urlencode( $value );
334 }
335 }
336 }
337 ksort( $pots );
338 $sels[ $id ][ $sku ] = $pots;
339 } else {
340 if ( empty( $pots ) ) {
341 $sels[ $id ][ $sku ] = 0;
342 } else {
343 $sels[ $id ][ $sku ] = $pots;
344 }
345 }
346 $sels = apply_filters( 'usces_filter_in_serialize', $sels, $id, $sku );
347 $this->serial = serialize( $sels );
348 }
349
350 /**
351 * Serial key recreation
352 *
353 * @param int $index Cart index.
354 * @param int $id Post ID.
355 * @param string $sku SKU code.
356 */
357 public function up_serialize( $index, $id, $sku ) {
358 global $usces;
359
360 $_POST = $usces->stripslashes_deep_post( $_POST );
361 $pots = array();
362 $option_field = usces_get_opts( $id, 'name' );
363
364 if ( isset( $_POST['itemOption'][ $index ][ $id ][ $sku ] ) && is_array( $_POST['itemOption'][ $index ][ $id ][ $sku ] ) ) {
365 foreach ( $_POST['itemOption'][ $index ][ $id ][ $sku ] as $key => $value ) {
366 if ( is_array( $value ) ) {
367 foreach ( $value as $k => $v ) {
368 $v = wel_safe_text_serialize( $v );
369 $pots[ $key ][ $v ] = $v;
370 }
371 } else {
372 $pots[ $key ] = wel_safe_text_serialize( $value );
373 }
374 }
375 ksort( $pots );
376 $sels[ $id ][ $sku ] = $pots;
377 } else {
378 $sels[ $id ][ $sku ] = 0;
379 }
380 $sels = apply_filters( 'usces_filter_up_serialize', $sels, $index, $id, $sku );
381 $this->serial = serialize( $sels );
382 }
383
384 /**
385 * Serial key decompression
386 *
387 * @param string $serial Serial key.
388 * @return array
389 */
390 public function key_unserialize( $serial ) {
391 $array = wel_safe_unserialize( $serial );
392 $ids = array_keys( $array );
393 $skus = array_keys( $array[ $ids[0] ] );
394
395 $row['serial'] = $serial;
396 $row['post_id'] = $ids[0];
397 $row['sku'] = $skus[0];
398 $options = $array[ $ids[0] ][ $skus[0] ];
399 $opt_fields = usces_get_opts( $row['post_id'], 'sort' );
400 $new_opt = array();
401 foreach ( $opt_fields as $key => $field ) {
402 $name = urlencode( $field['name'] );
403 $new_opt[ $name ] = isset( $options[ $name ] ) ? $options[ $name ] : '';
404 }
405 $row['options'] = apply_filters( 'usces_filter_key_unserialize_options', $new_opt, $ids[0], $skus[0], $serial );
406 $row['price'] = isset( $_SESSION['usces_cart'][ $serial ]['price'] ) ? $_SESSION['usces_cart'][ $serial ]['price'] : 0;
407 $row['unit_price'] = isset( $_SESSION['usces_cart'][ $serial ]['unit_price'] ) ? $_SESSION['usces_cart'][ $serial ]['unit_price'] : 0;
408 $row['quantity'] = isset( $_SESSION['usces_cart'][ $serial ]['quant'] ) ? $_SESSION['usces_cart'][ $serial ]['quant'] : 0;
409 $row['advance'] = isset( $_SESSION['usces_cart'][ $serial ]['advance'] ) ? $_SESSION['usces_cart'][ $serial ]['advance'] : '';
410
411 return $row;
412 }
413
414 /**
415 * Is condition
416 *
417 * @return bool
418 */
419 public function is_order_condition() {
420 if ( isset( $_SESSION['usces_entry']['condition'] ) ) {
421 return true;
422 } else {
423 return false;
424 }
425 }
426
427 /**
428 * Set condition
429 *
430 * @param array $conditions Condition.
431 */
432 public function set_order_condition( $conditions ) {
433 foreach ( $conditions as $key => $value ) {
434 $_SESSION['usces_entry']['condition'][ $key ] = $value;
435 }
436 }
437
438 /**
439 * Get condition
440 *
441 * @return mixed
442 */
443 public function get_order_condition() {
444 if ( isset( $_SESSION['usces_entry']['condition'] ) ) {
445 return $_SESSION['usces_entry']['condition'];
446 } else {
447 return null;
448 }
449 }
450
451 /**
452 * Set entry information
453 *
454 * @param array $array Entry data.
455 */
456 public function set_order_entry( $array ) {
457 foreach ( $array as $key => $value ) {
458 $_SESSION['usces_entry']['order'][ $key ] = $value;
459 }
460 }
461
462 /**
463 * Get entry information
464 *
465 * @param string $key Key.
466 * @return mixed
467 */
468 public function get_order_entry( $key ) {
469 if ( isset( $_SESSION['usces_entry']['order'][ $key ] ) ) {
470 return $_SESSION['usces_entry']['order'][ $key ];
471 } else {
472 return null;
473 }
474 }
475
476 /**
477 * Set entry data
478 */
479 public function entry() {
480 global $usces;
481 $_POST = $usces->stripslashes_deep_post( $_POST );
482
483 if ( isset( $_SESSION['usces_member']['ID'] ) && ! empty( $_SESSION['usces_member']['ID'] ) ) {
484
485 $usces->set_member_session_data( $_SESSION['usces_member']['ID'] );
486
487 if ( 'confirm' !== $usces->page ) {
488 foreach ( $_SESSION['usces_member'] as $key => $value ) {
489 if ( 'custom_member' === $key ) {
490 unset( $_SESSION['usces_entry']['custom_member'] );
491 foreach ( $_SESSION['usces_member']['custom_member'] as $mbkey => $mbvalue ) {
492 if ( empty( $_SESSION['usces_entry']['custom_customer'][ $mbkey] ) ) {
493 if ( is_array( $mbvalue ) ) {
494 foreach ( $mbvalue as $k => $v ) {
495 $_SESSION['usces_entry']['custom_customer'][ $mbkey ][ $v ] = $v;
496 }
497 } else {
498 $_SESSION['usces_entry']['custom_customer'][ $mbkey ] = $mbvalue;
499 }
500 }
501 }
502 } else {
503 if ( 'country' === $key && empty( $value ) ) {
504 $_SESSION['usces_entry']['customer'][ $key ] = usces_get_base_country();
505 } else {
506 $_SESSION['usces_entry']['customer'][ $key ] = trim( $value );
507 }
508 }
509 }
510 }
511 }
512 if ( isset( $_POST['customer'] ) ) {
513 foreach ( $_POST['customer'] as $key => $value ) {
514 if ( 'country' === $key && empty( $value ) ) {
515 $_SESSION['usces_entry']['customer'][ $key ] = usces_get_base_country();
516 } else {
517 $_SESSION['usces_entry']['customer'][ $key ] = trim( $value );
518 }
519 }
520 }
521
522 if ( isset( $_POST['delivery'] ) ) {
523 foreach ( $_POST['delivery'] as $key => $value ) {
524 if ( 'country' === $key && empty( $value ) ) {
525 $_SESSION['usces_entry']['delivery'][ $key ] = usces_get_base_country();
526 } else {
527 $_SESSION['usces_entry']['delivery'][ $key ] = trim( $value );
528 }
529 }
530 }
531 if ( isset( $_POST['delivery']['delivery_flag'] ) && 0 === (int) $_POST['delivery']['delivery_flag'] ) {
532 foreach ( $_SESSION['usces_entry']['customer'] as $key => $value ) {
533 if ( 'country' === $key && empty( $value ) ) {
534 $_SESSION['usces_entry']['delivery'][ $key ] = usces_get_base_country();
535 } else {
536 $_SESSION['usces_entry']['delivery'][ $key ] = trim( $value );
537 }
538 }
539 }
540
541 if ( isset( $_POST['offer'] ) ) {
542 foreach ( $_POST['offer'] as $key => $value ) {
543 $_SESSION['usces_entry']['order'][ $key ] = trim( $value );
544 }
545 }
546
547 if ( isset( $_POST['reserve'] ) ) {
548 foreach ( $_POST['reserve'] as $key => $value ) {
549 $_SESSION['usces_entry']['reserve'][ $key ] = trim( wel_safe_text_serialize( $value ) );
550 }
551 }
552 if ( isset( $_POST['custom_order'] ) ) {
553 unset( $_SESSION['usces_entry']['custom_order'] );
554 $csod_meta = usces_has_custom_field_meta( 'order' );
555 foreach ( $_POST['custom_order'] as $key => $value ) {
556 if ( ! is_array( $csod_meta ) || ! isset( $csod_meta[ $key ] ) ) {
557 continue;
558 }
559 $value = wel_safe_text_serialize( $value );
560 if ( is_array( $value ) ) {
561 foreach ( $value as $k => $v ) {
562 $_SESSION['usces_entry']['custom_order'][ $key ][ trim( $v ) ] = trim( $v );
563 }
564 } else {
565 $_SESSION['usces_entry']['custom_order'][ $key ] = trim( $value );
566 }
567 }
568 }
569 if ( isset( $_SESSION['usces_entry']['delivery']['delivery_flag'] ) && 0 === (int) $_SESSION['usces_entry']['delivery']['delivery_flag'] ) {
570 $this->set_custom_customer_delivery();
571 }
572 if ( isset( $_POST['custom_customer'] ) ) {
573 unset( $_SESSION['usces_entry']['custom_customer'] );
574 foreach ( $_POST['custom_customer'] as $key => $value ) {
575 $value = wel_safe_text_serialize( $value );
576 if ( is_array( $value ) ) {
577 foreach ( $value as $k => $v ) {
578 $_SESSION['usces_entry']['custom_customer'][ $key ][ trim( $v ) ] = trim( $v );
579 }
580 } else {
581 $_SESSION['usces_entry']['custom_customer'][ $key ] = trim( $value );
582 }
583 }
584 }
585 if ( isset( $_POST['custom_delivery'] ) ) {
586 unset( $_SESSION['usces_entry']['custom_delivery'] );
587 foreach ( $_POST['custom_delivery'] as $key => $value ) {
588 $value = wel_safe_text_serialize( $value );
589 if ( is_array( $value ) ) {
590 foreach ( $value as $k => $v ) {
591 $_SESSION['usces_entry']['custom_delivery'][ $key ][ trim( $v ) ] = trim( $v );
592 }
593 } else {
594 $_SESSION['usces_entry']['custom_delivery'][ $key ] = trim( $value );
595 }
596 }
597 }
598 if ( isset( $_POST['delivery']['delivery_flag'] ) && 0 === (int) $_POST['delivery']['delivery_flag'] ) {
599 $this->set_custom_customer_delivery();
600 }
601 }
602
603 /**
604 * Get entry data
605 *
606 * @return array
607 */
608 public function get_entry() {
609 $res['customer'] = array(
610 'mailaddress1' => '',
611 'mailaddress2' => '',
612 'password1' => '',
613 'password2' => '',
614 'name1' => '',
615 'name2' => '',
616 'name3' => '',
617 'name4' => '',
618 'zipcode' => '',
619 'address1' => '',
620 'address2' => '',
621 'address3' => '',
622 'tel' => '',
623 'fax' => '',
624 'country' => '',
625 'pref' => '',
626 );
627 if ( isset( $_SESSION['usces_entry']['customer'] ) ) {
628 foreach ( (array) $_SESSION['usces_entry']['customer'] as $key => $val ) {
629 $res['customer'][ $key ] = $val;
630 }
631 }
632
633 $res['delivery'] = array(
634 'name1' => '',
635 'name2' => '',
636 'name3' => '',
637 'name4' => '',
638 'zipcode' => '',
639 'address1' => '',
640 'address2' => '',
641 'address3' => '',
642 'tel' => '',
643 'fax' => '',
644 'country' => '',
645 'pref' => '',
646 'delivery_flag' => '0',
647 );
648 if ( isset( $_SESSION['usces_entry']['delivery'] ) ) {
649 foreach ( (array) $_SESSION['usces_entry']['delivery'] as $key => $val ) {
650 $res['delivery'][ $key ] = $val;
651 }
652 }
653
654 $res['order'] = array(
655 'usedpoint' => '',
656 'total_items_price' => '',
657 'discount' => '',
658 'shipping_charge' => '',
659 'cod_fee' => '',
660 'shipping_charge' => '',
661 'payment_name' => '',
662 'delivery_method' => '',
663 'delivery_date' => '',
664 'delivery_time' => '',
665 'total_full_price' => '',
666 'note' => '',
667 'tax' => '',
668 'payment_name' => '',
669 'delidue_date' => '',
670 );
671 if ( isset( $_SESSION['usces_entry']['order'] ) ) {
672 foreach ( (array) $_SESSION['usces_entry']['order'] as $key => $val ) {
673 $res['order'][ $key ] = $val;
674 }
675 }
676 if ( isset( $_SESSION['usces_entry']['reserve'] ) ) {
677 $res['reserve'] = $_SESSION['usces_entry']['reserve'];
678 } else {
679 $res['reserve'] = null;
680 }
681 if ( isset( $_SESSION['usces_entry']['condition'] ) ) {
682 $res['condition'] = $_SESSION['usces_entry']['condition'];
683 } else {
684 $res['condition'] = null;
685 }
686 if ( isset( $_SESSION['usces_entry']['custom_order'] ) ) {
687 $res['custom_order'] = $_SESSION['usces_entry']['custom_order'];
688 } else {
689 $res['custom_order'] = null;
690 }
691 if ( isset( $_SESSION['usces_entry']['custom_customer'] ) ) {
692 $res['custom_customer'] = $_SESSION['usces_entry']['custom_customer'];
693 } else {
694 $res['custom_customer'] = null;
695 }
696 if ( isset( $_SESSION['usces_entry']['custom_delivery'] ) ) {
697 $res['custom_delivery'] = $_SESSION['usces_entry']['custom_delivery'];
698 } else {
699 $res['custom_delivery'] = null;
700 }
701 return $res;
702 }
703
704 /**
705 * Get sales price
706 *
707 * @param int $post_id Post ID.
708 * @param string $sku SKU code.
709 * @param int $quant Quantity.
710 * @param float $price Sales price.
711 * @param float $unit_price Unit price.
712 * @return float
713 */
714 public function get_realprice( $post_id, $sku, $quant, $price = null, &$unit_price = null ) {
715 global $usces;
716
717 $sku = urldecode( $sku );
718 $skus = $usces->get_skus( $post_id, 'code' );
719
720 if ( null === $price ) {
721 $p = isset( $skus[ $sku ]['price'] ) ? $skus[ $sku ]['price'] : '';
722 } else {
723 $p = $price;
724 }
725 $p = apply_filters( 'usces_filter_realprice', $p, $this->serial );
726 $unit_price = $p;
727 if ( isset( $skus[ $sku ]['price'] ) && ! $skus[ $sku ]['gp'] ) {
728 return $p;
729 }
730
731 $realprice = usces_get_gp_price( $post_id, $p, $quant );
732
733 return $realprice;
734 }
735
736 /**
737 * Set Pre-Order ID
738 *
739 * @param string $id Pre-Order ID.
740 * @return void
741 */
742 public function set_pre_order_id( $id ) {
743 $_SESSION['usces_entry']['reserve']['pre_order_id'] = $id;
744 }
745
746 /**
747 * Transcribe membership information to shipping address information
748 *
749 * @return void
750 */
751 public function set_custom_customer_delivery() {
752 if ( isset( $_SESSION['usces_entry']['custom_customer'] ) ) {
753 $delivery = array();
754 $csde_meta = usces_has_custom_field_meta( 'delivery' );
755 if ( ! empty( $csde_meta ) && is_array( $csde_meta ) ) {
756 foreach ( $csde_meta as $key => $entry ) {
757 $delivery[ $key ] = $key;
758 }
759 }
760 foreach ( $_SESSION['usces_entry']['custom_customer'] as $mbkey => $mbvalue ) {
761 if ( array_key_exists( $mbkey, $delivery ) ) {
762 if ( is_array( $mbvalue ) ) {
763 foreach ( $mbvalue as $k => $v ) {
764 $_SESSION['usces_entry']['custom_delivery'][ $mbkey ][ $v ] = $v;
765 }
766 } else {
767 $_SESSION['usces_entry']['custom_delivery'][ $mbkey ] = $mbvalue;
768 }
769 }
770 }
771 }
772 if ( ! empty( $_SESSION['usces_entry']['custom_delivery'] ) ) {
773 foreach ( $_SESSION['usces_entry']['custom_delivery'] as $key => $value ) {
774 if ( ! isset( $_SESSION['usces_entry']['custom_customer'] ) || ! array_key_exists( $key, $_SESSION['usces_entry']['custom_customer'] ) ) {
775 // Set item empty.
776 if ( is_array( $value ) ) {
777 foreach ( $value as $k => $v ) {
778 $_SESSION['usces_entry']['custom_delivery'][ $key ][ $v ] = '';
779 }
780 } else {
781 $_SESSION['usces_entry']['custom_delivery'][ $key ] = '';
782 }
783 }
784 }
785 }
786 }
787 }
788