diff --git a/assets/js/parcelshop.js b/assets/js/parcelshop.js index 04308fb..ffe109e 100644 --- a/assets/js/parcelshop.js +++ b/assets/js/parcelshop.js @@ -13,7 +13,7 @@ var map; var parcelshop_address; // If parcelshop is selected in shipment. Adds a button to choose a parcelshop -if (document.getElementById('shipping_method_0_wuunder_parcelshop').checked) { +if (document.getElementById('shipping_method_0_wuunder_parcelshop') && document.getElementById('shipping_method_0_wuunder_parcelshop').checked) { var node = document.createElement("div"); node.className += "chooseParcelshop"; node.innerHTML = '
'; diff --git a/includes/parcelshop.php b/includes/parcelshop.php index f2e560a..9ece902 100644 --- a/includes/parcelshop.php +++ b/includes/parcelshop.php @@ -1,12 +1,10 @@ getParcelshopsByAddress(); $parcelshopsConfig = new \Wuunder\Api\Config\ParcelshopsConfig(); - $logger = wc_get_logger(); - $context = array('source' => "wuunder_connector"); - $parcelshopsConfig->setProviders(get_option('woocommerce_wuunder_parcelshop_settings')['select_carriers']); $parcelshopsConfig->setAddress($shipping_address); diff --git a/includes/wcwuunder-create.php b/includes/wcwuunder-create.php index fce1c4e..a0d5c30 100644 --- a/includes/wcwuunder-create.php +++ b/includes/wcwuunder-create.php @@ -64,9 +64,11 @@ public function sample_admin_notice__error() */ private function setBookingConfig($orderId) { - $logger = wc_get_logger(); - $context = array('source' => "wuunder_connector"); - $logger->log('info', "Filling the booking config", $context); + if (WP_DEBUG) { + $logger = wc_get_logger(); + $context = array('source' => "wuunder_connector"); + $logger->log('info', "Filling the booking config", $context); + } $orderItems = $this->get_order_items($orderId); @@ -153,31 +155,33 @@ public function generateBookingUrl() $context = array('source' => "wuunder_connector"); if (isset($_REQUEST['order']) && $_REQUEST['action'] === "bookorder") { - $logger->log('info', "Generating the booking url", $context); + if (WP_DEBUG) + $logger->log('info', "Generating the booking url", $context); $order_id = $_REQUEST['order']; $status = get_option('wc_wuunder_api_status'); $apiKey = ($status == 'productie' ? get_option('wc_wuunder_api') : get_option('wc_wuunder_test_api')); - $connector = new Wuunder\Connector($apiKey, $status !== 'productie'); $booking = $connector->createBooking(); $bookingConfig = $this->setBookingConfig($order_id); if ($bookingConfig->validate()) { $booking->setConfig($bookingConfig); - $logger->log('info', "Going to fire for bookingurl", $context); + if (WP_DEBUG) + $logger->log('info', "Going to fire for bookingurl", $context); if ($booking->fire()) { $url = $booking->getBookingResponse()->getBookingUrl(); - } else { + } else if (WP_DEBUG) { $logger->log('error', $booking->getBookingResponse()->getError(), $context); } - } else { + } else if (WP_DEBUG) { $logger->log('error', "Bookingconfig not complete", $context); } - $logger->log('info', "Handling response", $context); + if (WP_DEBUG) + $logger->log('info', "Handling response", $context); if (isset($url)) { update_post_meta($order_id, '_wuunder_label_booking_url', $url); @@ -257,7 +261,8 @@ public function get_company_address() if ($pickupAddress->validate()) { return $pickupAddress; } else { - $logger->log('error', "Invalid pickup address. There are mistakes or missing fields.", $context); + if (WP_DEBUG) + $logger->log('error', "Invalid pickup address. There are mistakes or missing fields.", $context); return $pickupAddress; } } @@ -366,7 +371,8 @@ public function get_customer_address($orderid) if ($deliveryAddress->validate()) { return $deliveryAddress; } else { - $logger->log('error', "Invalid delivery address. There are mistakes or missing fields.", $context); + if (WP_DEBUG) + $logger->log('error', "Invalid delivery address. There are mistakes or missing fields.", $context); return $deliveryAddress; } } @@ -384,9 +390,11 @@ public function get_base64_image($imagepath) try { $fileSize = (substr($imagepath, 0, 4) === "http") ? $this->remote_filesize($imagepath) : filesize($imagepath); - $logger->log("Handling a image of size: " . $fileSize, $context); + if (WP_DEBUG) + $logger->log("Handling a image of size: " . $fileSize, $context); if ($fileSize > 0 && $fileSize <= 2097152) { //smaller or equal to 2MB - $logger->log("Base64 encoding image", $context); + if (WP_DEBUG) + $logger->log("Base64 encoding image", $context); $imagedata = file_get_contents($imagepath); $image = base64_encode($imagedata); } else { @@ -394,7 +402,8 @@ public function get_base64_image($imagepath) } return $image; } catch (Exception $e) { - $logger->log('error', $e, $context); + if (WP_DEBUG) + $logger->log('error', $e, $context); return ""; } } diff --git a/woocommerce-wuunder.php b/woocommerce-wuunder.php index 1f4b2d4..fcf721f 100644 --- a/woocommerce-wuunder.php +++ b/woocommerce-wuunder.php @@ -98,12 +98,14 @@ public function add_admin_styles_scripts() public function webhook() { - $logger = wc_get_logger(); - $context = array('source' => "wuunder_connector"); + if (WP_DEBUG) { + $logger = wc_get_logger(); + $context = array('source' => "wuunder_connector"); - $logger->log('info', "Test webhook", $context); - $logger->log('info', $_REQUEST['order'], $context); - $logger->log('info', $_REQUEST['token'], $context); + $logger->log('info', "Test webhook", $context); + $logger->log('info', $_REQUEST['order'], $context); + $logger->log('info', $_REQUEST['token'], $context); + } if (!isset($_REQUEST['order']) || !isset($_REQUEST['token'])) { wp_redirect("", 500);