Plugin Directory

Changeset 2305894


Ignore:
Timestamp:
05/15/2020 07:29:55 PM (6 years ago)
Author:
pcis
Message:

Added extensive better error checking

Location:
zsquared-connector-for-zoho-crm
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • zsquared-connector-for-zoho-crm/tags/1.0/include/ZsqConnectorOptions.php

    r2303034 r2305894  
    1212    private $hook_trigger;
    1313    private $shipping_item;
     14
     15    private $server_online = false;
     16    private $account_connect = false;
    1417
    1518    public function __construct()
     
    4750                echo "<div class=\"notice notice-error is-dismissible\"><p>Order replay failed. Please see Slack output for details.</p></div>";
    4851            }
    49             if(true === $check) {
     52            else if(true === $check) {
    5053                echo "<div class=\"notice notice-success is-dismissible\"><p>Order replay succeeded.</p></div>";
    5154            }
    52             if(is_null($check)) {
     55            else if(is_null($check)) {
    5356                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>";
    5460            }
    5561        }
     
    97103            }
    98104        }
    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        }
    115123    }
    116124
     
    205213
    206214    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>";
    208216    }
    209217
     
    220228
    221229    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        }
    222238        $url = ZSQ_CRM_API_ENDPOINT."wp/taxes?api_key=".$this->api_key."&zsq_conn_host=".ZSQ_CRM_HOST;
    223239        $response = wp_remote_get($url,
    224240            array('sslverify' => FALSE));
    225241        if(is_a($response, WP_Error::class)) {
    226             return [];
     242            echo "ERROR: " . $response->get_error_message();
     243            die;
    227244        }
    228245        $output = json_decode($response['body'], true);
     
    254271                array('sslverify' => FALSE));
    255272            if(is_a($response, WP_Error::class)) {
    256                 return "Could not reach ZSquared Server";
     273                return "WP ERROR: " . $response->get_error_message();
    257274            }
    258275            $output = json_decode($response['body'], true);
    259276            if (isset($output['data']['status']) && !empty($output['data']['status'])) {
     277                $this->account_connect = true;
    260278                return $output['data']['status'];
    261279            }
    262             else {
    263                 ZsqSlackNotifications::send('Error on connection status API call: '.print_r($output['message'], true));
    264             }
    265280            return "Could not determine status at this time";
    266281        }
     
    269284
    270285    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";
    285301    }
    286302
  • zsquared-connector-for-zoho-crm/tags/1.0/include/ZsqOrderSync.php

    r2303034 r2305894  
    1212
    1313    private $processOutput = [];
     14    public $error_message;
    1415
    1516    private $state = null;
     
    2021        try {
    2122            $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;
    2324            $order_array = [];
    2425            $order_prefix = get_option('zsq_crm_order_prefix');
     
    3738                $tax_id = get_option('zsq_crm_ex_to_woo_tax_map_'.$rate_id);
    3839                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.";
    4042                    $this->sendProcessOutput();
    4143                    return false;
     
    6062                if(is_a($response, WP_Error::class)) {
    6163                    $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);
    6265                    $this->sendProcessOutput();
    6366                    $this->state = false;
     
    6568                }
    6669                $body = json_decode($response['body'], true);
    67                 if (isset($body['data']['output']) && $body['data']['output'] == "Done") {
     70                if (isset($body['message']) && $body['message'] == "Done") {
    6871                    ZsqSlackNotifications::orderComplete($order);
    6972                    $this->state = true;
    7073                    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;
    7178                } 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);
    7381                    $this->state = false;
    7482                }
    7583            } else {
    7684                $this->processOutput[] = "ERROR: API key missing";
     85                $this->error_message = "ERROR: API key missing";
    7786            }
    7887            $this->sendProcessOutput();
    7988            $this->state = false;
    8089        } 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();
    8392            $this->sendProcessOutput();
    8493            $this->state = false;
     
    97106            $product = new WC_Order_Item_Product($item->get_id());
    98107            $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            }
    107121        }
    108122        return $return_array;
  • zsquared-connector-for-zoho-crm/tags/1.0/include/ZsqProductSync.php

    r2303034 r2305894  
    3535                return "Product sync complete";
    3636            }
     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            }
    3743            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.";
    4045            }
    4146        }
     
    6671                    }
    6772                    if ($output['data']['more'] === 'true') {
    68                         return 'more';
     73                        $page++;
     74                        return $this->dailySync($page);
    6975                    }
    7076                    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 {
    7385                    return "No products found! Could not sync at this time";
    7486                }
  • 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; ?>
    102<div class="wrap zspl-wrap">
    113    <div class="zspl-header">
     
    168    <div class="zspl-tab-parent">
    179        <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>
    2214        </div>
    2315    </div>
    2416
    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;"';?>>
    2618        <div class="zspl-conn-info">
    2719            <?php if (strlen(get_option('zsq_crm_api_key')) > 0) : ?>
     
    5547    </div>
    5648
    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;"';?>>
    5850        <form class="zspl-form zspl-sync-settings-form" method="post" action="options-general.php?page=zsq_crm.php&show=inventory">
    5951            <input type="hidden" name="zsq_crm_setting_supdate" value="1"/>
     
    8173
    8274
    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;"';?>>
    8476        <div class="zspl-manual-sync">
    8577            <h2>Replay order submission</h2>
     
    10698    </div>
    10799
    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;"';?>>
    109101        <div class="zspl-tax-mapping">
    110102            <h2>Tax Information Mapping</h2>
  • zsquared-connector-for-zoho-crm/tags/1.0/templates/scripts.php

    r2303034 r2305894  
    22    jQuery(function($) {
    33        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...");
    57            $.ajax({
    68                url: ajaxurl,
     
    1214                    if(data === 'more') {
    1315                        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);
    1617                    }
    1718                    else {
     
    1920                        setTimeout(function(){
    2021                            $("#zsq_crm_manual_sync_message").text("");
    21                         }, 5000);
     22                        }, 10000);
    2223                    }
    2324                }
     
    3233        });
    3334    });
     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    }
    3442</script>
  • zsquared-connector-for-zoho-crm/tags/1.0/zsq-connector-crm.php

    r2303034 r2305894  
    5757    $order = wc_get_order($order_id);
    5858    $obj = new \PCIS\ZSquared\CRM\ZsqOrderSync($order);
     59    if(!$obj->getState()) {
     60        return $obj->error_message;
     61    }
    5962    return $obj->getState();
    6063}
     
    6265function zsq_crm_daily_sync() {
    6366    $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    }
    6571}
    6672
  • zsquared-connector-for-zoho-crm/trunk/include/ZsqConnectorOptions.php

    r2303034 r2305894  
    1212    private $hook_trigger;
    1313    private $shipping_item;
     14
     15    private $server_online = false;
     16    private $account_connect = false;
    1417
    1518    public function __construct()
     
    4750                echo "<div class=\"notice notice-error is-dismissible\"><p>Order replay failed. Please see Slack output for details.</p></div>";
    4851            }
    49             if(true === $check) {
     52            else if(true === $check) {
    5053                echo "<div class=\"notice notice-success is-dismissible\"><p>Order replay succeeded.</p></div>";
    5154            }
    52             if(is_null($check)) {
     55            else if(is_null($check)) {
    5356                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>";
    5460            }
    5561        }
     
    97103            }
    98104        }
    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        }
    115123    }
    116124
     
    205213
    206214    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>";
    208216    }
    209217
     
    220228
    221229    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        }
    222238        $url = ZSQ_CRM_API_ENDPOINT."wp/taxes?api_key=".$this->api_key."&zsq_conn_host=".ZSQ_CRM_HOST;
    223239        $response = wp_remote_get($url,
    224240            array('sslverify' => FALSE));
    225241        if(is_a($response, WP_Error::class)) {
    226             return [];
     242            echo "ERROR: " . $response->get_error_message();
     243            die;
    227244        }
    228245        $output = json_decode($response['body'], true);
     
    254271                array('sslverify' => FALSE));
    255272            if(is_a($response, WP_Error::class)) {
    256                 return "Could not reach ZSquared Server";
     273                return "WP ERROR: " . $response->get_error_message();
    257274            }
    258275            $output = json_decode($response['body'], true);
    259276            if (isset($output['data']['status']) && !empty($output['data']['status'])) {
     277                $this->account_connect = true;
    260278                return $output['data']['status'];
    261279            }
    262             else {
    263                 ZsqSlackNotifications::send('Error on connection status API call: '.print_r($output['message'], true));
    264             }
    265280            return "Could not determine status at this time";
    266281        }
     
    269284
    270285    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";
    285301    }
    286302
  • zsquared-connector-for-zoho-crm/trunk/include/ZsqOrderSync.php

    r2303034 r2305894  
    1212
    1313    private $processOutput = [];
     14    public $error_message;
    1415
    1516    private $state = null;
     
    2021        try {
    2122            $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;
    2324            $order_array = [];
    2425            $order_prefix = get_option('zsq_crm_order_prefix');
     
    3738                $tax_id = get_option('zsq_crm_ex_to_woo_tax_map_'.$rate_id);
    3839                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.";
    4042                    $this->sendProcessOutput();
    4143                    return false;
     
    6062                if(is_a($response, WP_Error::class)) {
    6163                    $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);
    6265                    $this->sendProcessOutput();
    6366                    $this->state = false;
     
    6568                }
    6669                $body = json_decode($response['body'], true);
    67                 if (isset($body['data']['output']) && $body['data']['output'] == "Done") {
     70                if (isset($body['message']) && $body['message'] == "Done") {
    6871                    ZsqSlackNotifications::orderComplete($order);
    6972                    $this->state = true;
    7073                    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;
    7178                } 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);
    7381                    $this->state = false;
    7482                }
    7583            } else {
    7684                $this->processOutput[] = "ERROR: API key missing";
     85                $this->error_message = "ERROR: API key missing";
    7786            }
    7887            $this->sendProcessOutput();
    7988            $this->state = false;
    8089        } 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();
    8392            $this->sendProcessOutput();
    8493            $this->state = false;
     
    97106            $product = new WC_Order_Item_Product($item->get_id());
    98107            $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            }
    107121        }
    108122        return $return_array;
  • zsquared-connector-for-zoho-crm/trunk/include/ZsqProductSync.php

    r2303034 r2305894  
    3535                return "Product sync complete";
    3636            }
     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            }
    3743            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.";
    4045            }
    4146        }
     
    6671                    }
    6772                    if ($output['data']['more'] === 'true') {
    68                         return 'more';
     73                        $page++;
     74                        return $this->dailySync($page);
    6975                    }
    7076                    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 {
    7385                    return "No products found! Could not sync at this time";
    7486                }
  • 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; ?>
    102<div class="wrap zspl-wrap">
    113    <div class="zspl-header">
     
    168    <div class="zspl-tab-parent">
    179        <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>
    2214        </div>
    2315    </div>
    2416
    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;"';?>>
    2618        <div class="zspl-conn-info">
    2719            <?php if (strlen(get_option('zsq_crm_api_key')) > 0) : ?>
     
    5547    </div>
    5648
    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;"';?>>
    5850        <form class="zspl-form zspl-sync-settings-form" method="post" action="options-general.php?page=zsq_crm.php&show=inventory">
    5951            <input type="hidden" name="zsq_crm_setting_supdate" value="1"/>
     
    8173
    8274
    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;"';?>>
    8476        <div class="zspl-manual-sync">
    8577            <h2>Replay order submission</h2>
     
    10698    </div>
    10799
    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;"';?>>
    109101        <div class="zspl-tax-mapping">
    110102            <h2>Tax Information Mapping</h2>
  • zsquared-connector-for-zoho-crm/trunk/templates/scripts.php

    r2303034 r2305894  
    22    jQuery(function($) {
    33        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...");
    57            $.ajax({
    68                url: ajaxurl,
     
    1214                    if(data === 'more') {
    1315                        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);
    1617                    }
    1718                    else {
     
    1920                        setTimeout(function(){
    2021                            $("#zsq_crm_manual_sync_message").text("");
    21                         }, 5000);
     22                        }, 10000);
    2223                    }
    2324                }
     
    3233        });
    3334    });
     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    }
    3442</script>
  • zsquared-connector-for-zoho-crm/trunk/zsq-connector-crm.php

    r2303034 r2305894  
    5757    $order = wc_get_order($order_id);
    5858    $obj = new \PCIS\ZSquared\CRM\ZsqOrderSync($order);
     59    if(!$obj->getState()) {
     60        return $obj->error_message;
     61    }
    5962    return $obj->getState();
    6063}
     
    6265function zsq_crm_daily_sync() {
    6366    $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    }
    6571}
    6672
Note: See TracChangeset for help on using the changeset viewer.