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

782 lines 22.1 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 $pots[ $key ][ trim( $v ) ] = trim( $v );
322 }
323 } else {
324 $pots[ $key ] = $value;
325 }
326 } else {
327 if ( is_array( $value ) ) {
328 foreach ( $value as $k => $v ) {
329 $pots[ $key ][ urlencode( trim( $v ) ) ] = urlencode( trim( $v ) );
330 }
331 } else {
332 $pots[ $key ] = urlencode( $value );
333 }
334 }
335 }
336 ksort( $pots );
337 $sels[ $id ][ $sku ] = $pots;
338 } else {
339 if ( empty( $pots ) ) {
340 $sels[ $id ][ $sku ] = 0;
341 } else {
342 $sels[ $id ][ $sku ] = $pots;
343 }
344 }
345 $sels = apply_filters( 'usces_filter_in_serialize', $sels, $id, $sku );
346 $this->serial = serialize( $sels );
347 }
348
349 /**
350 * Serial key recreation
351 *
352 * @param int $index Cart index.
353 * @param int $id Post ID.
354 * @param string $sku SKU code.
355 */
356 public function up_serialize( $index, $id, $sku ) {
357 global $usces;
358
359 $_POST = $usces->stripslashes_deep_post( $_POST );
360 $pots = array();
361 $option_field = usces_get_opts( $id, 'name' );
362
363 if ( isset( $_POST['itemOption'][ $index ][ $id ][ $sku ] ) && is_array( $_POST['itemOption'][ $index ][ $id ][ $sku ] ) ) {
364 foreach ( $_POST['itemOption'][ $index ][ $id ][ $sku ] as $key => $value ) {
365 if ( is_array( $value ) ) {
366 foreach ( $value as $k => $v ) {
367 $pots[ $key ][ $v ] = $v;
368 }
369 } else {
370 $pots[ $key ] = $value;
371 }
372 }
373 ksort( $pots );
374 $sels[ $id ][ $sku ] = $pots;
375 } else {
376 $sels[ $id ][ $sku ] = 0;
377 }
378 $sels = apply_filters( 'usces_filter_up_serialize', $sels, $index, $id, $sku );
379 $this->serial = serialize( $sels );
380 }
381
382 /**
383 * Serial key decompression
384 *
385 * @param string $serial Serial key.
386 * @return array
387 */
388 public function key_unserialize( $serial ) {
389 $array = @unserialize( $serial );
390 $ids = array_keys( $array );
391 $skus = array_keys( $array[ $ids[0] ] );
392
393 $row['serial'] = $serial;
394 $row['post_id'] = $ids[0];
395 $row['sku'] = $skus[0];
396 $options = $array[ $ids[0] ][ $skus[0] ];
397 $opt_fields = usces_get_opts( $row['post_id'], 'sort' );
398 $new_opt = array();
399 foreach ( $opt_fields as $key => $field ) {
400 $name = urlencode( $field['name'] );
401 $new_opt[ $name ] = isset( $options[ $name ] ) ? $options[ $name ] : '';
402 }
403 $row['options'] = apply_filters( 'usces_filter_key_unserialize_options', $new_opt, $ids[0], $skus[0], $serial );
404 $row['price'] = isset( $_SESSION['usces_cart'][ $serial ]['price'] ) ? $_SESSION['usces_cart'][ $serial ]['price'] : 0;
405 $row['unit_price'] = isset( $_SESSION['usces_cart'][ $serial ]['unit_price'] ) ? $_SESSION['usces_cart'][ $serial ]['unit_price'] : 0;
406 $row['quantity'] = isset( $_SESSION['usces_cart'][ $serial ]['quant'] ) ? $_SESSION['usces_cart'][ $serial ]['quant'] : 0;
407 $row['advance'] = isset( $_SESSION['usces_cart'][ $serial ]['advance'] ) ? $_SESSION['usces_cart'][ $serial ]['advance'] : '';
408
409 return $row;
410 }
411
412 /**
413 * Is condition
414 *
415 * @return bool
416 */
417 public function is_order_condition() {
418 if ( isset( $_SESSION['usces_entry']['condition'] ) ) {
419 return true;
420 } else {
421 return false;
422 }
423 }
424
425 /**
426 * Set condition
427 *
428 * @param array $conditions Condition.
429 */
430 public function set_order_condition( $conditions ) {
431 foreach ( $conditions as $key => $value ) {
432 $_SESSION['usces_entry']['condition'][ $key ] = $value;
433 }
434 }
435
436 /**
437 * Get condition
438 *
439 * @return mixed
440 */
441 public function get_order_condition() {
442 if ( isset( $_SESSION['usces_entry']['condition'] ) ) {
443 return $_SESSION['usces_entry']['condition'];
444 } else {
445 return null;
446 }
447 }
448
449 /**
450 * Set entry information
451 *
452 * @param array $array Entry data.
453 */
454 public function set_order_entry( $array ) {
455 foreach ( $array as $key => $value ) {
456 $_SESSION['usces_entry']['order'][ $key ] = $value;
457 }
458 }
459
460 /**
461 * Get entry information
462 *
463 * @param string $key Key.
464 * @return mixed
465 */
466 public function get_order_entry( $key ) {
467 if ( isset( $_SESSION['usces_entry']['order'][ $key ] ) ) {
468 return $_SESSION['usces_entry']['order'][ $key ];
469 } else {
470 return null;
471 }
472 }
473
474 /**
475 * Set entry data
476 */
477 public function entry() {
478 global $usces;
479 $_POST = $usces->stripslashes_deep_post( $_POST );
480
481 if ( isset( $_SESSION['usces_member']['ID'] ) && ! empty( $_SESSION['usces_member']['ID'] ) ) {
482
483 $usces->set_member_session_data( $_SESSION['usces_member']['ID'] );
484
485 if ( 'confirm' !== $usces->page ) {
486 foreach ( $_SESSION['usces_member'] as $key => $value ) {
487 if ( 'custom_member' === $key ) {
488 unset( $_SESSION['usces_entry']['custom_member'] );
489 foreach ( $_SESSION['usces_member']['custom_member'] as $mbkey => $mbvalue ) {
490 if ( empty( $_SESSION['usces_entry']['custom_customer'][ $mbkey] ) ) {
491 if ( is_array( $mbvalue ) ) {
492 foreach ( $mbvalue as $k => $v ) {
493 $_SESSION['usces_entry']['custom_customer'][ $mbkey ][ $v ] = $v;
494 }
495 } else {
496 $_SESSION['usces_entry']['custom_customer'][ $mbkey ] = $mbvalue;
497 }
498 }
499 }
500 } else {
501 if ( 'country' === $key && empty( $value ) ) {
502 $_SESSION['usces_entry']['customer'][ $key ] = usces_get_base_country();
503 } else {
504 $_SESSION['usces_entry']['customer'][ $key ] = trim( $value );
505 }
506 }
507 }
508 }
509 }
510 if ( isset( $_POST['customer'] ) ) {
511 foreach ( $_POST['customer'] as $key => $value ) {
512 if ( 'country' === $key && empty( $value ) ) {
513 $_SESSION['usces_entry']['customer'][ $key ] = usces_get_base_country();
514 } else {
515 $_SESSION['usces_entry']['customer'][ $key ] = trim( $value );
516 }
517 }
518 }
519
520 if ( isset( $_POST['delivery'] ) ) {
521 foreach ( $_POST['delivery'] as $key => $value ) {
522 if ( 'country' === $key && empty( $value ) ) {
523 $_SESSION['usces_entry']['delivery'][ $key ] = usces_get_base_country();
524 } else {
525 $_SESSION['usces_entry']['delivery'][ $key ] = trim( $value );
526 }
527 }
528 }
529 if ( isset( $_POST['delivery']['delivery_flag'] ) && 0 === (int) $_POST['delivery']['delivery_flag'] ) {
530 foreach ( $_SESSION['usces_entry']['customer'] as $key => $value ) {
531 if ( 'country' === $key && empty( $value ) ) {
532 $_SESSION['usces_entry']['delivery'][ $key ] = usces_get_base_country();
533 } else {
534 $_SESSION['usces_entry']['delivery'][ $key ] = trim( $value );
535 }
536 }
537 }
538
539 if ( isset( $_POST['offer'] ) ) {
540 foreach ( $_POST['offer'] as $key => $value ) {
541 $_SESSION['usces_entry']['order'][ $key ] = trim( $value );
542 }
543 }
544
545 if ( isset( $_POST['reserve'] ) ) {
546 foreach ( $_POST['reserve'] as $key => $value ) {
547 $_SESSION['usces_entry']['reserve'][ $key ] = trim( $value );
548 }
549 }
550 if ( isset( $_POST['custom_order'] ) ) {
551 unset( $_SESSION['usces_entry']['custom_order'] );
552 foreach ( $_POST['custom_order'] as $key => $value ) {
553 $value = wel_safe_text_serialize( $value );
554 if ( is_array( $value ) ) {
555 foreach ( $value as $k => $v ) {
556 $_SESSION['usces_entry']['custom_order'][ $key ][ trim( $v ) ] = trim( $v );
557 }
558 } else {
559 $_SESSION['usces_entry']['custom_order'][ $key ] = trim( $value );
560 }
561 }
562 }
563 if ( isset( $_SESSION['usces_entry']['delivery']['delivery_flag'] ) && 0 === (int) $_SESSION['usces_entry']['delivery']['delivery_flag'] ) {
564 $this->set_custom_customer_delivery();
565 }
566 if ( isset( $_POST['custom_customer'] ) ) {
567 unset( $_SESSION['usces_entry']['custom_customer'] );
568 foreach ( $_POST['custom_customer'] as $key => $value ) {
569 $value = wel_safe_text_serialize( $value );
570 if ( is_array( $value ) ) {
571 foreach ( $value as $k => $v ) {
572 $_SESSION['usces_entry']['custom_customer'][ $key ][ trim( $v ) ] = trim( $v );
573 }
574 } else {
575 $_SESSION['usces_entry']['custom_customer'][ $key ] = trim( $value );
576 }
577 }
578 }
579 if ( isset( $_POST['custom_delivery'] ) ) {
580 unset( $_SESSION['usces_entry']['custom_delivery'] );
581 foreach ( $_POST['custom_delivery'] as $key => $value ) {
582 $value = wel_safe_text_serialize( $value );
583 if ( is_array( $value ) ) {
584 foreach ( $value as $k => $v ) {
585 $_SESSION['usces_entry']['custom_delivery'][ $key ][ trim( $v ) ] = trim( $v );
586 }
587 } else {
588 $_SESSION['usces_entry']['custom_delivery'][ $key ] = trim( $value );
589 }
590 }
591 }
592 if ( isset( $_POST['delivery']['delivery_flag'] ) && 0 === (int) $_POST['delivery']['delivery_flag'] ) {
593 $this->set_custom_customer_delivery();
594 }
595 }
596
597 /**
598 * Get entry data
599 *
600 * @return array
601 */
602 public function get_entry() {
603 $res['customer'] = array(
604 'mailaddress1' => '',
605 'mailaddress2' => '',
606 'password1' => '',
607 'password2' => '',
608 'name1' => '',
609 'name2' => '',
610 'name3' => '',
611 'name4' => '',
612 'zipcode' => '',
613 'address1' => '',
614 'address2' => '',
615 'address3' => '',
616 'tel' => '',
617 'fax' => '',
618 'country' => '',
619 'pref' => '',
620 );
621 if ( isset( $_SESSION['usces_entry']['customer'] ) ) {
622 foreach ( (array) $_SESSION['usces_entry']['customer'] as $key => $val ) {
623 $res['customer'][ $key ] = $val;
624 }
625 }
626
627 $res['delivery'] = array(
628 'name1' => '',
629 'name2' => '',
630 'name3' => '',
631 'name4' => '',
632 'zipcode' => '',
633 'address1' => '',
634 'address2' => '',
635 'address3' => '',
636 'tel' => '',
637 'fax' => '',
638 'country' => '',
639 'pref' => '',
640 'delivery_flag' => '0',
641 );
642 if ( isset( $_SESSION['usces_entry']['delivery'] ) ) {
643 foreach ( (array) $_SESSION['usces_entry']['delivery'] as $key => $val ) {
644 $res['delivery'][ $key ] = $val;
645 }
646 }
647
648 $res['order'] = array(
649 'usedpoint' => '',
650 'total_items_price' => '',
651 'discount' => '',
652 'shipping_charge' => '',
653 'cod_fee' => '',
654 'shipping_charge' => '',
655 'payment_name' => '',
656 'delivery_method' => '',
657 'delivery_date' => '',
658 'delivery_time' => '',
659 'total_full_price' => '',
660 'note' => '',
661 'tax' => '',
662 'payment_name' => '',
663 'delidue_date' => '',
664 );
665 if ( isset( $_SESSION['usces_entry']['order'] ) ) {
666 foreach ( (array) $_SESSION['usces_entry']['order'] as $key => $val ) {
667 $res['order'][ $key ] = $val;
668 }
669 }
670 if ( isset( $_SESSION['usces_entry']['reserve'] ) ) {
671 $res['reserve'] = $_SESSION['usces_entry']['reserve'];
672 } else {
673 $res['reserve'] = null;
674 }
675 if ( isset( $_SESSION['usces_entry']['condition'] ) ) {
676 $res['condition'] = $_SESSION['usces_entry']['condition'];
677 } else {
678 $res['condition'] = null;
679 }
680 if ( isset( $_SESSION['usces_entry']['custom_order'] ) ) {
681 $res['custom_order'] = $_SESSION['usces_entry']['custom_order'];
682 } else {
683 $res['custom_order'] = null;
684 }
685 if ( isset( $_SESSION['usces_entry']['custom_customer'] ) ) {
686 $res['custom_customer'] = $_SESSION['usces_entry']['custom_customer'];
687 } else {
688 $res['custom_customer'] = null;
689 }
690 if ( isset( $_SESSION['usces_entry']['custom_delivery'] ) ) {
691 $res['custom_delivery'] = $_SESSION['usces_entry']['custom_delivery'];
692 } else {
693 $res['custom_delivery'] = null;
694 }
695 return $res;
696 }
697
698 /**
699 * Get sales price
700 *
701 * @param int $post_id Post ID.
702 * @param string $sku SKU code.
703 * @param int $quant Quantity.
704 * @param float $price Sales price.
705 * @param float $unit_price Unit price.
706 * @return float
707 */
708 public function get_realprice( $post_id, $sku, $quant, $price = null, &$unit_price = null ) {
709 global $usces;
710
711 $sku = urldecode( $sku );
712 $skus = $usces->get_skus( $post_id, 'code' );
713
714 if ( null === $price ) {
715 $p = isset( $skus[ $sku ]['price'] ) ? $skus[ $sku ]['price'] : '';
716 } else {
717 $p = $price;
718 }
719 $p = apply_filters( 'usces_filter_realprice', $p, $this->serial );
720 $unit_price = $p;
721 if ( isset( $skus[ $sku ]['price'] ) && ! $skus[ $sku ]['gp'] ) {
722 return $p;
723 }
724
725 $realprice = usces_get_gp_price( $post_id, $p, $quant );
726
727 return $realprice;
728 }
729
730 /**
731 * Set Pre-Order ID
732 *
733 * @param string $id Pre-Order ID.
734 * @return void
735 */
736 public function set_pre_order_id( $id ) {
737 $_SESSION['usces_entry']['reserve']['pre_order_id'] = $id;
738 }
739
740 /**
741 * Transcribe membership information to shipping address information
742 *
743 * @return void
744 */
745 public function set_custom_customer_delivery() {
746 if ( isset( $_SESSION['usces_entry']['custom_customer'] ) ) {
747 $delivery = array();
748 $csde_meta = usces_has_custom_field_meta( 'delivery' );
749 if ( ! empty( $csde_meta ) && is_array( $csde_meta ) ) {
750 foreach ( $csde_meta as $key => $entry ) {
751 $delivery[ $key ] = $key;
752 }
753 }
754 foreach ( $_SESSION['usces_entry']['custom_customer'] as $mbkey => $mbvalue ) {
755 if ( array_key_exists( $mbkey, $delivery ) ) {
756 if ( is_array( $mbvalue ) ) {
757 foreach ( $mbvalue as $k => $v ) {
758 $_SESSION['usces_entry']['custom_delivery'][ $mbkey ][ $v ] = $v;
759 }
760 } else {
761 $_SESSION['usces_entry']['custom_delivery'][ $mbkey ] = $mbvalue;
762 }
763 }
764 }
765 }
766 if ( ! empty( $_SESSION['usces_entry']['custom_delivery'] ) ) {
767 foreach ( $_SESSION['usces_entry']['custom_delivery'] as $key => $value ) {
768 if ( ! isset( $_SESSION['usces_entry']['custom_customer'] ) || ! array_key_exists( $key, $_SESSION['usces_entry']['custom_customer'] ) ) {
769 // Set item empty.
770 if ( is_array( $value ) ) {
771 foreach ( $value as $k => $v ) {
772 $_SESSION['usces_entry']['custom_delivery'][ $key ][ $v ] = '';
773 }
774 } else {
775 $_SESSION['usces_entry']['custom_delivery'][ $key ] = '';
776 }
777 }
778 }
779 }
780 }
781 }
782