Plugin Directory

Changeset 2738570


Ignore:
Timestamp:
06/07/2022 11:16:10 AM (4 years ago)
Author:
bostateam
Message:

Handle cities/areas when network is down.

Location:
bosta-woocommerce
Files:
15 added
4 edited

Legend:

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

    r2704571 r2738570  
    77 * Version: 2.9
    88 * Requires at least: 5.0
    9  * Tested up to: 5.7
     9 * Tested up to: 5.8.3
    1010 * WC requires at least: 2.6
    1111 * WC tested up to: 4.4.1
  • bosta-woocommerce/readme.txt

    r2704571 r2738570  
    66Requires at least: 5.0
    77Requires PHP: 7.0
    8 Tested up to: 5.7
    9 Stable tag: 2.9
     8Tested up to: 5.8.3
     9Stable tag: 2.9.1
    1010WC requires at least: 2.6
    1111WC tested up to: 4.4.1
     
    126126= 2.9 =
    127127* Update cities/areas in KSA.
     128
     129= 2.9.1 =
     130* Handle cities/areas when network is down.
  • bosta-woocommerce/trunk/bosta-woocommerce.php

    r2704571 r2738570  
    55 * Author: Bosta
    66 * Author URI: https://www.bosta.co/
    7  * Version: 2.9
     7 * Version: 2.9.1
    88 * Requires at least: 5.0
    9  * Tested up to: 5.7
     9 * Tested up to: 5.8.3
    1010 * WC requires at least: 2.6
    1111 * WC tested up to: 4.4.1
     
    2121
    2222add_action('admin_print_styles', 'bosta_stylesheet');
     23
     24function console_log($output, $with_script_tags = true) {
     25    $js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) .
     26');';
     27    if ($with_script_tags) {
     28        $js_code = '<script>' . $js_code . '</script>';
     29    }
     30    echo $js_code;
     31}
     32
    2333function bosta_stylesheet()
    2434{
     
    2939function get_new_cities()
    3040{
    31     $result = wp_remote_post('https://app.bosta.co/api/v0/cities?context=dropoff', array(
     41    $APIKey = get_option('woocommerce_bosta_settings')['APIKey'];
     42    // $APIKey = md5('606ead9eaeace1ab89ad10181b68ea391a518f48fb3d52516c0c6ec343e87611');
     43    $url = 'https://app.bosta.co/api/v0/businesses/' . $APIKey. '/info';
     44    $business_result = wp_remote_get($url, array(
    3245        'timeout' => 30,
     46        'method' => 'GET',
     47        'headers' => array(
     48            'Content-Type' => 'application/json',
     49            'X-Requested-By' => 'WooCommerce',
     50        ),
     51    ));
     52    if (is_wp_error($business_result) || $business_result['response']['code'] !== 200) {
     53        $countryId = "60e4482c7cb7d4bc4849c4d5";
     54    } else {
     55        $business = json_decode($business_result['body']);
     56        $countryId = $business->country->_id;
     57    }
     58
     59    $cities_url = 'https://app.bosta.co/api/v0/cities?context=dropoff&countryId=' . $countryId;
     60    // $cities_url = 'https://app.bosta.co/api/v0/cities?context=dropoff';
     61    $result = wp_remote_post($cities_url, array(
     62       'timeout' => 30,
    3363        'method' => 'GET',
    3464        'headers' => array(
     
    3868        ),
    3969    ));
     70
    4071    if (is_wp_error($result)) {
    4172        $error_message = $result->get_error_message();
     
    5687function get_new_states()
    5788{
    58     $states = wp_remote_post('https://app.bosta.co/api/v0/cities/getAllDistricts?context=dropoff', array(
     89    $APIKey = get_option('woocommerce_bosta_settings')['APIKey'];
     90    $url = 'https://app.bosta.co/api/v0/businesses/' . $APIKey. '/info';
     91    $business_result = wp_remote_get($url, array(
     92        'timeout' => 30,
     93        'method' => 'GET',
     94        'headers' => array(
     95            'Content-Type' => 'application/json',
     96            'X-Requested-By' => 'WooCommerce',
     97        ),
     98    ));
     99
     100    if (is_wp_error($business_result) || $business_result['response']['code'] !== 200) {
     101        $countryId = "60e4482c7cb7d4bc4849c4d5";
     102    } else {
     103        $business = json_decode($business_result['body']);
     104        $countryId = $business->country->_id;
     105    }
     106
     107    $states_url = 'https://app.bosta.co/api/v0/cities/getAllDistricts?context=dropoff&countryId=' . $countryId;
     108
     109    $states = wp_remote_post($states_url, array(
    59110        'timeout' => 30,
    60111        'method' => 'GET',
     
    82133    }
    83134}
     135$resultCities = get_new_cities();
    84136$resultStates = get_new_states();
    85 $resultCities = get_new_cities();
    86137
    87138add_filter('woocommerce_checkout_fields', 'bost_override_checkout_city_fields');
     
    119170    global $resultCities;
    120171    $states = $resultStates;
    121     for ($i = 0; $i < count($resultStates); $i++) {
     172    for ($i = 0; $i < count(array($resultStates)); $i++) {
    122173        $resultStates[$i] = __($resultStates[$i], 'wps');
    123174    }
     
    194245    global $resultStates;
    195246    $bostaStates = array();
    196     for ($i = 0; $i < count($resultStates); $i++) {
    197         for ($x = 0; $x < count($resultStates[$i]); $x++) {
     247    for ($i = 0; $i < count(array($resultStates)); $i++) {
     248        for ($x = 0; $x < count(array($resultStates[$i])); $x++) {
    198249            $new_val = $resultStates[$i][$x]->zoneName . ' - ' . $resultStates[$i][$x]->districtName;
    199250            array_push($bostaStates, $new_val);
  • bosta-woocommerce/trunk/readme.txt

    r2704571 r2738570  
    66Requires at least: 5.0
    77Requires PHP: 7.0
    8 Tested up to: 5.7
    9 Stable tag: 2.9
     8Tested up to: 5.8.3
     9Stable tag: 2.9.1
    1010WC requires at least: 2.6
    1111WC tested up to: 4.4.1
     
    126126= 2.9 =
    127127* Update cities/areas in KSA.
     128
     129= 2.9.1 =
     130* Handle cities/areas when network is down.
Note: See TracChangeset for help on using the changeset viewer.