Plugin Directory

Changeset 2738574


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

Handle cities/areas when network is down.

Location:
bosta-woocommerce
Files:
3 edited

Legend:

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

    r2738570 r2738574  
    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
    99 * Tested up to: 5.8.3
     
    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    $url = 'https://app.bosta.co/api/v0/businesses/' . $APIKey. '/info';
     43    $business_result = wp_remote_get($url, array(
    3244        'timeout' => 30,
     45        'method' => 'GET',
     46        'headers' => array(
     47            'Content-Type' => 'application/json',
     48            'X-Requested-By' => 'WooCommerce',
     49        ),
     50    ));
     51    if (is_wp_error($business_result) || $business_result['response']['code'] !== 200) {
     52        $countryId = "60e4482c7cb7d4bc4849c4d5";
     53    } else {
     54        $business = json_decode($business_result['body']);
     55        $countryId = $business->country->_id;
     56    }
     57
     58    $cities_url = 'https://app.bosta.co/api/v0/cities?context=dropoff&countryId=' . $countryId;
     59    // $cities_url = 'https://app.bosta.co/api/v0/cities?context=dropoff';
     60    $result = wp_remote_post($cities_url, array(
     61       'timeout' => 30,
    3362        'method' => 'GET',
    3463        'headers' => array(
     
    3867        ),
    3968    ));
     69
    4070    if (is_wp_error($result)) {
    4171        $error_message = $result->get_error_message();
     
    5686function get_new_states()
    5787{
    58     $states = wp_remote_post('https://app.bosta.co/api/v0/cities/getAllDistricts?context=dropoff', array(
     88    $APIKey = get_option('woocommerce_bosta_settings')['APIKey'];
     89    $url = 'https://app.bosta.co/api/v0/businesses/' . $APIKey. '/info';
     90    $business_result = wp_remote_get($url, array(
     91        'timeout' => 30,
     92        'method' => 'GET',
     93        'headers' => array(
     94            'Content-Type' => 'application/json',
     95            'X-Requested-By' => 'WooCommerce',
     96        ),
     97    ));
     98
     99    if (is_wp_error($business_result) || $business_result['response']['code'] !== 200) {
     100        $countryId = "60e4482c7cb7d4bc4849c4d5";
     101    } else {
     102        $business = json_decode($business_result['body']);
     103        $countryId = $business->country->_id;
     104    }
     105
     106    $states_url = 'https://app.bosta.co/api/v0/cities/getAllDistricts?context=dropoff&countryId=' . $countryId;
     107
     108    $states = wp_remote_post($states_url, array(
    59109        'timeout' => 30,
    60110        'method' => 'GET',
     
    82132    }
    83133}
     134$resultCities = get_new_cities();
    84135$resultStates = get_new_states();
    85 $resultCities = get_new_cities();
    86136
    87137add_filter('woocommerce_checkout_fields', 'bost_override_checkout_city_fields');
     
    119169    global $resultCities;
    120170    $states = $resultStates;
    121     for ($i = 0; $i < count($resultStates); $i++) {
     171    for ($i = 0; $i < count(array($resultStates)); $i++) {
    122172        $resultStates[$i] = __($resultStates[$i], 'wps');
    123173    }
     
    194244    global $resultStates;
    195245    $bostaStates = array();
    196     for ($i = 0; $i < count($resultStates); $i++) {
    197         for ($x = 0; $x < count($resultStates[$i]); $x++) {
     246    for ($i = 0; $i < count(array($resultStates)); $i++) {
     247        for ($x = 0; $x < count(array($resultStates[$i])); $x++) {
    198248            $new_val = $resultStates[$i][$x]->zoneName . ' - ' . $resultStates[$i][$x]->districtName;
    199249            array_push($bostaStates, $new_val);
  • bosta-woocommerce/tags/2.9.1/bosta-woocommerce.php

    r2738570 r2738574  
    4040{
    4141    $APIKey = get_option('woocommerce_bosta_settings')['APIKey'];
    42     // $APIKey = md5('606ead9eaeace1ab89ad10181b68ea391a518f48fb3d52516c0c6ec343e87611');
    4342    $url = 'https://app.bosta.co/api/v0/businesses/' . $APIKey. '/info';
    4443    $business_result = wp_remote_get($url, array(
  • bosta-woocommerce/trunk/bosta-woocommerce.php

    r2738570 r2738574  
    4040{
    4141    $APIKey = get_option('woocommerce_bosta_settings')['APIKey'];
    42     // $APIKey = md5('606ead9eaeace1ab89ad10181b68ea391a518f48fb3d52516c0c6ec343e87611');
    4342    $url = 'https://app.bosta.co/api/v0/businesses/' . $APIKey. '/info';
    4443    $business_result = wp_remote_get($url, array(
Note: See TracChangeset for help on using the changeset viewer.