Skip to content

Commit

Permalink
* Tweaked: Checking if logger is enabled within logger function
Browse files Browse the repository at this point in the history
* Tweaked: Added Actionhook 'shipcloud_shipment_tracking_change' for all tracking status changes
* Fixed: Error 500 on calling Webhook URL
  • Loading branch information
mahype committed Sep 14, 2016
1 parent 4fb6a03 commit eb5b212
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 49 deletions.
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
*** WooCommerce Shipcloud Changelog ***

2016.*.* - version 1.1.1
* Tweaked: Checking if logger is enabled within logger function
* Tweaked: Added Actionhook 'shipcloud_shipment_tracking_change' for all tracking status changes
* Fixed: Error 500 on calling Webhook URL

2016.09.08 - version 1.1.0
* Enhanced: Better logging information
* Enhanced: Replaced new lines on Logging and only using Shipping method logger
Expand Down
65 changes: 17 additions & 48 deletions components/woo/shipping-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ class WC_Shipcloud_Shipping extends WC_Shipping_Method
*/
private static $logger;

/**
* Debug mode
*
* @var bool $debug
* @since 1.0.0
*/
private $debug = true;

/**
* Callback URL
*
Expand Down Expand Up @@ -124,11 +116,6 @@ public function __construct( $instance_id = 0 )

$this->enabled = $this->get_option( 'enabled' );

if ( 'no' == $this->get_option( 'debug' ) )
{
$this->debug = false;
}

$this->start();
}

Expand All @@ -150,7 +137,7 @@ private function init_shipcloud_api( $api_key = null ){
$this->shipcloud_api = new Woocommerce_Shipcloud_API( $api_key );

if( is_wp_error( $this->shipcloud_api ) ) {
$this->log( $price->get_error_message() );
self::log( $this->shipcloud_api->get_error_message() );
return $this->shipcloud_api;
}

Expand Down Expand Up @@ -680,30 +667,21 @@ public static function shipment_listener()

if ( ( json_last_error() !== JSON_ERROR_NONE ) )
{
if ( self::$debug )
{
self::log( sprintf( 'Shipment Listener: JSON error (%s).', json_last_error_msg() ) );
}
self::log( sprintf( 'Shipment Listener: JSON error (%s).', json_last_error_msg() ) );
exit;
}

if ( ! property_exists( $shipment, 'data' ) || ! property_exists( $shipment->data, 'id' ) )
{
if ( self::$debug )
{
self::log( 'Shipment Listener: Wrong data format.' );
}
self::log( 'Shipment Listener: Wrong data format.' );
exit;
}

$shipment_id = $shipment->data->id;

if ( empty( $shipment_id ) )
{
if ( self::$debug )
{
self::log( 'Shipment Listener: Shipment ID not given.' );
}
self::log( 'Shipment Listener: Shipment ID not given.' );
exit;
}

Expand All @@ -713,18 +691,12 @@ public static function shipment_listener()

if ( null == $order_id )
{
if ( self::$debug )
{
self::log( sprintf( 'Shipment Listener: Order ID for Shipment ID #%s not found', $shipment_id ) );
}
self::log( sprintf( 'Shipment Listener: Order ID for Shipment ID #%s not found', $shipment_id ) );
exit;
}
else
{
if ( self::$debug )
{
self::log( sprintf( 'Shipment Listener: Changed status to "%s" for Shipment ID %s (Order ID %s) ', $shipment->type, $shipment_id, $order_id ) );
}
self::log( sprintf( 'Shipment Listener: Changed status to "%s" for Shipment ID %s (Order ID %s) ', $shipment->type, $shipment_id, $order_id ) );
}

$order = wc_get_order( $order_id );
Expand All @@ -735,6 +707,8 @@ public static function shipment_listener()
/**
* Hooks in for further functions after status changes
*/
do_action( 'shipcloud_shipment_tracking_change', $order_id, $shipment_id, $shipment->type );

switch ( $shipment->type )
{
case 'shipment.tracking.picked_up':
Expand Down Expand Up @@ -1480,7 +1454,7 @@ private function calculate_virtual_parcel( $parcels )
*
* @param string $shipping_class
*
* @return float $costs
* @return float|boolean $costs
* @since 1.0.0
*/
private function get_shipping_class_costs( $shipping_class )
Expand All @@ -1489,22 +1463,15 @@ private function get_shipping_class_costs( $shipping_class )

if ( ! is_object( $term ) )
{
if ( $this->debug )
{
self::log( sprintf( __( 'No term found for shipping class #%s', 'woocommerce-shipcloud' ), $shipping_class ) );
}

self::log( sprintf( __( 'No term found for shipping class #%s', 'woocommerce-shipcloud' ), $shipping_class ) );
return false;
}

$parcel_id = get_option( 'wcsc_shipping_class_' . $term->term_id . '_parcel_id', 0 );

if ( 0 == $parcel_id )
{
if ( $this->debug )
{
self::log( sprintf( __( 'No parcel found for product id #%s', 'woocommerce-shipcloud' ), $product_id ) );
}
self::log( sprintf( __( 'No parcel found for product id #%s', 'woocommerce-shipcloud' ), $product_id ) );
}

$retail_price = $this->get_parcel_retail_price( $parcel_id );
Expand Down Expand Up @@ -1533,10 +1500,7 @@ private function get_parcel_retail_price( $parcel_id = 0 )
if ( '' == $retail_price )
{
$retail_price = $this->get_option( 'standard_price' );
if ( $this->debug )
{
self::log( sprintf( __( 'No price found for parcel. Using fallback price %s', 'woocommerce-shipcloud' ), $retail_price ) );
}
self::log( sprintf( __( 'No price found for parcel. Using fallback price %s', 'woocommerce-shipcloud' ), $retail_price ) );
}

return $retail_price;
Expand Down Expand Up @@ -1610,6 +1574,7 @@ public function get_allowed_carriers( $only_customer_services = false )
* @param null $empty_value
*
* @return mixed|string
* @since 1.0.0
*/
public function get_option( $key, $empty_value = null ) {
$option = parent::get_option( $key, $empty_value );
Expand All @@ -1631,6 +1596,10 @@ public function get_option( $key, $empty_value = null ) {
*/
public static function log( $message )
{
if( 'no' === WC_Settings_API::get_option( 'debug', 'no' ) ) {
return;
}

if ( ! is_object( self::$logger ) )
{
self::$logger = new WC_Logger();
Expand Down
2 changes: 1 addition & 1 deletion woocommerce-shipcloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WooCommerce shipcloud.io
* Plugin URI: http://www.woothemes.com/products/woocommerce-shipcloud/
* Description: Integrates shipcloud.io shipment services to your WooCommerce shop.
* Version: 1.1.0
* Version: 1.1.1-beta.1
* Author: WooThemes
* Author URI: http://woothemes.com/
* Developer: awesome.ug
Expand Down

0 comments on commit eb5b212

Please sign in to comment.