Plugin Directory

Changeset 2761181


Ignore:
Timestamp:
07/25/2022 12:53:59 PM (4 years ago)
Author:
invelity
Message:

invelityGlsParcelShopGetShops prevent fatal error

Location:
invelity-gls-parcelshop/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • invelity-gls-parcelshop/trunk/README.txt

    r2547468 r2761181  
    55Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=38W6PN4WHLK32
    66Requires at least: 5.0.0
    7 Tested up to: 5.7.2
    8 Stable tag: 5.3.2
    9 Requires PHP: 7.2
     7Tested up to: 5.8.1
     8Stable tag: 5.8.1
     9Requires PHP: 7.4
    1010WC requires at least: 4.0
    1111License: GPLv2 or later
     
    5050renamed default shipping method
    5151fixed notices
     52
     53= 1.0.2 =
     54invelityGlsParcelShopGetShops prevent fatal error
  • invelity-gls-parcelshop/trunk/includes/WC_Gls_Parcel_Shop_Shipping_Method.php

    r2399263 r2761181  
    44    if (!class_exists('WC_Shipping_Method'))
    55        return;
    6 
    76    if (!class_exists('WC_Gls_Parcel_Shop_Shipping_Method')) {
    87        class WC_Gls_Parcel_Shop_Shipping_Method extends WC_Shipping_Method
  • invelity-gls-parcelshop/trunk/invelity-gls-parcelshop.php

    r2399263 r2761181  
    88Author: Invelity
    99Author URI: https://www.invelity.com
    10 Version: 1.0.1
     10Version: 1.0.2
    1111*/
    1212
  • invelity-gls-parcelshop/trunk/invelityGlsParcelShopShops.php

    r2394221 r2761181  
    44function invelityGlsParcelShopCronAction()
    55{
    6     $log = fopen(__DIR__ . '/log.txt', 'a+');
     6    $log = fopen(__DIR__.'/log.txt', 'a+');
    77    fwrite($log, date('d.m.Y H:i:s'));
    88
    99    $response_data = invelityGlsParcelShopGetShops();
    10     invelityUpdateInvelityGlsParcelShopTable($response_data);
    11     fwrite($log, 'GLS Parcel Shop updated');
    12     fclose($log);
     10    if($response_data){
     11        invelityUpdateInvelityGlsParcelShopTable($response_data);
     12        fwrite($log, 'GLS Parcel Shop updated');
     13        fclose($log);
     14    }else{
     15        fwrite($log, 'GLS Parcel Shop not updated');
     16        fclose($log);
     17    }
     18
    1319}
    1420
    1521function invelityGlsParcelShopFirstInitShops()
    1622{
    17 
    18     if (!$_POST['method_id']) {
     23    if ( ! $_POST['method_id']) {
    1924        return;
    2025    }
    2126    if ($_POST['method_id'] == 'inv_gls_parcel_shop') {
    22 
    2327        $response_data = invelityGlsParcelShopGetShops();
    2428
     
    3236         </div>';
    3337                });
    34 
    3538            }
    3639        }
    37 
    3840    }
    3941}
     
    4143function invelityGlsParcelShopGetShops()
    4244{
     45    $url    = 'https://datarequester.gls-hungary.com/glsconnect/getDropoffPoints.php?ctrcode=sk';
     46    $remote = wp_remote_get($url, ['timeout' => 120, 'method' => 'POST', 'redirection' => 5]);
    4347
    44     $url = 'https://datarequester.gls-hungary.com/glsconnect/getDropoffPoints.php?ctrcode=sk';
    45     $remote = wp_remote_get($url, ['timeout'     => 120,  'method' => 'POST','redirection' =>5]);
    46     $xmlContent = simplexml_load_string(gzdecode($remote['body']));
     48    try {
     49        $xmlContent = simplexml_load_string(gzdecode($remote['body']));
     50        if (isset($xmlContent->Data)) {
     51            return get_object_vars($xmlContent->Data);
     52        } else {
     53            return false;
     54        }
     55    } catch (Exception $e) {
     56        echo $e->getMessage();
    4757
    48     return get_object_vars($xmlContent->Data);
    49 
    50 
     58        return false;
     59    }
    5160}
    5261
    5362function invelityUpdateInvelityGlsParcelShopTable($response_data)
    5463{
    55 
    56 
    5764    global $wpdb;
    5865
    59     $table = $wpdb->prefix . 'inv_gls_parcel_shop';
    60     $wpdb->delete($table, array('country' => 'SK'));
     66    $table = $wpdb->prefix.'inv_gls_parcel_shop';
     67    $wpdb->delete($table, ['country' => 'SK']);
    6168
    6269    foreach ($response_data['DropoffPoint'] as $item) {
    63         $data = array();
     70        $data      = [];
    6471        $openHours = [];
    6572
    6673        $serializedOpenHours = '';
    6774        foreach ($item->Openings as $opening) {
    68 
    6975            foreach ($opening as $open) {
    70                 $toArray = (array)$open;
     76                $toArray     = (array)$open;
    7177                $openHours[] = $toArray;
    7278            }
    7379            $serializedOpenHours = serialize($openHours);
    74 
    7580        }
    7681
    7782
    7883        foreach ($item->attributes() as $a => $b) {
    79 
    80 
    8184            if ($a == 'ID') {
    82                 $data['ID_PARCEL_SHOP'] = (string)$b;
     85                $data['ID_PARCEL_SHOP']  = (string)$b;
    8386                $data['GLS_PARCEL_SHOP'] = (string)$b;
    8487            } elseif ($a == 'Name') {
     
    102105            }
    103106            $data['CP'] = '-';
     107        }
     108
     109        $data['PARCEL_SHOP'] = (string)$data['ADDRESS'].' '.$data['CITY'].' '.$data['ZIP'];
     110        $data['COUNTRY']     = 'SK';
     111        $data['DATA']        = $serializedOpenHours;
    104112
    105113
    106         }
    107 
    108         $data['PARCEL_SHOP'] = (string)$data['ADDRESS'] . ' ' . $data['CITY'] . ' ' . $data['ZIP'];
    109         $data['COUNTRY'] = 'SK';
    110         $data['DATA'] = $serializedOpenHours;
    111 
    112 
    113         $wpdb->insert($wpdb->prefix . 'inv_gls_parcel_shop', $data);
    114 
     114        $wpdb->insert($wpdb->prefix.'inv_gls_parcel_shop', $data);
    115115    }
    116 
    117116}
    118117
     
    120119{
    121120    global $wpdb;
    122     $table_name = $wpdb->prefix . 'inv_gls_parcel_shop';
    123     $result = $wpdb->get_results('SELECT * FROM ' . $table_name . '');
     121    $table_name = $wpdb->prefix.'inv_gls_parcel_shop';
     122    $result     = $wpdb->get_results('SELECT * FROM '.$table_name.'');
     123
    124124    return $result;
    125 
    126 
    127125}
    128126
     
    130128function displayParcelShopData($data)
    131129{
    132 
    133130    $array = unserialize($data);
    134131    $hours = [];
    135132
    136133    foreach ($array as $key => $value) {
    137         $day = $value['@attributes']['Day'];
    138         $open = $value['@attributes']['OpenHours'];
     134        $day   = $value['@attributes']['Day'];
     135        $open  = $value['@attributes']['OpenHours'];
    139136        $break = $value['@attributes']['MidBreak'];
    140137
     
    144141
    145142    $day_map = [
    146         'Monday' => 'Pondelok',
    147         'Tuesday' => 'Utorok',
     143        'Monday'    => 'Pondelok',
     144        'Tuesday'   => 'Utorok',
    148145        'Wednesday' => 'Streda',
    149         'Thursday' => 'Štvrtok',
    150         'Friday' => 'Piatok',
    151         'Saturday' => 'Sobota',
    152         'Sunday' => 'Nedeľa'
     146        'Thursday'  => 'Štvrtok',
     147        'Friday'    => 'Piatok',
     148        'Saturday'  => 'Sobota',
     149        'Sunday'    => 'Nedeľa'
    153150    ];
    154151
    155     $result = array();
     152    $result = [];
    156153
    157154    foreach ($hours as $i => $array2) {
    158 
    159         $translatedKey = array_key_exists($i, $day_map) ?
     155        $translatedKey          = array_key_exists($i, $day_map) ?
    160156            $day_map[$i] :
    161157            $i;
    162158        $result[$translatedKey] = $array2;
    163 
    164159    }
    165160
     
    168163
    169164    return $result;
    170 
    171165}
    172166
    173167function sortResultByDays(array $array, array $orderArray)
    174168{
    175     $ordered = array();
     169    $ordered = [];
    176170    foreach ($orderArray as $key) {
    177171        if (array_key_exists($key, $array)) {
     
    180174        }
    181175    }
     176
    182177    return $ordered + $array;
    183178}
  • invelity-gls-parcelshop/trunk/public/js/invelity-gls-parcel-shop-public.js

    r2547468 r2761181  
    3333            custom.map.mapObject.setView([gps_lat, gps_long], 15);
    3434        }
    35 
    3635
    3736        for (let index = 0; index < vendors.length; index++) {
     
    4241                .on('click', selectShop, vendors[index].id)
    4342                .addTo(custom.map.mapObject);
    44 
    4543        }
    4644
Note: See TracChangeset for help on using the changeset viewer.