Completed
Pull Request — master (#2165)
by Justin
06:42
created

purchaselogs.functions.php ➔ wpsc_display_purchlog_display_howtheyfoundus()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
global $wpsc_purchlog_statuses;
4
if (!isset($wpsc_purchlog_statuses) || !count($wpsc_purchlog_statuses)) {
5
   wpsc_core_load_purchase_log_statuses();
6
}
7
8
function wpsc_instantiate_purchaselogitem() {
9
   global $purchlogitem;
10
   if ( isset( $_REQUEST['purchaselog_id'] ) )
11
	  $purchlogitem = new wpsc_purchaselogs_items( (int)$_REQUEST['purchaselog_id'] );
12
13
}
14
add_action( 'wpsc_core_included', 'wpsc_instantiate_purchaselogitem' );
15
16
function wpsc_display_purchlog_howtheyfoundus() {
17
   global $purchlogitem;
18
   return esc_attr( $purchlogitem->extrainfo->find_us );
19
}
20
21
function wpsc_display_purchlog_display_howtheyfoundus() {
22
   global $purchlogitem;
23
   if ( !empty( $purchlogitem->extrainfo->find_us ) )
0 ignored issues
show
Coding Style introduced by
The if-else statement can be simplified to return !empty($purchlogitem->extrainfo->find_us);.
Loading history...
24
	  return true;
25
   else
26
	  return false;
27
}
28
29
function wpsc_check_uniquenames() {
30
   global $wpdb;
31
   $sql = 'SELECT COUNT(`id`) FROM `' . WPSC_TABLE_CHECKOUT_FORMS . '` WHERE unique_name != "" ';
32
   $check_unique_names = $wpdb->get_var( $sql );
33
   if ( $check_unique_names > 0 ) {
0 ignored issues
show
Coding Style introduced by
The if-else statement can be simplified to return !($check_unique_names > 0);.
Loading history...
34
	  return false;
35
   } else {
36
	  return true;
37
   }
38
}
39
40
/** Does the purchaselog have tracking information
41
 * @return boolean
42
 */
43
function wpsc_purchlogs_has_tracking() {
44
	global $purchlogitem;
45
	if ( ! empty( $purchlogitem->extrainfo->track_id ) ) {
0 ignored issues
show
Coding Style introduced by
The if-else statement can be simplified to return !empty($purchlogi...->extrainfo->track_id);.
Loading history...
46
		return true;
47
	} else {
48
		return false;
49
	}
50
}
51
52
/**
53
 * * @return string  current tracking id or or empty string if there isn't a tracking id
54
 */
55
function wpsc_purchlogitem_trackid() {
56
	global $purchlogitem;
57
	return esc_attr( empty( $purchlogitem->extrainfo->track_id ) ? '' : $purchlogitem->extrainfo->track_id );
58
}
59
60
/** Purchase shipping status
61
 * @return string shipping status or empty string
62
 */
63
function wpsc_purchlogitem_trackstatus() {
64
	global $wpsc_shipping_modules, $purchlogitem;
65
66
	$callable = array( $purchlogitem->extrainfo->shipping_method, 'getStatus' );
67
	$shipping_status_is_callable = is_callable( $callable );
68
69
	if ( $shipping_status_is_callable && ! empty( $purchlogitem->extrainfo->track_id ) ) {
70
		$status = $wpsc_shipping_modules [$purchlogitem->extrainfo->shipping_method]->getStatus( $purchlogitem->extrainfo->track_id );
71
	} else {
72
		$status = '';
73
	}
74
75
	return $status;
76
}
77
78
/** Tracking history for purchase
79
 * @return string tracking history or empty string
80
 */
81
function wpsc_purchlogitem_trackhistory() {
82
	global $purchlogitem;
83
84
	if ( ( 'nzpost' == $purchlogitem->extrainfo->shipping_method ) && ! empty( $purchlogitem->extrainfo->track_id ) ) {
85
86
		$output  = '<ul>';
87
		$outputs = array();
88
89
		foreach ( ( array ) $_SESSION ['wpsc_nzpost_parsed'] [0] ['children'] [0] ['children'] [1] ['children'] as $history ) {
0 ignored issues
show
introduced by
Cast statements must not contain whitespace; expected "(array)" but found "( array )"
Loading history...
introduced by
Usage of $_SESSION variable is prohibited.
Loading history...
90
			$outputs[] = '<li>' . $history ['children'] [0] ['tagData'] . ' : ' . $history ['children'] [1] ['tagData'] . ' </li>';
91
		}
92
93
		$outputs = array_reverse( $outputs );
94
		foreach ( $outputs as $o ) {
95
			$output .= $o;
96
		}
97
98
		$output .= '</ul>';
99
		return $output;
100
	} else {
101
		// TODO: If there isn't one already, we should add a tracking callback to the shipping API
102
		return '';
103
	}
104
}
105
106
107
/**
108
 * Weight of current or specified purchase
109
 *
110
 * @since 3.8.14
111
 *
112
 *
113
 * @param string $id
114
 * @return float $weight in '$out_unit' of shipment
115
 */
116
function wpsc_purchlogs_get_weight( $id = '', $out_unit = 'pound' ) {
117
	global $purchlogitem;
118
	$weight = 0.0;
119
	$items_count = 0;
120
121
	if ( empty( $id ) || ( ! empty( $purchlogitem ) &&  ( $id == $purchlogitem->purchlogid ) ) ) {
122
		$thepurchlogitem = $purchlogitem;
123
	} else {
124
		$thepurchlogitem = new wpsc_purchaselogs_items( $id );
125
	}
126
127
	/**
128
	 * Filter wpsc_purchlogs_before_get_weight
129
	 *
130
	 * Allow the weight to be overridden, can be used to persistantly save weight and recall it rather than recalculate
131
	 *
132
	 * @since 3.8.14
133
	 *
134
	 * @param  float  $weight, purchase calculation will not continue if value is returned
135
	 * @param  string weight unit to use for return value
136
	 * @param  object wpsc_purchaselogs_items purchase log item being used
137
	 * @param  int    purchase log item id
138
	 * @return float  $weight
139
	 */
140
	$weight_override = apply_filters( 'wpsc_purchlogs_before_get_weight', false, $out_unit, $thepurchlogitem, $thepurchlogitem->purchlogid );
141
	if ( $weight_override !== false ) {
142
		return $weight_override;
143
	}
144
145
	// if there isn't a purchase log item we are done
146
	if ( empty( $thepurchlogitem ) ) {
147
		return false;
148
	}
149
150
	foreach ( ( array ) $thepurchlogitem->allcartcontent as $cartitem ) {
0 ignored issues
show
introduced by
Cast statements must not contain whitespace; expected "(array)" but found "( array )"
Loading history...
151
		$product_meta = get_product_meta( $cartitem->prodid, 'product_metadata', true );
152
		if ( ! empty( $product_meta ['weight'] ) ) {
153
154
			$converted_weight = wpsc_convert_weight( $product_meta ['weight'], $product_meta['weight_unit'], $out_unit, true );
155
156
			$weight += $converted_weight * $cartitem->quantity;
157
			$items_count += $cartitem->quantity;
158
		}
159
	}
160
161
	/**
162
	 * Filter wpsc_purchlogs_get_weight
163
	 *
164
	 * Allow the weight to be overridden
165
	 *
166
	 * @since 3.8.14
167
	 *
168
	 * @param  float  $weight                 calculated cart weight
169
	 * @param  object wpsc_purchaselogs_items purchase log item being used
170
	 * @param  int    purchase log item id
171
	 * @param  int    $items_count            how many items are in the cart, useful for
172
	 *                                        cases where packaging weight changes as more items are
173
	 *                                        added
174
	 */
175
	$weight = apply_filters( 'wpsc_purchlogs_get_weight', $weight, $thepurchlogitem, $thepurchlogitem->purchlogid, $items_count );
176
177
	return $weight;
178
}
179
180
/**
181
 * Weight of current or specified purchase formatted as text with units
182
 *
183
 * @since 3.8.14
184
 *
185
 * @param string $id
186
 * @return string $weight in KG and lbs and ounces
187
 */
188
function wpsc_purchlogs_get_weight_text( $id = '' ) {
189
	global $purchlogitem;
190
191
	if ( empty( $id ) ) {
192
		$id = $purchlogitem->purchlogid;
193
	}
194
195
	$weight_in_pounds = wpsc_purchlogs_get_weight( $id, 'pound' );
196
197
	if ( $weight_in_pounds > 0 ) {
198
199
		$pound = floor( $weight_in_pounds );
200
		$ounce = round( ( $weight_in_pounds - $pound ) * 16 );
201
202
		$weight_in_kg = wpsc_purchlogs_get_weight( $id, 'kg' );
203
204
		$weight_string = number_format( $weight_in_kg , 2 ) .' ' .  __( 'KG' , 'wp-e-commerce' ) . ' / ' .  $pound . ' ' .  __( 'LB', 'wp-e-commerce' ) . ' ' . $ounce . ' ' . __( 'OZ', 'wp-e-commerce' );
205
206
	} else {
207
		$weight_string = '';
208
	}
209
210
	/**
211
	 * Filter wpsc_purchlogs_get_weight_text
212
	 *
213
	 * Format weight as text suitable to inform user of purchase shipping weight
214
	 *
215
	 * @since 3.8.14
216
	 *
217
	 * @param  string weight of purchase as text string with both KG and pounds/ounces
218
	 * @param  object wpsc_purchaselogs_items purchase log item being used
219
	 */
220
	return apply_filters( 'wpsc_purchlogs_get_weight_text', $weight_string, $id  );
221
222
}
223
224
function wpsc_purchlogs_has_customfields( $id = '' ) {
225
   global $purchlogitem;
226
   if ( $id == '' ) {
227
	  foreach ( (array)$purchlogitem->allcartcontent as $cartitem ) {
228
		 if ( $cartitem->files != 'N;' || $cartitem->custom_message != '' ) {
229
			return true;
230
		 }
231
	  }
232
	  return false;
233
   } else {
234
	  $purchlogitem = new wpsc_purchaselogs_items( $id );
235
	  foreach ( (array)$purchlogitem->allcartcontent as $cartitem ) {
236
		 if ( $cartitem->files != 'N;' || $cartitem->custom_message != '' ) {
237
			return true;
238
		 }
239
	  }
240
	  return false;
241
   }
242
   return false;
0 ignored issues
show
Unused Code introduced by
return false; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
243
}
244
245
function wpsc_trackingid_value() {
246
   global $purchlogs;
247
   return $purchlogs->purchitem->track_id;
248
}
249
250
function wpsc_purchlogs_custommessages() {
251
   global $purchlogitem;
252
   $messages = array();
253
   foreach ( $purchlogitem->allcartcontent as $cartitem ) {
254
	  if ( $cartitem->custom_message != '' ) {
255
		 $messages[] = array(
256
		 	'title'   => apply_filters( 'the_title', $cartitem->name ),
257
		 	'message' => $cartitem->custom_message,
258
		 );
259
	  }
260
   }
261
   return $messages;
262
}
263
264
function wpsc_purchlogs_customfiles() {
265
   global $purchlogitem;
266
   $files = array( );
0 ignored issues
show
introduced by
Empty array declaration must have no space between the parentheses
Loading history...
267
   foreach ( $purchlogitem->allcartcontent as $cartitem ) {
268
	  if ( $cartitem->files != 'N;' ) {
269
		 $file = unserialize( $cartitem->files );
270
271
		 if ( $file["mime_type"] == "image/jpeg" || $file["mime_type"] == "image/png" || $file["mime_type"] == "image/gif" ) {
272
			$image = "<a href='" . esc_url ( WPSC_USER_UPLOADS_URL . $file['file_name'] ) . "' >";
0 ignored issues
show
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
273
			$image .= "<img width='150' src='".esc_url( WPSC_USER_UPLOADS_URL . $file['file_name'] ). "' alt='' />";
274
			$image .="</a>";
275
			$files[] = $cartitem->name . ' :<br />' . $image;
276
		 } else {
277
			$files[] = $cartitem->name . ' :<br />' . esc_url( $file['file_name'] );
278
		 }
279
	  }
280
   }
281
   return $files;
282
}
283
284
function wpsc_have_purch_items() {
285
   global $purchlogs;
286
   return $purchlogs->have_purch_items();
287
}
288
289
function wpsc_is_checked_status() {
290
   global $purchlogs;
291
292
   return $purchlogs->is_checked_status();
293
}
294
295
function wpsc_have_purchaselog_details() {
296
   global $purchlogitem;
297
   return $purchlogitem->have_purch_item();
298
}
299
300
function wpsc_purchaselog_details_name() {
301
   global $purchlogitem;
302
   return esc_html( apply_filters( 'the_title', $purchlogitem->purchitem->name, $purchlogitem->purchitem->prodid ) );
303
}
304
305
function wpsc_purchaselog_details_id() {
306
   global $purchlogitem;
307
   return $purchlogitem->purchitem->id;
308
}
309
310
function wpsc_the_purchaselog_item() {
311
   global $purchlogitem;
312
   return $purchlogitem->the_purch_item();
313
}
314
315
function wpsc_purchaselog_details_SKU() {
316
   global $purchlogitem;
317
   $meta_value = wpsc_get_cart_item_meta( $purchlogitem->purchitem->id, 'sku', true );
318
   if ( $meta_value != null ) {
319
	  return esc_attr( $meta_value );
320
   } else {
321
	  $meta_value = get_product_meta( $purchlogitem->purchitem->prodid, 'sku', true );
322
	  if ( $meta_value != null ) {
323
		 return esc_attr( $meta_value );
324
	  } else {
325
		 return __('N/A', 'wp-e-commerce');
326
	  }
327
   }
328
}
329
330
function wpsc_purchaselog_details_quantity() {
331
   global $purchlogitem;
332
   return (float) $purchlogitem->purchitem->quantity;
333
}
334
335
function wpsc_purchaselog_details_price() {
336
   global $purchlogitem;
337
   return (float) $purchlogitem->purchitem->price;
338
}
339
340
function wpsc_purchaselog_details_shipping() {
341
   global $purchlogitem;
342
   return (float) $purchlogitem->purchitem->pnp;
343
}
344
345
function wpsc_purchaselog_details_tax() {
346
   global $purchlogitem, $wpsc_cart;
347
348
   return (float) $purchlogitem->purchitem->tax_charged;
349
}
350
351
function wpsc_purchaselog_details_discount() {
352
   global $purchlogitem;
353
   return (float) $purchlogitem->extrainfo->discount_value;
354
}
355
356
function wpsc_purchaselog_details_date() {
357
   global $purchlogitem;
358
   return date_i18n( apply_filters( 'wpsc_single_purchase_log_date_format', get_option( 'date_format' ) ), $purchlogitem->extrainfo->date + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
359
}
360
361
function wpsc_purchaselog_details_date_time() {
362
   global $purchlogitem;
363
   return date_i18n( apply_filters( 'wpsc_single_purchase_log_date_time_format', get_option( 'date_format' ) . ' g:ia' ),   $purchlogitem->extrainfo->date + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
364
}
365
366
function wpsc_purchaselog_details_total() {
367
   global $purchlogitem;
368
   $total = 0;
369
   $total += ( $purchlogitem->purchitem->price * $purchlogitem->purchitem->quantity);
370
   $total += ( $purchlogitem->purchitem->pnp );
371
   $purchlogitem->totalAmount += $total;
372
   return $total;
373
}
374
375
function wpsc_purchaselog_details_purchnumber() {
376
   global $purchlogitem;
377
   return $purchlogitem->extrainfo->id;
378
}
379
380
/*
381
 * Has Discount Data?
382
 */
383
384
function wpsc_purchlog_has_discount_data() {
385
   global $purchlogitem;
386
   return!empty( $purchlogitem->extrainfo->discount_data );
387
}
388
389
/*
390
 * Returns Discount Code
391
 */
392
393
function wpsc_display_purchlog_discount_data( $numeric = false ) {
0 ignored issues
show
Unused Code introduced by
The parameter $numeric is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
394
   global $purchlogitem;
395
   return $purchlogitem->extrainfo->discount_data;
396
}
397
398
/*
399
 * Returns base shipping should make a function to calculate items shipping as well
400
 */
401
402
function wpsc_display_purchlog_discount( $numeric = false ) {
403
   global $purchlogitem;
404
   $discount = $purchlogitem->extrainfo->discount_value;
405
   if ( $numeric == true ) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
406
	  return $discount;
407
   } else {
408
	  return wpsc_currency_display( $discount,array( 'display_as_html' => false ) );
409
   }
410
}
411
412
/*
413
 * Returns base shipping should make a function to calculate items shipping as well
414
 */
415
416
function wpsc_display_purchlog_shipping( $numeric = false, $include_item = false ) {
417
   global $purchlogitem;
418
   $base_shipping = $purchlogitem->extrainfo->base_shipping;
419
   $per_item_shipping = 0;
420
421
   if ( $include_item ) {
422
      foreach ( (array)$purchlogitem->allcartcontent as $cart_item ) {
423
         if ( $cart_item->pnp > 0 ) {
424
            $per_item_shipping += ( $cart_item->pnp );
425
         }
426
      }
427
   }
428
429
   $total_shipping = $per_item_shipping + $base_shipping;
430
431
   if ( $numeric == true ) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
432
      return $total_shipping;
433
   } else {
434
      return wpsc_currency_display( $total_shipping,array( 'display_as_html' => false ) );
435
   }
436
}
437
438
/**
439
 * @description: returns taxes as set in purchase log
440
 * @param: numeric - if set will return unformatted price
441
 * */
442
function wpec_display_purchlog_taxes( $numeric = false ) {
443
	return wpsc_display_purchlog_taxes( $numeric );
444
}
445
446
/**
447
 * @description: determines whether or not to display the product tax or not
448
 * @return: boolean
449
**/
450
function wpec_display_product_tax()
451
{
452
   global $purchlogitem;
453
   return ($purchlogitem->extrainfo->wpec_taxes_total == 0.00) ? true : false;
454
}// wpec_display_product_tax
455
456
457
function wpsc_display_purchlog_taxes( $numeric = false ) {
458
	global $purchlogitem;
459
	return ($numeric) ? $purchlogitem->extrainfo->wpec_taxes_total : wpsc_currency_display( $purchlogitem->extrainfo->wpec_taxes_total,array( 'display_as_html' => false ) );
460
}
461
462
function wpsc_display_purchlog_totalprice() {
463
	global $purchlogitem;
464
	$total = $purchlogitem->totalAmount - wpsc_display_purchlog_discount( true ) + wpsc_display_purchlog_shipping( true ) + wpsc_display_purchlog_taxes( true );
465
	return wpsc_currency_display( $total, array( 'display_as_html' => false ) );
466
}
467
468
function wpsc_display_purchlog_buyers_name() {
469
   global $purchlogitem;
470
471
   $first_name = $last_name = '';
472
473
   if ( isset( $purchlogitem->userinfo['billingfirstname'] ) ) {
474
   		$first_name = $purchlogitem->userinfo['billingfirstname']['value'];
475
   }
476
477
   if ( isset( $purchlogitem->userinfo['billinglastname'] ) ) {
478
   		$last_name = ' ' . $purchlogitem->userinfo['billinglastname']['value'];
479
   }
480
481
   $name = trim( $first_name . $last_name );
482
483
   return esc_html( $name );
484
}
485
486
function wpsc_display_purchlog_buyers_city() {
487
   global $purchlogitem;
488
   return isset( $purchlogitem->userinfo['billingcity'] ) ? esc_html( $purchlogitem->userinfo['billingcity']['value'] ) : '';
489
}
490
491
function wpsc_display_purchlog_buyers_email() {
492
   global $purchlogitem;
493
   return esc_html( $purchlogitem->userinfo['billingemail']['value'] );
494
}
495
496
function wpsc_display_purchlog_buyers_address() {
497
   global $purchlogitem;
498
   return isset( $purchlogitem->userinfo['billingaddress'] ) ? nl2br( esc_html( $purchlogitem->userinfo['billingaddress']['value'] ) ) : '';
499
}
500
501
function wpsc_display_purchlog_buyers_state_and_postcode() {
502
   global $purchlogitem;
503
   if( is_numeric($purchlogitem->extrainfo->billing_region ) )
504
		 $state = wpsc_get_region($purchlogitem->extrainfo->billing_region);
505
   else
506
		 $state = $purchlogitem->userinfo['billingstate']['value'];
507
508
   $output = esc_html( $state );
509
510
   if ( isset( $purchlogitem->userinfo['billingpostcode']['value'] ) && ! empty( $purchlogitem->userinfo['billingpostcode']['value'] ) ) {
511
      if (! empty( $output ) ) {
512
         $output .= ', ';
513
      }
514
      $output .= esc_html( $purchlogitem->userinfo['billingpostcode']['value'] );
515
   }
516
517
   return $output;
518
}
519
520
function wpsc_display_purchlog_buyers_country() {
521
   global $purchlogitem;
522
   return esc_html( wpsc_get_country( $purchlogitem->userinfo['billingcountry']['value'] ) );
523
}
524
525
function wpsc_display_purchlog_buyers_phone() {
526
   global $purchlogitem;
527
   $value = '';
528
   if ( isset( $purchlogitem->userinfo['billingphone']['value'] ) )
529
      $value = $purchlogitem->userinfo['billingphone']['value'];
530
531
   return esc_html( $value );
532
}
533
534
function wpsc_display_purchlog_shipping_name() {
535
   global $purchlogitem;
536
   return esc_html( $purchlogitem->shippinginfo['shippingfirstname']['value'] ) . ' ' . esc_html( $purchlogitem->shippinginfo['shippinglastname']['value'] );
537
}
538
539
function wpsc_display_purchlog_shipping_address() {
540
	global $purchlogitem;
541
542
	if ( isset( $purchlogitem->shippinginfo['shippingaddress'] ) ) {
543
		return nl2br( esc_html( $purchlogitem->shippinginfo['shippingaddress']['value'] ) );
544
	} else {
545
		return '';
546
	}
547
548
}
549
550
function wpsc_display_purchlog_shipping_city() {
551
   global $purchlogitem;
552
553
	if ( isset( $purchlogitem->shippinginfo['shippingcity'] ) ) {
554
		return esc_html( $purchlogitem->shippinginfo['shippingcity']['value'] );
555
	} else {
556
		return '';
557
	}
558
}
559
560
function wpsc_display_purchlog_shipping_state_and_postcode() {
561
   global $purchlogitem;
562
   $state = '';
563
   if( is_numeric($purchlogitem->extrainfo->shipping_region) )
564
		$state = esc_html( wpsc_get_region($purchlogitem->extrainfo->shipping_region) );
565
   else
566
		$state = esc_html( $purchlogitem->shippinginfo['shippingstate']['value'] );
567
568
   if ( !empty( $purchlogitem->shippinginfo['shippingpostcode']['value'] ) ){
569
		if( empty( $state ) )
570
			$state = esc_html( $purchlogitem->shippinginfo['shippingpostcode']['value'] );
571
		else
572
			$state .= ' ' . esc_html( $purchlogitem->shippinginfo['shippingpostcode']['value'] );
573
   }
574
575
   return $state;
576
}
577
578
function wpsc_display_purchlog_shipping_country() {
579
   global $purchlogitem;
580
581
	if ( isset( $purchlogitem->shippinginfo['shippingcountry'] ) ) {
582
		return esc_html( wpsc_get_country( $purchlogitem->shippinginfo['shippingcountry']['value'] ) );
583
	} else {
584
		return '';
585
	}
586
}
587
588
function wpsc_display_purchlog_shipping_method() {
589
   global $purchlogitem, $wpsc_shipping_modules;
590
591
   if ( ! empty ( $wpsc_shipping_modules[$purchlogitem->extrainfo->shipping_method] ) ) {
0 ignored issues
show
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
592
	  $shipping_class = &$wpsc_shipping_modules[$purchlogitem->extrainfo->shipping_method];
593
	  return esc_html( $shipping_class->getName() );
594
   } else {
595
	  return esc_html( $purchlogitem->extrainfo->shipping_method );
596
   }
597
}
598
599
function wpsc_display_purchlog_shipping_option() {
600
   global $purchlogitem;
601
   return esc_html( $purchlogitem->extrainfo->shipping_option );
602
}
603
604
function wpsc_display_purchlog_paymentmethod() {
605
   global $purchlogitem, $nzshpcrt_gateways;
606
   $gateway_name = '';
607
   if('wpsc_merchant_testmode' == $purchlogitem->extrainfo->gateway)
608
      return __( 'Manual Payment', 'wp-e-commerce' );
609
610
   foreach ( (array)$nzshpcrt_gateways as $gateway ) {
611
	  if ( $gateway['internalname'] == $purchlogitem->extrainfo->gateway )
612
		 $gateway_name = $gateway['name'];
613
   }
614
   if( !empty($gateway_name) )
615
	  return esc_html( $gateway_name );
616
   else
617
	  return esc_html( $purchlogitem->extrainfo->gateway );
618
619
}
620
621
function wpsc_purchaselog_order_summary_headers() {
622
	global $purchlogitem;
623
	do_action( 'wpsc_purchaselog_order_summary_headers', $purchlogitem );
624
}
625
626
function wpsc_purchaselog_order_summary() {
627
	global $purchlogitem;
628
	do_action( 'wpsc_purchaselog_order_summary', $purchlogitem );
629
}
630
631
function wpsc_has_purchlog_shipping() {
632
   global $purchlogitem;
633
   if ( isset( $purchlogitem->shippinginfo['shippingfirstname'] ) && $purchlogitem->shippinginfo['shippingfirstname']['value'] != '' ) {
0 ignored issues
show
Coding Style introduced by
The if-else statement can be simplified to return isset($purchlogit...tname']['value'] != '';.
Loading history...
634
	  return true;
635
   } else {
636
	  return false;
637
   }
638
}
639
640
function wpsc_purchlogs_have_downloads_locked() {
641
   global $purchlogitem;
642
   $ip = $purchlogitem->have_downloads_locked();
643
   if ( $ip != '' ) {
644
	  return sprintf( __( 'Release downloads locked to this IP address %s', 'wp-e-commerce' ), $ip );
645
   } else {
646
	  return false;
647
   }
648
}
649
650
/**
651
 * Display Purchase Log Notes
652
 *
653
 * @return  string  Notes.
654
 */
655
function wpsc_display_purchlog_notes() {
656
	global $purchlogitem;
657
	$purchase_log = new WPSC_Purchase_Log( $purchlogitem->purchlogid );
658
	return $purchase_log->get( 'notes' );
659
}
660
661
//edit purchase log status function
662
function wpsc_purchlog_edit_status( $purchlog_id='', $purchlog_status='' ) {
0 ignored issues
show
introduced by
Expected 1 space between default value and equals sign for argument "$purchlog_id";
Loading history...
introduced by
Expected 1 space between default value and equals sign for argument "$purchlog_status";
Loading history...
introduced by
Expected 1 space between argument "$purchlog_id" and equals sign; 0 found
Loading history...
introduced by
Expected 1 space between argument "$purchlog_status" and equals sign; 0 found
Loading history...
663
   global $wpdb;
664
   if ( empty($purchlog_id) && empty($purchlog_status) ) {
665
      $purchlog_id = absint( $_POST['id'] );
666
      $purchlog_status = absint( $_POST['new_status'] );
667
   }
668
669
   $purchase_log = new WPSC_Purchase_Log( $purchlog_id );
670
671
   //in the future when everyone is using the 2.0 merchant api, we should use the merchant class to update the staus,
672
   // then you can get rid of this hook and have each person overwrite the method that updates the status.
673
   do_action('wpsc_edit_order_status', array('purchlog_id'=>$purchlog_id, 'purchlog_data'=>$purchase_log->get_data(), 'new_status'=>$purchlog_status));
674
675
   $result = wpsc_update_purchase_log_status( $purchlog_id, $purchlog_status );
676
   wpsc_clear_stock_claims();
677
678
   return $result;
679
}
680