Changeset 2305894
- Timestamp:
- 05/15/2020 07:29:55 PM (6 years ago)
- Location:
- zsquared-connector-for-zoho-crm
- Files:
-
- 12 edited
-
tags/1.0/include/ZsqConnectorOptions.php (modified) (7 diffs)
-
tags/1.0/include/ZsqOrderSync.php (modified) (6 diffs)
-
tags/1.0/include/ZsqProductSync.php (modified) (2 diffs)
-
tags/1.0/templates/options.php (modified) (5 diffs)
-
tags/1.0/templates/scripts.php (modified) (4 diffs)
-
tags/1.0/zsq-connector-crm.php (modified) (2 diffs)
-
trunk/include/ZsqConnectorOptions.php (modified) (7 diffs)
-
trunk/include/ZsqOrderSync.php (modified) (6 diffs)
-
trunk/include/ZsqProductSync.php (modified) (2 diffs)
-
trunk/templates/options.php (modified) (5 diffs)
-
trunk/templates/scripts.php (modified) (4 diffs)
-
trunk/zsq-connector-crm.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
zsquared-connector-for-zoho-crm/tags/1.0/include/ZsqConnectorOptions.php
r2303034 r2305894 12 12 private $hook_trigger; 13 13 private $shipping_item; 14 15 private $server_online = false; 16 private $account_connect = false; 14 17 15 18 public function __construct() … … 47 50 echo "<div class=\"notice notice-error is-dismissible\"><p>Order replay failed. Please see Slack output for details.</p></div>"; 48 51 } 49 if(true === $check) {52 else if(true === $check) { 50 53 echo "<div class=\"notice notice-success is-dismissible\"><p>Order replay succeeded.</p></div>"; 51 54 } 52 if(is_null($check)) {55 else if(is_null($check)) { 53 56 echo "<div class=\"notice notice-warning is-dismissible\"><p>Order replay not triggered due to status. Please review your settings.</p></div>"; 57 } 58 else if (is_string($check)) { 59 echo "<div class=\"notice notice-error is-dismissible\"><p>Order replay failed: $check</p></div>"; 54 60 } 55 61 } … … 97 103 } 98 104 } 99 $woo_taxes = $this->getWooTaxes(); 100 $server = $this->getServerStatus(); 101 if(is_null($this->api_key) || $this->api_key == "") { 102 $ex_taxes = []; 103 $status = 'No connection set up'; 104 } 105 else if($server != 'Connected') { 106 $ex_taxes = []; 107 $status = 'Could not reach ZSquared Server'; 108 } 109 else { 110 $ex_taxes = $this->getExternalTaxes(); 111 $status = $this->getConnectionStatus(); 112 } 113 include(ZSQ_CRM_PLUGIN_PATH."/templates/scripts.php"); 114 include(ZSQ_CRM_PLUGIN_PATH."/templates/options.php"); 105 if(function_exists('wc_get_order')) { 106 $woo_taxes = $this->getWooTaxes(); 107 $server = $this->getServerStatus(); 108 if(is_null($this->api_key) || $this->api_key == "") { 109 $ex_taxes = []; 110 $status = 'No connection set up'; 111 } 112 else if($server != 'Connected') { 113 $ex_taxes = []; 114 $status = 'Could not reach ZSquared Server'; 115 } 116 else { 117 $ex_taxes = $this->getExternalTaxes(); 118 $status = $this->getConnectionStatus(); 119 } 120 include(ZSQ_CRM_PLUGIN_PATH . "/templates/scripts.php"); 121 include(ZSQ_CRM_PLUGIN_PATH . "/templates/options.php"); 122 } 115 123 } 116 124 … … 205 213 206 214 public function invSync() { 207 echo " Keep Woocommerce products up to date by automatically syncing changes from Zoho CRM. <br /><strong>Note that products will be updated according to their SKU numbers, and there will be a delay of 24 hours to avoid breaking your API limit.</strong>";215 echo "<p>Keep Woocommerce products up to date by automatically syncing changes from Zoho CRM. <br /><strong>Note that products will be updated every 24 hrs.</strong></p>"; 208 216 } 209 217 … … 220 228 221 229 private function getExternalTaxes() { 230 if(empty($this->api_key) || $this->api_key == "") { 231 // can't get taxes without the api key 232 return []; 233 } 234 if(!$this->server_online || !$this->account_connect) { 235 // can't get taxes if the server/account are not responding 236 return []; 237 } 222 238 $url = ZSQ_CRM_API_ENDPOINT."wp/taxes?api_key=".$this->api_key."&zsq_conn_host=".ZSQ_CRM_HOST; 223 239 $response = wp_remote_get($url, 224 240 array('sslverify' => FALSE)); 225 241 if(is_a($response, WP_Error::class)) { 226 return []; 242 echo "ERROR: " . $response->get_error_message(); 243 die; 227 244 } 228 245 $output = json_decode($response['body'], true); … … 254 271 array('sslverify' => FALSE)); 255 272 if(is_a($response, WP_Error::class)) { 256 return " Could not reach ZSquared Server";273 return "WP ERROR: " . $response->get_error_message(); 257 274 } 258 275 $output = json_decode($response['body'], true); 259 276 if (isset($output['data']['status']) && !empty($output['data']['status'])) { 277 $this->account_connect = true; 260 278 return $output['data']['status']; 261 279 } 262 else {263 ZsqSlackNotifications::send('Error on connection status API call: '.print_r($output['message'], true));264 }265 280 return "Could not determine status at this time"; 266 281 } … … 269 284 270 285 private function getServerStatus() { 271 $url = ZSQ_CRM_API_ENDPOINT."wp/server"; 272 $response = wp_remote_get($url, 273 array('sslverify' => FALSE)); 274 if(is_a($response, WP_Error::class)) { 275 return "Offline"; 276 } 277 $output = json_decode($response['body'], true); 278 if (isset($output['data']['server']) && !empty($output['data']['server'])) { 279 return $output['data']['server']; 280 } 281 else { 282 ZsqSlackNotifications::send('Error on connection status API call: '.print_r($output['message'], true)); 283 } 284 return "Could not reach ZSquared Server"; 286 if(!empty($this->api_key) && $this->api_key != "") { 287 $url = ZSQ_CRM_API_ENDPOINT . "wp/server?api_key=" . $this->api_key . "&zsq_conn_host=" . ZSQ_CRM_HOST; 288 $response = wp_remote_get($url, 289 array('sslverify' => FALSE)); 290 if(is_a($response, WP_Error::class)) { 291 return "WP ERROR: " . $response->get_error_message(); 292 } 293 $output = json_decode($response['body'], true); 294 if (isset($output['data']['server']) && !empty($output['data']['server'])) { 295 $this->server_online = true; 296 return $output['data']['server']; 297 } 298 return "Not connected"; 299 } 300 return "No connection set up"; 285 301 } 286 302 -
zsquared-connector-for-zoho-crm/tags/1.0/include/ZsqOrderSync.php
r2303034 r2305894 12 12 13 13 private $processOutput = []; 14 public $error_message; 14 15 15 16 private $state = null; … … 20 21 try { 21 22 $this->api_key = get_option('zsq_crm_api_key'); 22 $this->processOutput[] = "API Key => " . $this->api_key . "; endpoint => " . ZSQ_CRM_API_ENDPOINT;23 $this->processOutput[] = "API Key => " . $this->api_key; 23 24 $order_array = []; 24 25 $order_prefix = get_option('zsq_crm_order_prefix'); … … 37 38 $tax_id = get_option('zsq_crm_ex_to_woo_tax_map_'.$rate_id); 38 39 if(empty($tax_id)) { 39 $this->processOutput[] = "ERROR: No Zoho Inventory tax ID set for the following tax: ".print_r($t, true); 40 $this->processOutput[] = "ERROR: No Zoho CRM tax ID set for the following tax: ".print_r($t, true); 41 $this->error_message = "ERROR: No Zoho CRM tax ID set for the following tax: ".print_r($t, true)."; cannot transfer at this time."; 40 42 $this->sendProcessOutput(); 41 43 return false; … … 60 62 if(is_a($response, WP_Error::class)) { 61 63 $this->processOutput[] = "WP ERROR on sales order send: " . print_r($response->get_error_message(), true); 64 $this->error_message = "WP ERROR on sales order send: " . print_r($response->get_error_message(), true); 62 65 $this->sendProcessOutput(); 63 66 $this->state = false; … … 65 68 } 66 69 $body = json_decode($response['body'], true); 67 if (isset($body[' data']['output']) && $body['data']['output'] == "Done") {70 if (isset($body['message']) && $body['message'] == "Done") { 68 71 ZsqSlackNotifications::orderComplete($order); 69 72 $this->state = true; 70 73 return true; 74 } else if (isset($body['message'])) { 75 $this->processOutput[] = "ERROR on sales order send: " . $body['message']; 76 $this->error_message = "ERROR on sales order send: " . $body['message']; 77 $this->state = false; 71 78 } else { 72 $this->processOutput[] = "ZOHO ERROR on sales order send: " . print_r($response['body'], true); 79 $this->processOutput[] = "ERROR on sales order send; response from ZSquared: " . print_r($response['body'], true); 80 $this->error_message = "ERROR on sales order send; response from ZSquared: " . print_r($response['body'], true); 73 81 $this->state = false; 74 82 } 75 83 } else { 76 84 $this->processOutput[] = "ERROR: API key missing"; 85 $this->error_message = "ERROR: API key missing"; 77 86 } 78 87 $this->sendProcessOutput(); 79 88 $this->state = false; 80 89 } catch (\Exception $e) { 81 $this->processOutput[] = " PHP Exception: " . $e->getMessage() . ' on order ID ' . $order->get_id();82 $this-> processOutput[] = "Exception on ".$e->getLine().' in '.$e->getFile();90 $this->processOutput[] = "ERROR: " . $e->getMessage() . ' on order ID ' . $order->get_id(); 91 $this->error_message = "ERROR: " . $e->getMessage() . ' on order ID ' . $order->get_id(); 83 92 $this->sendProcessOutput(); 84 93 $this->state = false; … … 97 106 $product = new WC_Order_Item_Product($item->get_id()); 98 107 $realproduct = wc_get_product($product->get_product_id()); 99 $new_item = [ 100 "rate" => number_format(($product->get_subtotal() / $item->get_quantity()), 2), 101 "quantity" => $item->get_quantity(), 102 "unit" => "qty", 103 "item_total" => $product->get_total(), 104 "sku" => $realproduct->get_sku() 105 ]; 106 $return_array[] = $new_item; 108 if($realproduct) { 109 $new_item = [ 110 "rate" => number_format(($product->get_subtotal() / $item->get_quantity()), 2), 111 "quantity" => $item->get_quantity(), 112 "unit" => "qty", 113 "item_total" => $product->get_total(), 114 "sku" => $realproduct->get_sku() 115 ]; 116 $return_array[] = $new_item; 117 } 118 else { 119 throw new \Exception("Could not get product info from order item ".$product->get_name()); 120 } 107 121 } 108 122 return $return_array; -
zsquared-connector-for-zoho-crm/tags/1.0/include/ZsqProductSync.php
r2303034 r2305894 35 35 return "Product sync complete"; 36 36 } 37 else if (isset($output['message']) && $output['message'] != 'done') { 38 return $output['message']; 39 } 40 else if (isset($output['message']) && $output['message'] == 'done') { 41 return "Product sync complete"; 42 } 37 43 else { 38 ZsqSlackNotifications::send('Error on connection manual sync API call: '.print_r($output['message'], true)); 39 return "No products found! Could not sync at this time"; 44 return "No products found! Please make sure that your API key is correct. Could not sync at this time."; 40 45 } 41 46 } … … 66 71 } 67 72 if ($output['data']['more'] === 'true') { 68 return 'more'; 73 $page++; 74 return $this->dailySync($page); 69 75 } 70 76 return "Daily product sync complete"; 71 } else { 72 ZsqSlackNotifications::send('Error on connection daily sync API call: ' . print_r($output['message'], true)); 77 } 78 else if (isset($output['message']) && $output != 'done') { 79 return $output['message']; 80 } 81 else if (isset($output['message']) && $output['message'] == 'done') { 82 return "Daily product sync complete"; 83 } 84 else { 73 85 return "No products found! Could not sync at this time"; 74 86 } -
zsquared-connector-for-zoho-crm/tags/1.0/templates/options.php
r2303034 r2305894 1 <script type="text/javascript"> 2 function zsq_switch_tabs(tabname) { 3 jQuery('.zspl-tab').hide(); 4 jQuery('.zspl-nav').removeClass('active'); 5 jQuery('#zspl-tab-' + tabname).show(); 6 jQuery('#zspl-nav-' + tabname).addClass('active'); 7 } 8 </script> 9 1 <?php $showtab = esc_attr($_REQUEST['show']); if($showtab == "") $showtab = null; ?> 10 2 <div class="wrap zspl-wrap"> 11 3 <div class="zspl-header"> … … 16 8 <div class="zspl-tab-parent"> 17 9 <div class="zspl-tab-wrapper"> 18 <a href="#" id="zspl-nav-settings" class="zspl-nav<?php echo esc_attr(($_REQUEST['show'] == 'settings' || !isset($_REQUEST['show'])) ? " active" : '');?>" onclick="zsq_switch_tabs('settings')">Configuration</a>19 <a href="#" id="zspl-nav-inventory" class="zspl-nav<?php echo esc_attr(($_REQUEST['show'] == 'inventory') ? " active" : '');?>" onclick="zsq_switch_tabs('inventory')">Inventory Management</a>20 <a href="#" id="zspl-nav-replay" class="zspl-nav<?php echo esc_attr(($_REQUEST['show'] == 'replay') ? " active" : '');?>" onclick="zsq_switch_tabs('replay')">Replay Sales Orders</a>21 <a href="#" id="zspl-nav-tax" class="zspl-nav<?php echo esc_attr(($_REQUEST['show'] == 'tax') ? " active" : '');?>" onclick="zsq_switch_tabs('tax')">Tax Settings</a>10 <a href="#" id="zspl-nav-settings" class="zspl-nav<?php echo $showtab == 'settings' || is_null($showtab) ? " active" : '';?>" onclick="zsq_switch_tabs('settings')">Configuration</a> 11 <a href="#" id="zspl-nav-inventory" class="zspl-nav<?php echo $showtab == 'inventory' ? " active" : '';?>" onclick="zsq_switch_tabs('inventory')">Inventory Management</a> 12 <a href="#" id="zspl-nav-replay" class="zspl-nav<?php echo $showtab == 'replay' ? " active" : '';?>" onclick="zsq_switch_tabs('replay')">Replay Sales Orders</a> 13 <a href="#" id="zspl-nav-tax" class="zspl-nav<?php echo $showtab == 'tax' ? " active" : '';?>" onclick="zsq_switch_tabs('tax')">Tax Settings</a> 22 14 </div> 23 15 </div> 24 16 25 <div class="zspl-tab" id="zspl-tab-settings"<?php echo esc_attr(($_REQUEST['show'] == 'settings' || !isset($_REQUEST['show'])) ? "" : ' style="display:none;"');?>>17 <div class="zspl-tab" id="zspl-tab-settings"<?php echo $showtab == 'settings' || is_null($showtab) ? "" : ' style="display:none;"';?>> 26 18 <div class="zspl-conn-info"> 27 19 <?php if (strlen(get_option('zsq_crm_api_key')) > 0) : ?> … … 55 47 </div> 56 48 57 <div class="zspl-tab" id="zspl-tab-inventory"<?php echo esc_attr($_REQUEST['show'] == 'inventory' ? "" : ' style="display:none;"');?>>49 <div class="zspl-tab" id="zspl-tab-inventory"<?php echo $showtab == 'inventory' ? "" : ' style="display:none;"';?>> 58 50 <form class="zspl-form zspl-sync-settings-form" method="post" action="options-general.php?page=zsq_crm.php&show=inventory"> 59 51 <input type="hidden" name="zsq_crm_setting_supdate" value="1"/> … … 81 73 82 74 83 <div class="zspl-tab" id="zspl-tab-replay"<?php echo esc_attr($_REQUEST['show'] == 'replay' ? "" : ' style="display:none;"');?>>75 <div class="zspl-tab" id="zspl-tab-replay"<?php echo $showtab == 'replay' ? "" : ' style="display:none;"';?>> 84 76 <div class="zspl-manual-sync"> 85 77 <h2>Replay order submission</h2> … … 106 98 </div> 107 99 108 <div class="zspl-tab" id="zspl-tab-tax"<?php echo esc_attr($_REQUEST['show'] == 'tax' ? "" : ' style="display:none;"');?>>100 <div class="zspl-tab" id="zspl-tab-tax"<?php echo $showtab == 'tax' ? "" : ' style="display:none;"';?>> 109 101 <div class="zspl-tax-mapping"> 110 102 <h2>Tax Information Mapping</h2> -
zsquared-connector-for-zoho-crm/tags/1.0/templates/scripts.php
r2303034 r2305894 2 2 jQuery(function($) { 3 3 function zsq_crm_manualSyncPage(page) { 4 $("#zsq_crm_manual_sync_message").text("Sync starting..."); 4 var from = (page*100)-99; 5 var to = page*100; 6 $("#zsq_crm_manual_sync_message").text("Syncing "+from+" to "+to+" products, please wait..."); 5 7 $.ajax({ 6 8 url: ajaxurl, … … 12 14 if(data === 'more') { 13 15 page++; 14 $("#zsq_crm_manual_sync_message").text("DO NOT REFRESH THE PAGE. Syncing "+(page*100)+" products, please wait..."); 15 zconn_manualSyncPage(page); 16 zsq_crm_manualSyncPage(page); 16 17 } 17 18 else { … … 19 20 setTimeout(function(){ 20 21 $("#zsq_crm_manual_sync_message").text(""); 21 }, 5000);22 }, 10000); 22 23 } 23 24 } … … 32 33 }); 33 34 }); 35 36 function zsq_switch_tabs(tabname) { 37 jQuery('.zspl-tab').hide(); 38 jQuery('.zspl-nav').removeClass('active'); 39 jQuery('#zspl-tab-' + tabname).show(); 40 jQuery('#zspl-nav-' + tabname).addClass('active'); 41 } 34 42 </script> -
zsquared-connector-for-zoho-crm/tags/1.0/zsq-connector-crm.php
r2303034 r2305894 57 57 $order = wc_get_order($order_id); 58 58 $obj = new \PCIS\ZSquared\CRM\ZsqOrderSync($order); 59 if(!$obj->getState()) { 60 return $obj->error_message; 61 } 59 62 return $obj->getState(); 60 63 } … … 62 65 function zsq_crm_daily_sync() { 63 66 $obj = new \PCIS\ZSquared\CRM\ZsqProductSync(); 64 $obj->dailySync(1); 67 $response = $obj->dailySync(1); 68 if(is_string($response) && $response != 'Daily product sync complete') { 69 \PCIS\ZSquared\CRM\ZsqSlackNotifications::send('Daily sync failed; ERROR: '.$response); 70 } 65 71 } 66 72 -
zsquared-connector-for-zoho-crm/trunk/include/ZsqConnectorOptions.php
r2303034 r2305894 12 12 private $hook_trigger; 13 13 private $shipping_item; 14 15 private $server_online = false; 16 private $account_connect = false; 14 17 15 18 public function __construct() … … 47 50 echo "<div class=\"notice notice-error is-dismissible\"><p>Order replay failed. Please see Slack output for details.</p></div>"; 48 51 } 49 if(true === $check) {52 else if(true === $check) { 50 53 echo "<div class=\"notice notice-success is-dismissible\"><p>Order replay succeeded.</p></div>"; 51 54 } 52 if(is_null($check)) {55 else if(is_null($check)) { 53 56 echo "<div class=\"notice notice-warning is-dismissible\"><p>Order replay not triggered due to status. Please review your settings.</p></div>"; 57 } 58 else if (is_string($check)) { 59 echo "<div class=\"notice notice-error is-dismissible\"><p>Order replay failed: $check</p></div>"; 54 60 } 55 61 } … … 97 103 } 98 104 } 99 $woo_taxes = $this->getWooTaxes(); 100 $server = $this->getServerStatus(); 101 if(is_null($this->api_key) || $this->api_key == "") { 102 $ex_taxes = []; 103 $status = 'No connection set up'; 104 } 105 else if($server != 'Connected') { 106 $ex_taxes = []; 107 $status = 'Could not reach ZSquared Server'; 108 } 109 else { 110 $ex_taxes = $this->getExternalTaxes(); 111 $status = $this->getConnectionStatus(); 112 } 113 include(ZSQ_CRM_PLUGIN_PATH."/templates/scripts.php"); 114 include(ZSQ_CRM_PLUGIN_PATH."/templates/options.php"); 105 if(function_exists('wc_get_order')) { 106 $woo_taxes = $this->getWooTaxes(); 107 $server = $this->getServerStatus(); 108 if(is_null($this->api_key) || $this->api_key == "") { 109 $ex_taxes = []; 110 $status = 'No connection set up'; 111 } 112 else if($server != 'Connected') { 113 $ex_taxes = []; 114 $status = 'Could not reach ZSquared Server'; 115 } 116 else { 117 $ex_taxes = $this->getExternalTaxes(); 118 $status = $this->getConnectionStatus(); 119 } 120 include(ZSQ_CRM_PLUGIN_PATH . "/templates/scripts.php"); 121 include(ZSQ_CRM_PLUGIN_PATH . "/templates/options.php"); 122 } 115 123 } 116 124 … … 205 213 206 214 public function invSync() { 207 echo " Keep Woocommerce products up to date by automatically syncing changes from Zoho CRM. <br /><strong>Note that products will be updated according to their SKU numbers, and there will be a delay of 24 hours to avoid breaking your API limit.</strong>";215 echo "<p>Keep Woocommerce products up to date by automatically syncing changes from Zoho CRM. <br /><strong>Note that products will be updated every 24 hrs.</strong></p>"; 208 216 } 209 217 … … 220 228 221 229 private function getExternalTaxes() { 230 if(empty($this->api_key) || $this->api_key == "") { 231 // can't get taxes without the api key 232 return []; 233 } 234 if(!$this->server_online || !$this->account_connect) { 235 // can't get taxes if the server/account are not responding 236 return []; 237 } 222 238 $url = ZSQ_CRM_API_ENDPOINT."wp/taxes?api_key=".$this->api_key."&zsq_conn_host=".ZSQ_CRM_HOST; 223 239 $response = wp_remote_get($url, 224 240 array('sslverify' => FALSE)); 225 241 if(is_a($response, WP_Error::class)) { 226 return []; 242 echo "ERROR: " . $response->get_error_message(); 243 die; 227 244 } 228 245 $output = json_decode($response['body'], true); … … 254 271 array('sslverify' => FALSE)); 255 272 if(is_a($response, WP_Error::class)) { 256 return " Could not reach ZSquared Server";273 return "WP ERROR: " . $response->get_error_message(); 257 274 } 258 275 $output = json_decode($response['body'], true); 259 276 if (isset($output['data']['status']) && !empty($output['data']['status'])) { 277 $this->account_connect = true; 260 278 return $output['data']['status']; 261 279 } 262 else {263 ZsqSlackNotifications::send('Error on connection status API call: '.print_r($output['message'], true));264 }265 280 return "Could not determine status at this time"; 266 281 } … … 269 284 270 285 private function getServerStatus() { 271 $url = ZSQ_CRM_API_ENDPOINT."wp/server"; 272 $response = wp_remote_get($url, 273 array('sslverify' => FALSE)); 274 if(is_a($response, WP_Error::class)) { 275 return "Offline"; 276 } 277 $output = json_decode($response['body'], true); 278 if (isset($output['data']['server']) && !empty($output['data']['server'])) { 279 return $output['data']['server']; 280 } 281 else { 282 ZsqSlackNotifications::send('Error on connection status API call: '.print_r($output['message'], true)); 283 } 284 return "Could not reach ZSquared Server"; 286 if(!empty($this->api_key) && $this->api_key != "") { 287 $url = ZSQ_CRM_API_ENDPOINT . "wp/server?api_key=" . $this->api_key . "&zsq_conn_host=" . ZSQ_CRM_HOST; 288 $response = wp_remote_get($url, 289 array('sslverify' => FALSE)); 290 if(is_a($response, WP_Error::class)) { 291 return "WP ERROR: " . $response->get_error_message(); 292 } 293 $output = json_decode($response['body'], true); 294 if (isset($output['data']['server']) && !empty($output['data']['server'])) { 295 $this->server_online = true; 296 return $output['data']['server']; 297 } 298 return "Not connected"; 299 } 300 return "No connection set up"; 285 301 } 286 302 -
zsquared-connector-for-zoho-crm/trunk/include/ZsqOrderSync.php
r2303034 r2305894 12 12 13 13 private $processOutput = []; 14 public $error_message; 14 15 15 16 private $state = null; … … 20 21 try { 21 22 $this->api_key = get_option('zsq_crm_api_key'); 22 $this->processOutput[] = "API Key => " . $this->api_key . "; endpoint => " . ZSQ_CRM_API_ENDPOINT;23 $this->processOutput[] = "API Key => " . $this->api_key; 23 24 $order_array = []; 24 25 $order_prefix = get_option('zsq_crm_order_prefix'); … … 37 38 $tax_id = get_option('zsq_crm_ex_to_woo_tax_map_'.$rate_id); 38 39 if(empty($tax_id)) { 39 $this->processOutput[] = "ERROR: No Zoho Inventory tax ID set for the following tax: ".print_r($t, true); 40 $this->processOutput[] = "ERROR: No Zoho CRM tax ID set for the following tax: ".print_r($t, true); 41 $this->error_message = "ERROR: No Zoho CRM tax ID set for the following tax: ".print_r($t, true)."; cannot transfer at this time."; 40 42 $this->sendProcessOutput(); 41 43 return false; … … 60 62 if(is_a($response, WP_Error::class)) { 61 63 $this->processOutput[] = "WP ERROR on sales order send: " . print_r($response->get_error_message(), true); 64 $this->error_message = "WP ERROR on sales order send: " . print_r($response->get_error_message(), true); 62 65 $this->sendProcessOutput(); 63 66 $this->state = false; … … 65 68 } 66 69 $body = json_decode($response['body'], true); 67 if (isset($body[' data']['output']) && $body['data']['output'] == "Done") {70 if (isset($body['message']) && $body['message'] == "Done") { 68 71 ZsqSlackNotifications::orderComplete($order); 69 72 $this->state = true; 70 73 return true; 74 } else if (isset($body['message'])) { 75 $this->processOutput[] = "ERROR on sales order send: " . $body['message']; 76 $this->error_message = "ERROR on sales order send: " . $body['message']; 77 $this->state = false; 71 78 } else { 72 $this->processOutput[] = "ZOHO ERROR on sales order send: " . print_r($response['body'], true); 79 $this->processOutput[] = "ERROR on sales order send; response from ZSquared: " . print_r($response['body'], true); 80 $this->error_message = "ERROR on sales order send; response from ZSquared: " . print_r($response['body'], true); 73 81 $this->state = false; 74 82 } 75 83 } else { 76 84 $this->processOutput[] = "ERROR: API key missing"; 85 $this->error_message = "ERROR: API key missing"; 77 86 } 78 87 $this->sendProcessOutput(); 79 88 $this->state = false; 80 89 } catch (\Exception $e) { 81 $this->processOutput[] = " PHP Exception: " . $e->getMessage() . ' on order ID ' . $order->get_id();82 $this-> processOutput[] = "Exception on ".$e->getLine().' in '.$e->getFile();90 $this->processOutput[] = "ERROR: " . $e->getMessage() . ' on order ID ' . $order->get_id(); 91 $this->error_message = "ERROR: " . $e->getMessage() . ' on order ID ' . $order->get_id(); 83 92 $this->sendProcessOutput(); 84 93 $this->state = false; … … 97 106 $product = new WC_Order_Item_Product($item->get_id()); 98 107 $realproduct = wc_get_product($product->get_product_id()); 99 $new_item = [ 100 "rate" => number_format(($product->get_subtotal() / $item->get_quantity()), 2), 101 "quantity" => $item->get_quantity(), 102 "unit" => "qty", 103 "item_total" => $product->get_total(), 104 "sku" => $realproduct->get_sku() 105 ]; 106 $return_array[] = $new_item; 108 if($realproduct) { 109 $new_item = [ 110 "rate" => number_format(($product->get_subtotal() / $item->get_quantity()), 2), 111 "quantity" => $item->get_quantity(), 112 "unit" => "qty", 113 "item_total" => $product->get_total(), 114 "sku" => $realproduct->get_sku() 115 ]; 116 $return_array[] = $new_item; 117 } 118 else { 119 throw new \Exception("Could not get product info from order item ".$product->get_name()); 120 } 107 121 } 108 122 return $return_array; -
zsquared-connector-for-zoho-crm/trunk/include/ZsqProductSync.php
r2303034 r2305894 35 35 return "Product sync complete"; 36 36 } 37 else if (isset($output['message']) && $output['message'] != 'done') { 38 return $output['message']; 39 } 40 else if (isset($output['message']) && $output['message'] == 'done') { 41 return "Product sync complete"; 42 } 37 43 else { 38 ZsqSlackNotifications::send('Error on connection manual sync API call: '.print_r($output['message'], true)); 39 return "No products found! Could not sync at this time"; 44 return "No products found! Please make sure that your API key is correct. Could not sync at this time."; 40 45 } 41 46 } … … 66 71 } 67 72 if ($output['data']['more'] === 'true') { 68 return 'more'; 73 $page++; 74 return $this->dailySync($page); 69 75 } 70 76 return "Daily product sync complete"; 71 } else { 72 ZsqSlackNotifications::send('Error on connection daily sync API call: ' . print_r($output['message'], true)); 77 } 78 else if (isset($output['message']) && $output != 'done') { 79 return $output['message']; 80 } 81 else if (isset($output['message']) && $output['message'] == 'done') { 82 return "Daily product sync complete"; 83 } 84 else { 73 85 return "No products found! Could not sync at this time"; 74 86 } -
zsquared-connector-for-zoho-crm/trunk/templates/options.php
r2303034 r2305894 1 <script type="text/javascript"> 2 function zsq_switch_tabs(tabname) { 3 jQuery('.zspl-tab').hide(); 4 jQuery('.zspl-nav').removeClass('active'); 5 jQuery('#zspl-tab-' + tabname).show(); 6 jQuery('#zspl-nav-' + tabname).addClass('active'); 7 } 8 </script> 9 1 <?php $showtab = esc_attr($_REQUEST['show']); if($showtab == "") $showtab = null; ?> 10 2 <div class="wrap zspl-wrap"> 11 3 <div class="zspl-header"> … … 16 8 <div class="zspl-tab-parent"> 17 9 <div class="zspl-tab-wrapper"> 18 <a href="#" id="zspl-nav-settings" class="zspl-nav<?php echo esc_attr(($_REQUEST['show'] == 'settings' || !isset($_REQUEST['show'])) ? " active" : '');?>" onclick="zsq_switch_tabs('settings')">Configuration</a>19 <a href="#" id="zspl-nav-inventory" class="zspl-nav<?php echo esc_attr(($_REQUEST['show'] == 'inventory') ? " active" : '');?>" onclick="zsq_switch_tabs('inventory')">Inventory Management</a>20 <a href="#" id="zspl-nav-replay" class="zspl-nav<?php echo esc_attr(($_REQUEST['show'] == 'replay') ? " active" : '');?>" onclick="zsq_switch_tabs('replay')">Replay Sales Orders</a>21 <a href="#" id="zspl-nav-tax" class="zspl-nav<?php echo esc_attr(($_REQUEST['show'] == 'tax') ? " active" : '');?>" onclick="zsq_switch_tabs('tax')">Tax Settings</a>10 <a href="#" id="zspl-nav-settings" class="zspl-nav<?php echo $showtab == 'settings' || is_null($showtab) ? " active" : '';?>" onclick="zsq_switch_tabs('settings')">Configuration</a> 11 <a href="#" id="zspl-nav-inventory" class="zspl-nav<?php echo $showtab == 'inventory' ? " active" : '';?>" onclick="zsq_switch_tabs('inventory')">Inventory Management</a> 12 <a href="#" id="zspl-nav-replay" class="zspl-nav<?php echo $showtab == 'replay' ? " active" : '';?>" onclick="zsq_switch_tabs('replay')">Replay Sales Orders</a> 13 <a href="#" id="zspl-nav-tax" class="zspl-nav<?php echo $showtab == 'tax' ? " active" : '';?>" onclick="zsq_switch_tabs('tax')">Tax Settings</a> 22 14 </div> 23 15 </div> 24 16 25 <div class="zspl-tab" id="zspl-tab-settings"<?php echo esc_attr(($_REQUEST['show'] == 'settings' || !isset($_REQUEST['show'])) ? "" : ' style="display:none;"');?>>17 <div class="zspl-tab" id="zspl-tab-settings"<?php echo $showtab == 'settings' || is_null($showtab) ? "" : ' style="display:none;"';?>> 26 18 <div class="zspl-conn-info"> 27 19 <?php if (strlen(get_option('zsq_crm_api_key')) > 0) : ?> … … 55 47 </div> 56 48 57 <div class="zspl-tab" id="zspl-tab-inventory"<?php echo esc_attr($_REQUEST['show'] == 'inventory' ? "" : ' style="display:none;"');?>>49 <div class="zspl-tab" id="zspl-tab-inventory"<?php echo $showtab == 'inventory' ? "" : ' style="display:none;"';?>> 58 50 <form class="zspl-form zspl-sync-settings-form" method="post" action="options-general.php?page=zsq_crm.php&show=inventory"> 59 51 <input type="hidden" name="zsq_crm_setting_supdate" value="1"/> … … 81 73 82 74 83 <div class="zspl-tab" id="zspl-tab-replay"<?php echo esc_attr($_REQUEST['show'] == 'replay' ? "" : ' style="display:none;"');?>>75 <div class="zspl-tab" id="zspl-tab-replay"<?php echo $showtab == 'replay' ? "" : ' style="display:none;"';?>> 84 76 <div class="zspl-manual-sync"> 85 77 <h2>Replay order submission</h2> … … 106 98 </div> 107 99 108 <div class="zspl-tab" id="zspl-tab-tax"<?php echo esc_attr($_REQUEST['show'] == 'tax' ? "" : ' style="display:none;"');?>>100 <div class="zspl-tab" id="zspl-tab-tax"<?php echo $showtab == 'tax' ? "" : ' style="display:none;"';?>> 109 101 <div class="zspl-tax-mapping"> 110 102 <h2>Tax Information Mapping</h2> -
zsquared-connector-for-zoho-crm/trunk/templates/scripts.php
r2303034 r2305894 2 2 jQuery(function($) { 3 3 function zsq_crm_manualSyncPage(page) { 4 $("#zsq_crm_manual_sync_message").text("Sync starting..."); 4 var from = (page*100)-99; 5 var to = page*100; 6 $("#zsq_crm_manual_sync_message").text("Syncing "+from+" to "+to+" products, please wait..."); 5 7 $.ajax({ 6 8 url: ajaxurl, … … 12 14 if(data === 'more') { 13 15 page++; 14 $("#zsq_crm_manual_sync_message").text("DO NOT REFRESH THE PAGE. Syncing "+(page*100)+" products, please wait..."); 15 zconn_manualSyncPage(page); 16 zsq_crm_manualSyncPage(page); 16 17 } 17 18 else { … … 19 20 setTimeout(function(){ 20 21 $("#zsq_crm_manual_sync_message").text(""); 21 }, 5000);22 }, 10000); 22 23 } 23 24 } … … 32 33 }); 33 34 }); 35 36 function zsq_switch_tabs(tabname) { 37 jQuery('.zspl-tab').hide(); 38 jQuery('.zspl-nav').removeClass('active'); 39 jQuery('#zspl-tab-' + tabname).show(); 40 jQuery('#zspl-nav-' + tabname).addClass('active'); 41 } 34 42 </script> -
zsquared-connector-for-zoho-crm/trunk/zsq-connector-crm.php
r2303034 r2305894 57 57 $order = wc_get_order($order_id); 58 58 $obj = new \PCIS\ZSquared\CRM\ZsqOrderSync($order); 59 if(!$obj->getState()) { 60 return $obj->error_message; 61 } 59 62 return $obj->getState(); 60 63 } … … 62 65 function zsq_crm_daily_sync() { 63 66 $obj = new \PCIS\ZSquared\CRM\ZsqProductSync(); 64 $obj->dailySync(1); 67 $response = $obj->dailySync(1); 68 if(is_string($response) && $response != 'Daily product sync complete') { 69 \PCIS\ZSquared\CRM\ZsqSlackNotifications::send('Daily sync failed; ERROR: '.$response); 70 } 65 71 } 66 72
Note: See TracChangeset
for help on using the changeset viewer.