From 63c71400c6d3f5642240834258605789b81be6a4 Mon Sep 17 00:00:00 2001 From: kFrolichs Date: Thu, 26 Apr 2018 13:58:48 +0200 Subject: [PATCH] Added logging and source to request to Wuunder --- includes/wcwuunder-create.php | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/includes/wcwuunder-create.php b/includes/wcwuunder-create.php index c4a4fd0..483deca 100644 --- a/includes/wcwuunder-create.php +++ b/includes/wcwuunder-create.php @@ -55,6 +55,10 @@ 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); + $orderItems = $this->get_order_items($orderId); $orderMeta = get_post_meta($orderId); $order = new WC_Order($orderId); @@ -105,6 +109,7 @@ private function setBookingConfig($orderId) $bookingConfig->setHeight(round($dimensions[2])); $bookingConfig->setWeight($totalWeight ? $totalWeight : 0); $bookingConfig->setPreferredServiceLevel((count($order->get_items('shipping')) > 0) ? $this->get_filter_from_shippingmethod(reset($order->get_items('shipping'))->get_method_id()) : ""); + $bookingConfig->setSource($version_obj); $bookingConfig->setDeliveryAddress($customer); $bookingConfig->setPickupAddress($company); @@ -118,6 +123,10 @@ private function setBookingConfig($orderId) */ public function generateBookingUrl() { + $logger = wc_get_logger(); + $context = array('source' => "wuunder_connector"); + $logger->log('info', "Generating the booking url", $context); + if (isset($_REQUEST['order']) && $_REQUEST['action'] === "bookorder") { $order_id = $_REQUEST['order']; $postData = array(); @@ -135,15 +144,16 @@ public function generateBookingUrl() if ($booking->fire()) { $url = $booking->getBookingResponse()->getBookingUrl(); } else { - var_dump($booking->getBookingResponse()->getError()); + $logger->log('error', $booking->getBookingResponse()->getError(), $context); } } else { - print("Bookingconfig not complete"); + $logger->log('error', "Bookingconfig not complete", $context); } wp_redirect($url); exit; } else { + $logger->log('error', "No order set", $context); // wp_redirect(get_site_url(null, " / wp - admin / edit . php ? post_type = shop_order")); // exit; } @@ -184,6 +194,9 @@ private function get_filter_from_shippingmethod($shipping_method) */ public function get_company_address() { + $logger = wc_get_logger(); + $context = array('source' => "wuunder_connector"); + $pickupAddress = new \Wuunder\Api\Config\AddressConfig(); $pickupAddress->setEmailAddress(get_option('wc_wuunder_company_email')); @@ -199,7 +212,7 @@ public function get_company_address() { return $pickupAddress; } else { - print("Invalid pickup address"); + $logger->log('error', "Invalid pickup address. There are mistakes or missing fields.", $context); return $pickupAddress; } } @@ -267,6 +280,9 @@ private function get_customer_address_from_address_line($order_meta) */ public function get_customer_address($orderid) { + $logger = wc_get_logger(); + $context = array('source' => "wuunder_connector"); + // Get customer address from order $order_meta = get_post_meta($orderid); $deliveryAddress = new \Wuunder\Api\Config\AddressConfig(); @@ -292,7 +308,7 @@ public function get_customer_address($orderid) { return $deliveryAddress; } else { - print("Invalid delivery address"); + $logger->log('error', "Invalid delivery address. There are mistakes or missing fields.", $context); return $deliveryAddress; } } @@ -305,6 +321,8 @@ public function get_customer_address($orderid) */ public function get_base64_image($imagepath) { + $logger = wc_get_logger(); + $context = array('source' => "wuunder_connector"); try { $fileSize = (substr($imagepath, 0, 4) === "http") ? $this->remote_filesize($imagepath) : filesize($imagepath); if ($fileSize <= 2097152) { //smaller or equal to 2MB @@ -315,6 +333,7 @@ public function get_base64_image($imagepath) } return $image; } catch (Exception $e) { + $logger->log('error', $e, $context); return ""; } }