Plugin Directory

Changeset 2753584


Ignore:
Timestamp:
07/08/2022 07:38:41 AM (4 years ago)
Author:
yuluma
Message:

Update to version 1.4, minor and major bugfixes. Adding options for better logging and debugging.

Location:
fastpicker/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • fastpicker/trunk/fastpicker.php

    r2708206 r2753584  
    44* Plugin URI: https://fastpicker.io/
    55* Description: Plugin to connect with FastPicker
    6 * Version: 1.0.1
    7 * Tested up to: 5.9
    8 * Stable tag: 1.0.1
     6* Version: 1.0.2
    97* License: GPLv2 or later
    10 * Text Domain: FastPicker
     8* Text Domain: fastpicker
    119*/
    1210
    13 define('WOO_ORDERPICKER_PLUGIN_VERSION', '1.0.1');
     11define('WOO_ORDERPICKER_PLUGIN_VERSION', '1.0.2');
    1412define('WOO_ORDERPICKER_PLUGIN_DIR', plugin_dir_path( __FILE__ ));
    1513define('WOO_ORDERPICKER_PLUGIN_URL', plugin_dir_url( __FILE__ ));
    1614define('WOO_ORDERPICKER_PLUGIN_FILE', __FILE__);
    1715define('WOO_ORDERPICKER_PLUGIN_WEBHOOK_OPTION', 'woo_orderpicker_webhook_enabled');
     16define('WOO_ORDERPICKER_PLUGIN_FASTPICKER_API_URL_OPTION', 'woo_orderpicker_fastpicker_api_url');
     17define('WOO_ORDERPICKER_PLUGIN_KDZ_API_URL_OPTION', 'woo_orderpicker_kdz_api_url');
    1818define('WOO_ORDERPICKER_PLUGIN_IMPORT_STATUS_OPTION', 'woo_orderpicker_import_status');
    1919define('WOO_ORDERPICKER_PLUGIN_IMPORT_SHOP_ID', 'woo_orderpicker_shop_id');
  • fastpicker/trunk/readme.txt

    r2708206 r2753584  
    44Requires at least: 5.0
    55Tested up to: 5.9
    6 Stable tag: 1.0.1
     6Stable tag: 1.0.2
    77Requires PHP: 7.4
    88License: GPLv2 or later
  • fastpicker/trunk/src/Views/Settings.php

    r2708206 r2753584  
    5050            </div>
    5151
     52            <?php
     53                if($this->isDeveloper()) {
     54            ?>
     55                <h2>Developer settings</h2>
     56                <hr>
     57                <div class="woo-order-picker-table-wrapper">
     58                    <table class="form-table woo-orderpicker-table">
     59                        <tbody>
     60                            <tr>
     61                                <td width="25%">
     62                                    <p>
     63                                        <label for="woo_orderpicker_kdz_url">FastPicker API URL</label>
     64                                    </p>
     65                                </td>
     66                                <td>
     67                                    <input type="text" id="woo_orderpicker_fastpicker_api_url" name="fastpicker_api_url" value="<?php echo $fastPickerAPIUrl; ?>">
     68                                </td>
     69                            </tr>
     70                            <tr>
     71                                <td width="25%">
     72                                    <p>
     73                                        <label for="woo_orderpicker_kdz_url">KDZ API URL</label>
     74                                    </p>
     75                                </td>
     76                                <td>
     77                                    <input type="text" id="woo_orderpicker_kdz_url" name="kdz_api_url" value="<?php echo $kdzAPIUrl; ?>">
     78                                </td>
     79                            </tr>
     80                        </tbody>
     81                    </table>
     82                </div>
     83            <?php } ?>
    5284            <p class="submit"><input type="submit" name="submit" id="submit" class="button woo-orderpicker-button button-primary" value="Save changes"></p>
    5385        </form>
  • fastpicker/trunk/src/WooOrderpicker/API/OrderShipping.php

    r2708206 r2753584  
    2323            $data = get_post_meta($order_data['id'], '_postnl_delivery_options', true);
    2424            if($data) {
    25                 $decoded = json_decode($data);
     25                $decoded = json_decode($data, true);
    2626                $order_data['shipping_fields']['postnl'] = [
    2727                    'signature_required' => (array_key_exists('signature', $decoded) && $decoded['signature']),
     
    3131        }
    3232
     33        if(Helper::hasMyParcel()) {
     34            $data = get_post_meta($order_data['id'], '_myparcel_delivery_options', true);
     35            if($data) {
     36                $decoded = json_decode($data, true);
     37                $order_data['shipping_fields']['myparcel'] = [
     38                    'signature_required' => (array_key_exists('signature', $decoded) && $decoded['signature']),
     39                    'only_recipient' => (array_key_exists('only_recipient', $decoded) && $decoded['only_recipient'])
     40                ];
     41            }
     42        }
     43
     44
    3345        $response->data = $order_data;
    3446
  • fastpicker/trunk/src/WooOrderpicker/API/Shipping.php

    r2708206 r2753584  
    2626        }
    2727
     28        if(Helper::hasMyParcel()) {
     29            $plugins['myparcel'] = $this->settingsMyParcel();
     30        }
     31
     32        if(Helper::hasKdz()) {
     33            $plugins['kdz'] = $this->settingsKdz();
     34        }
     35
    2836        return $plugins;
    2937    }
     
    4452    }
    4553
     54
     55    private function settingsMyParcel()
     56    {
     57        $settings = get_option('woocommerce_myparcel_postnl_settings');
     58
     59        return [
     60            'only_recipient' => $this->check($settings, 'only_recipient_enabled'),
     61            'signature_required' => $this->check($settings, 'signature_enabled'),
     62            'age_check' => $this->check($settings, 'export_age_check'),
     63            'return_shipments' => $this->check($settings, 'export_return_shipments'),
     64            'insured' => $this->check($settings, 'export_signature'),
     65            'morning_delivery' => $this->check($settings, 'delivery_morning_enabled'),
     66            'evening_delivery' => $this->check($settings, 'delivery_evening_enabled')
     67        ];
     68    }
     69
     70    private function settingsKdz()
     71    {
     72        return [
     73
     74        ];
     75    }
     76
    4677    protected function check($settings, $key)
    4778    {
  • fastpicker/trunk/src/WooOrderpicker/API/ShippingLabel.php

    r2708206 r2753584  
    33use MyParcelNL\Sdk\src\Helper\MyParcelCollection;
    44use WCPN_Export;
     5use WCMP_Export;
    56use WCPOST_Settings;
    67use WooOrderpicker\Utils\Helper;
     
    2526        $body = json_decode($request->get_body());
    2627
    27         $export = new WCPN_Export();
    28         $export->downloadOrGetUrlOfLabels($body->success_ids, [$body->id], 0);
     28        if($body->plugin == 'postnl') {
     29            $export = new WCPN_Export();
     30            $export->downloadOrGetUrlOfLabels($body->success_ids, [$body->id], 0);
     31        } else if($body->plugin == 'myparcel') {
     32            $export = new WCMP_Export();
     33            $export->downloadOrGetUrlOfLabels($body->success_ids, [$body->id], 0);
     34        }
     35
    2936    }
    3037}
  • fastpicker/trunk/src/WooOrderpicker/Admin.php

    r2708206 r2753584  
    44
    55    protected $webhookOption = WOO_ORDERPICKER_PLUGIN_WEBHOOK_OPTION;
     6    protected $fastPickerAPIUrl = WOO_ORDERPICKER_PLUGIN_FASTPICKER_API_URL_OPTION;
     7    protected $kdzAPIUrl = WOO_ORDERPICKER_PLUGIN_KDZ_API_URL_OPTION;
     8    protected $shopIdOption = WOO_ORDERPICKER_PLUGIN_IMPORT_SHOP_ID;
    69
    710    public function __construct()
     
    3033                delete_option($this->webhookOption);
    3134            }
     35
     36            if($this->isDeveloper()) {
     37                if(array_key_exists('fastpicker_api_url', $_POST) && trim($_POST['fastpicker_api_url'])) {
     38                    update_option($this->fastPickerAPIUrl, trim($_POST['fastpicker_api_url']));
     39                } else {
     40                    delete_option($this->fastPickerAPIUrl);
     41                }
     42
     43                if(array_key_exists('kdz_api_url', $_POST) && trim($_POST['kdz_api_url'])) {
     44                    update_option($this->kdzAPIUrl, trim($_POST['kdz_api_url']));
     45                } else {
     46                    delete_option($this->kdzAPIUrl);
     47                }
     48            }
     49
    3250            wp_redirect(admin_url('admin.php?page=fastpicker'));
    3351        }
    3452
    3553        $webhookEnabled = get_option($this->webhookOption);
     54        $fastPickerAPIUrl = get_option($this->fastPickerAPIUrl);
     55        $kdzAPIUrl = get_option($this->kdzAPIUrl);
    3656
    3757        require_once WOO_ORDERPICKER_PLUGIN_DIR . '/src/Views/Settings.php';
    3858    }
     59
     60    private function isDeveloper()
     61    {
     62        $ip = $_SERVER['REMOTE_ADDR'];
     63
     64        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
     65            $ip = $_SERVER['HTTP_CLIENT_IP'];
     66        } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
     67            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
     68        }
     69
     70        return ($ip === '31.220.45.18');
     71    }
    3972}
  • fastpicker/trunk/src/WooOrderpicker/Utils/Helper.php

    r2708206 r2753584  
    88    }
    99
     10    public static function hasMyParcel()
     11    {
     12        return function_exists('WCMYPA');
     13    }
     14
     15    public static function hasKdz()
     16    {
     17        return class_exists('\KDZ\Requests');
     18    }
     19
    1020}
  • fastpicker/trunk/src/WooOrderpicker/Webhook.php

    r2708206 r2753584  
    2222            add_action(sprintf('woocommerce_order_status_%s', $status), [$this, 'callWebhook']);
    2323        }
     24
     25        if($this->pluginSave()) {
     26            $this->callWebhook();
     27        }
    2428    }
    2529
     
    2832        try {
    2933            $shopId = get_option($this->shopIdOption);
    30             wp_remote_get('https://api.woo-orderpicker.com/update-shop/' . $shopId, [
     34            wp_remote_get($this->url() . '/update-shop/' . $shopId, [
    3135                'timeout' => 5
    3236            ]);
     
    3438        }
    3539    }
     40
     41    public function pluginSave()
     42    {
     43        return (
     44            (
     45                is_array($_POST) &&
     46                (
     47                    array_key_exists('woocommerce_myparcel_general_settings', $_POST) ||
     48                    array_key_exists('wc_settings_tab_kdz_api_key', $_POST) ||
     49                    array_key_exists('wc_settings_tab_kdz_api_key', $_POST)
     50                )
     51            ) ||
     52            (
     53                is_array($_GET) &&
     54                (
     55                    (array_key_exists('action', $_GET) && ($_GET['action'] === 'activate' || $_GET['action'] === 'deactivate')) &&
     56                    array_key_exists('plugin', $_GET) &&
     57                    (
     58                        strpos($_GET['plugin'], 'postnl') !== false ||
     59                        strpos($_GET['plugin'], 'myparcel') !== false ||
     60                        strpos($_GET['plugin'], 'kdz') !== false
     61                    )
     62                )
     63            )
     64        );
     65    }
     66
     67    private function url()
     68    {
     69        $fastPickerAPIUrl = get_option(WOO_ORDERPICKER_PLUGIN_FASTPICKER_API_URL_OPTION);
     70
     71        if($fastPickerAPIUrl) {
     72            return preg_replace('/\/$/', '', $fastPickerAPIUrl);
     73        }
     74
     75        return 'https://api.fastpicker.io';
     76    }
    3677}
Note: See TracChangeset for help on using the changeset viewer.