diff --git a/changelog.txt b/changelog.txt index b3758a6e..1cd89a81 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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 diff --git a/components/woo/shipping-method.php b/components/woo/shipping-method.php index dfdf4b3a..3d8e0b50 100644 --- a/components/woo/shipping-method.php +++ b/components/woo/shipping-method.php @@ -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 * @@ -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(); } @@ -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; } @@ -680,19 +667,13 @@ 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; } @@ -700,10 +681,7 @@ public static function shipment_listener() if ( empty( $shipment_id ) ) { - if ( self::$debug ) - { - self::log( 'Shipment Listener: Shipment ID not given.' ); - } + self::log( 'Shipment Listener: Shipment ID not given.' ); exit; } @@ -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 ); @@ -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': @@ -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 ) @@ -1489,11 +1463,7 @@ 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; } @@ -1501,10 +1471,7 @@ private function get_shipping_class_costs( $shipping_class ) 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 ); @@ -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; @@ -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 ); @@ -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(); diff --git a/woocommerce-shipcloud.php b/woocommerce-shipcloud.php index 67651af7..b0d551ff 100644 --- a/woocommerce-shipcloud.php +++ b/woocommerce-shipcloud.php @@ -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