Skip to content

Commit

Permalink
logger changed
Browse files Browse the repository at this point in the history
  • Loading branch information
timoj committed Jan 21, 2019
1 parent 9567b19 commit 6f88582
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions includes/logger.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

function log( $severity, $message ) {
function wuunder_log($severity, $message ) {
$logger = wc_get_logger();
$context = array( 'source' => 'wuunder_connector' );
if ( WP_DEBUG ) {
$logger -> log( $severity, $message, $context );
$logger->log( $severity, $message, $context );
}

}
26 changes: 13 additions & 13 deletions includes/wcwuunder-create.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function sample_admin_notice__error() {
* @return $bookingConfig
*/
private function setBookingConfig( $orderId ) {
log( 'info', 'Filling the booking config' );
wuunder_log( 'info', 'Filling the booking config' );

$orderItems = $this->get_order_items( $orderId );

Expand Down Expand Up @@ -148,31 +148,31 @@ private function setBookingConfig( $orderId ) {
* Returns the user to the original order page with the redirect.
*/
public function generateBookingUrl() {
if ( 'bookorder' === isset($_REQUEST['order'] ) && $_REQUEST['action'] ) {
log( 'info', 'Generating the booking url' );
if (isset($_REQUEST['order']) && $_REQUEST['action'] === "bookorder") {
wuunder_log( 'info', 'Generating the booking url' );
$order_id = $_REQUEST['order'];

$status = get_option( 'wc_wuunder_api_status' );
$apiKey = ( 'productie' == $status ? get_option( 'wc_wuunder_api' ) : get_option( 'wc_wuunder_test_api' ) );


$connector = 'productie' !== new Wuunder\Connector( $apiKey, $status );
$connector = new Wuunder\Connector( $apiKey, 'productie' !== $status );
$booking = $connector->createBooking();
$bookingConfig = $this->setBookingConfig( $order_id );

if ( $bookingConfig->validate() ) {
$booking->setConfig( $bookingConfig );
log( 'info', 'Going to fire for bookingurl' );
wuunder_log( 'info', 'Going to fire for bookingurl' );
if ( $booking->fire() ) {
$url = $booking->getBookingResponse()->getBookingUrl();
} else {
log( 'error', $booking->getBookingResponse()->getError() );
wuunder_log( 'error', $booking->getBookingResponse()->getError() );
}
} else {
log( 'error', 'Bookingconfig not complete' );
wuunder_log( 'error', 'Bookingconfig not complete' );
}

log( 'info', 'Handling response' );
wuunder_log( 'info', 'Handling response' );

if (isset( $url ) ) {
update_post_meta( $order_id, '_wuunder_label_booking_url', $url );
Expand Down Expand Up @@ -244,7 +244,7 @@ public function get_company_address() {
if ( $pickupAddress->validate() ) {
return $pickupAddress;
} else {
log( 'error', 'Invalid pickup address. There are mistakes or missing fields.' );
wuunder_log( 'error', 'Invalid pickup address. There are mistakes or missing fields.' );
return $pickupAddress;
}
}
Expand Down Expand Up @@ -344,7 +344,7 @@ public function get_customer_address( $orderid ) {
if ( $deliveryAddress->validate() ) {
return $deliveryAddress;
} else {
log( 'error', 'Invalid delivery address. There are mistakes or missing fields.' );
wuunder_log( 'error', 'Invalid delivery address. There are mistakes or missing fields.' );
return $deliveryAddress;
}
}
Expand All @@ -358,17 +358,17 @@ public function get_customer_address( $orderid ) {
public function get_base64_image( $imagepath ) {
try {
$fileSize = ( 'http' === substr( $imagepath, 0, 4 ) ) ? $this->remote_filesize( $imagepath ) : filesize( $imagepath );
log( 'info', 'Handling a image of size: ' . $fileSize );
wuunder_log( 'info', 'Handling a image of size: ' . $fileSize );
if ( $fileSize > 0 && $fileSize <= 2097152 ) { //smaller or equal to 2MB
log( 'info', 'Base64 encoding image' );
wuunder_log( 'info', 'Base64 encoding image' );
$imagedata = file_get_contents( $imagepath );
$image = base64_encode( $imagedata );
} else {
$image = '';
}
return $image;
} catch ( Exception $e ) {
log( 'error', $e );
wuunder_log( 'error', $e );
return '';
}
}
Expand Down
7 changes: 4 additions & 3 deletions woocommerce-wuunder.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function __construct() {
include_once( 'includes/checkout.php' );

add_action('wp_ajax_wuunder_parcelshoplocator_get_parcelshop_address', 'getParcelshopAddress');
add_action('wp_ajax_nopriv_wuunder_parcelshoplocator_get_parcelshop_address', 'getParcelshopAddress');
add_action('wp_ajax_wuunder_parcelshoplocator_get_address', 'getAddress');
add_action('wp_ajax_nopriv_wuunder_parcelshoplocator_get_address', 'getAddress');

Expand Down Expand Up @@ -101,9 +102,9 @@ public function add_admin_styles_scripts() {
}

public function webhook() {
log( 'info', 'Test webhook' );
log( 'info', $_REQUEST['order'] );
log( 'info', $_REQUEST['token'] );
wuunder_log( 'info', 'Test webhook' );
wuunder_log( 'info', $_REQUEST['order'] );
wuunder_log( 'info', $_REQUEST['token'] );

if ( !isset($_REQUEST['order'] ) || !isset( $_REQUEST['token'] ) ) {
wp_redirect( '', 500 );
Expand Down

0 comments on commit 6f88582

Please sign in to comment.