Plugin Directory

Changeset 2945241


Ignore:
Timestamp:
07/31/2023 07:24:59 AM (2 years ago)
Author:
bostateam
Message:

fixed refresh status timeout

Location:
bosta-woocommerce
Files:
15 added
3 edited

Legend:

Unmodified
Added
Removed
  • bosta-woocommerce/trunk/bosta-woocommerce.php

    r2925746 r2945241  
    55 * Author: Bosta
    66 * Author URI: https://www.bosta.co/
    7  * Version: 3.0.5
     7 * Version: 3.0.6
    88 * Requires at least: 5.0
    99 * php version 7.0
     
    2424
    2525const BOSTA_ENV_URL = 'https://app.bosta.co/api/v0';
     26const PLUGIN_VERSION = '3.0.6';
    2627const bosta_cache_duration = 86400;
    2728const bosta_country_id_duration = 604800;
     
    5253            'Content-Type' => 'application/json',
    5354            'X-Requested-By' => 'WooCommerce',
     55            'X-Plugin-Version' => PLUGIN_VERSION
    5456        ),
    5557    ));
     
    104106                'X-Requested-By' => 'WooCommerce',
    105107                'Accept-Language' => get_locale() === 'ar' ? 'ar' : 'en',
     108                'X-Plugin-Version' => PLUGIN_VERSION
    106109            ),
    107110        ));
     
    154157                'X-Requested-By' => 'WooCommerce',
    155158                'Accept-Language' => get_locale() === 'ar' ? 'ar' : 'en',
     159                'X-Plugin-Version' => PLUGIN_VERSION
    156160            ),
    157161        ));
     
    572576
    573577add_filter('handle_bulk_actions-edit-shop_order', 'bosta_sync_handle', 10, 3);
    574 function bosta_sync_handle($redirect_to, $action, $order_ids)
     578function bosta_sync_handle($redirect_to, $action, $order_ids, $page_num)
    575579{
    576580    if ($action != 'sync_to_bosta' && $action != 'sync_cash_collection_orders') {
     
    708712                'authorization' => $APIKey,
    709713                'X-Requested-By' => 'WooCommerce',
     714                'X-Plugin-Version' => PLUGIN_VERSION
    710715            ),
    711716            'body' => json_encode($formatedOrders[$i]),
     
    746751        }
    747752    }
    748     $redirect_url = admin_url('edit.php?') . 'post_type=shop_order&paged=1';
     753    $page_num = $page_num ? $page_num : 1;
     754    $redirect_url = admin_url('edit.php?') . 'post_type=shop_order&paged=' . $page_num;
    749755    wp_redirect($redirect_url);
    750756}
     
    758764        ?>
    759765        <div class="alignleft actions custom">
     766                        <?php wp_nonce_field('bosta_send_all_nonce', 'bosta_send_all_nonce_field'); ?>
     767                        <input type="hidden" name="page_num" value="<?php echo esc_attr($_GET['paged']); ?>">
    760768            <button type="submit" name="send_all_orders" style="height:32px;" class="orders-button" value="yes">
    761769                <?php
     
    770778    }
    771779    if ('shop_order' === $typenow && 'edit.php' === $pagenow && isset($_GET['send_all_orders']) && $_GET['send_all_orders'] === 'yes') {
    772         $sendAllOrders = sanitize_text_field($_GET['send_all_orders']);
    773         echo esc_html($sendAllOrders);
    774         $orders = wc_get_orders(array(
    775             'limit' => -1,
    776             'return' => 'ids',
    777         ));
    778         bosta_sync_handle('', 'sync_to_bosta', $orders);
    779     }
     780        // Verify the nonce before processing the form
     781    if (isset($_GET['bosta_send_all_nonce_field']) && check_admin_referer('bosta_send_all_nonce', 'bosta_send_all_nonce_field')) {
     782            $page_num = isset($_GET['page_num']) ? $_GET['page_num'] : 1;
     783            $sendAllOrders = sanitize_text_field($_GET['send_all_orders']);
     784            echo esc_html($sendAllOrders);
     785            $orders = wc_get_orders(array(
     786                    'limit' => 25,
     787                    'paged' => $page_num,
     788                    'return' => 'ids',
     789            ));
     790            bosta_sync_handle('', 'sync_to_bosta', $orders, $page_num);
     791    } else {
     792            echo "Invalid nonce! Something went wrong.";
     793    }
     794}
    780795
    781796}
     
    785800{
    786801    global $pagenow, $typenow;
    787 
    788802    if ('shop_order' === $typenow && 'edit.php' === $pagenow && 'top' === $which) {
    789         ?>
    790         <div class="alignright actions custom">
    791             <button type="submit" name="fetch_status" style="height:32px;" class="danger-button" value="yes"> <?php
    792                 echo __('Refresh status ', 'woocommerce') . '<img src=' . esc_url(plugins_url('assets/images/refreshIcon.png', __FILE__)) . ' alt="Bosta" style="height:17px; width:20px;">'; ?></button>
    793         </div>
    794         <br>
    795         <br>
    796         <?php
     803            ?>
     804            <div class="alignright actions custom">
     805                            <?php wp_nonce_field('bosta_fetch_status_nonce', 'bosta_fetch_status_nonce_field'); ?>
     806                            <input type="hidden" name="page_num" value="<?php echo esc_attr($_GET['paged']); ?>">
     807                            <button type="submit" name="fetch_status" style="height:32px;" class="danger-button" value="yes"> <?php
     808                                    echo __('Refresh status ', 'woocommerce') . '<img src=' . esc_url(plugins_url('assets/images/refreshIcon.png', __FILE__)) . ' alt="Bosta" style="height:17px; width:20px;">'; ?></button>
     809            </div>
     810            <br>
     811            <br>
     812            <?php
    797813    }
    798814    if ('shop_order' === $typenow && 'edit.php' === $pagenow && isset($_GET['fetch_status']) && $_GET['fetch_status'] === 'yes') {
    799         $fetchStatus = sanitize_text_field($_GET['fetch_status']);
    800         echo esc_html($fetchStatus);
    801         $orders = wc_get_orders(array(
    802             'limit' => -1,
    803             'return' => 'ids',
    804         ));
    805         bosta_fetch_latest_status_action('fetch_latest_status', $orders);
    806     }
    807 }
    808 
    809 function bosta_fetch_latest_status_action($action, $order_ids)
     815            // Verify the nonce before processing the form
     816            if (isset($_GET['bosta_fetch_status_nonce_field']) && check_admin_referer('bosta_fetch_status_nonce', 'bosta_fetch_status_nonce_field')) {
     817                    $page_num = isset($_GET['page_num']) ? $_GET['page_num'] : 1;
     818                    $fetchStatus = sanitize_text_field($_GET['fetch_status']);
     819                    echo esc_html($fetchStatus);
     820                    $orders = wc_get_orders(array(
     821                            'limit' => 25,
     822                            'paged' => $page_num,
     823                            'return' => 'ids',
     824                    ));
     825                    bosta_fetch_latest_status_action('fetch_latest_status', $orders, $page_num);
     826            } else {
     827                    echo "Invalid nonce! Something went wrong.";
     828            }
     829    }
     830}
     831
     832function bosta_fetch_latest_status_action($action, $order_ids, $page_num)
    810833{
    811834    if ($action != 'fetch_latest_status') {
     
    841864            'authorization' => $APIKey,
    842865            'X-Requested-By' => 'WooCommerce',
     866            'X-Plugin-Version' => PLUGIN_VERSION
    843867        ),
    844868    ));
     
    871895            }
    872896        }
    873         $redirect_url = admin_url('edit.php?') . 'post_type=shop_order&paged=1';
     897        $page_num = $page_num ? $page_num : 1;
     898        $redirect_url = admin_url('edit.php?') . 'post_type=shop_order&paged=' . $page_num;
    874899        wp_redirect($redirect_url);
     900        exit;
    875901    }
    876902}
     
    937963            'authorization' => $APIKey,
    938964            'X-Requested-By' => 'WooCommerce',
     965            'X-Plugin-Version' => PLUGIN_VERSION
    939966        ),
    940967    ));
     
    10361063            'authorization' => $APIKey,
    10371064            'X-Requested-By' => 'WooCommerce',
     1065            'X-Plugin-Version' => PLUGIN_VERSION
    10381066        ),
    10391067        'body' => json_encode($newOrder),
     
    10731101            'authorization' => $APIKey,
    10741102            'X-Requested-By' => 'WooCommerce',
     1103            'X-Plugin-Version' => PLUGIN_VERSION
    10751104        ),
    10761105    ));
     
    11221151            'authorization' => $APIKey,
    11231152            'X-Requested-By' => 'WooCommerce',
     1153            'X-Plugin-Version' => PLUGIN_VERSION
    11241154        ),
    11251155    ));
     
    12371267                'authorization' => $APIKey,
    12381268                'X-Requested-By' => 'WooCommerce',
     1269                'X-Plugin-Version' => PLUGIN_VERSION
    12391270            ),
    12401271        ));
  • bosta-woocommerce/trunk/components/pickups/pickups.php

    r2925746 r2945241  
    1515            'authorization' => $APIKey,
    1616            'X-Requested-By' => 'WooCommerce',
     17            'X-Plugin-Version' => PLUGIN_VERSION
    1718        ),
    1819    ));
    1920
    20     if (is_wp_error($result)) {
    21         $error_message = $result->get_error_message();
     21    if (is_wp_error($result) || $result['response']['code'] != 200) {
     22        $result = json_decode($result['body']);
     23        $error_message = $result->message;
    2224        echo "Something went wrong: " .esc_html($error_message);
     25        return;
    2326    } else {
    2427        $result = json_decode($result['body'])->data;
     
    3538                'authorization' => $APIKey,
    3639                'X-Requested-By' => 'WooCommerce',
     40                'X-Plugin-Version' => PLUGIN_VERSION
    3741            ),
    3842        ));
     
    8791
    8892              </style>";
    89     if ($_GET['pickupId']) {
     93    if (isset($_GET['pickupId'])) {
    9094
    9195        echo "<p class='create-pickup-title'>Edit Pickup";
     
    129133                         <td>
    130134                          <label>Pickup Date</label>";
    131     if ($pickupEditData->scheduledDate) {
     135    if (isset($pickupEditData) && $pickupEditData->scheduledDate) {
    132136
    133137        $date = date('Y-m-d', strtotime($pickupEditData->scheduledDate));
     
    147151    ?>
    148152    <select required class='data' name='scheduledTimeSlot' >
    149         <option  <?php esc_attr(selectdCheck($pickupEditData->scheduledTimeSlot, '10:00 to 13:00'));?>   value='10:00 to 13:00'>10:00AM to 01:00PM</option>
    150         <option <?php esc_attr(selectdCheck($pickupEditData->scheduledTimeSlot, '13:00 to 16:00'));?>value='13:00 to 16:00' >01:00PM to 04:00PM</option>
     153        <option  <?php if(isset($pickupEditData)){esc_attr(selectdCheck($pickupEditData->scheduledTimeSlot, '10:00 to 13:00'));}?>   value='10:00 to 13:00'>10:00AM to 01:00PM</option>
     154        <option <?php if(isset($pickupEditData)){esc_attr(selectdCheck($pickupEditData->scheduledTimeSlot, '13:00 to 16:00'));}?>value='13:00 to 16:00' >01:00PM to 04:00PM</option>
    151155    </select>
    152156    <?php
     
    155159                  </tbody>
    156160              </table>";
    157     if ($_GET['pickupId']) {
     161    if (isset($_GET['pickupId'])) {
    158162
    159163        echo "<input class='primary-button' type='submit' name='create' value='Edit pickup'/>";
     
    201205    $pickupData->scheduledTimeSlot = $scheduledTimeSlot;
    202206    $pickupData->businessLocationId = $businessLocationId;
    203     if ($_GET['pickupId']) {
     207    if (isset($_GET['pickupId'])) {
    204208        $pickupId = sanitize_text_field($_GET['pickupId']);
    205209        $result = wp_remote_request(BOSTA_ENV_URL . '/pickups/' . esc_html($pickupId), array(
     
    210214                'authorization' => $APIKey,
    211215                'X-Requested-By' => 'WooCommerce',
     216                'X-Plugin-Version' => PLUGIN_VERSION
    212217            ),
    213218            'body' => json_encode($pickupData),
     
    229234                'authorization' => $APIKey,
    230235                'X-Requested-By' => 'WooCommerce',
     236                'X-Plugin-Version' => PLUGIN_VERSION
    231237            ),
    232238            'body' => json_encode($pickupData),
     
    255261    }
    256262
    257     if ('admin.php' === $pagenow && $_GET['page'] = 'bosta-woocommerce-view-pickups' && $_GET['pickupId']) {
     263    if ('admin.php' === $pagenow && $_GET['page'] = 'bosta-woocommerce-view-pickups' && isset($_GET['pickupId'])) {
    258264
    259265        echo "<p class='create-pickup-title'>Pickup Info
     
    271277                'authorization' => $APIKey,
    272278                'X-Requested-By' => 'WooCommerce',
     279                'X-Plugin-Version' => PLUGIN_VERSION
    273280            ),
    274281            'body' => json_encode($pickupData),
     
    352359                        'authorization' => $APIKey,
    353360                        'X-Requested-By' => 'WooCommerce',
     361                        'X-Plugin-Version' => PLUGIN_VERSION
    354362                    ),
    355363                    'body' => json_encode($pickupData),
     
    386394
    387395        }
    388     } else if ('admin.php' === $pagenow && $_GET['page'] = 'bosta-woocommerce-view-pickups' && !$_GET['pickupId']) {
     396    } else if ('admin.php' === $pagenow && $_GET['page'] = 'bosta-woocommerce-view-pickups' && !isset($_GET['pickupId'])) {
    389397        ?>   <button class="primary-button" onClick="document.location.href='admin.php?page=bosta-woocommerce-create-edit-pickup'">Create Pickup</button><?php
    390         if ($_GET['state'] == 'history-pickups') {
     398        if (isset($_GET['state']) && $_GET['state'] == 'history-pickups') {
    391399            ?>
    392400
     
    404412            <?php
    405413        }
    406         if ($_GET['state'] != 'history-pickups' || !isset($_GET['state'])) {
     414        if ((isset($_GET['state']) && $_GET['state'] != 'history-pickups') || !isset($_GET['state'])) {
    407415            $url = BOSTA_ENV_URL . '/pickups/search?state=Requested,Arrived at business,Route Assigned,Picking up,Receiving&pageId=-1';
    408416        } else {
    409417            $url = BOSTA_ENV_URL . '/pickups/search?state=Canceled,Picked up&pageId=-1';
    410418        }
     419
     420        if(!isset($pickupData)) return;
    411421        $result = wp_remote_post($url, array(
    412422            'timeout' => 30,
     
    416426                'authorization' => $APIKey,
    417427                'X-Requested-By' => 'WooCommerce',
     428                'X-Plugin-Version' => PLUGIN_VERSION
    418429            ),
    419430            'body' => json_encode($pickupData),
  • bosta-woocommerce/trunk/readme.txt

    r2925746 r2945241  
    77Requires PHP: 7.0
    88Tested up to: 6.1.1
    9 Stable tag: 3.0.5
     9Stable tag: 3.0.6
    1010WC requires at least: 2.6
    1111WC tested up to: 7.2.2
     
    166166* fixing mapping issues
    167167
    168 = 3.0.3
     168= 3.0.3 =
    169169* fixing no APIKEY and no "Allow New Zones" option issues
    170170
    171 = 3.0.4
     171= 3.0.4 =
    172172* fixing KSA zones
    173173
    174 = 3.0.5
     174= 3.0.5 =
    175175* allow clear caching
    176176* fixing missing districts
     177
     178= 3.0.6 =
     179* Fixed refresh status timeout
     180* Performance enhancements
Note: See TracChangeset for help on using the changeset viewer.