Plugin Directory

Changeset 3110987


Ignore:
Timestamp:
07/02/2024 08:49:51 AM (21 months ago)
Author:
fuvarhu
Message:

add additional shipping methods

Location:
fuvar-hu-api/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • fuvar-hu-api/trunk/fuvarhu.php

    r3051155 r3110987  
    22
    33/*
    4       Plugin Name: Fuvar.HU Api
    5       Plugin URI: https://uzlet.fuvar.hu
    6       description: Fuvar.hu B2B Rendszer api
    7       Version: 1.4.3.1
     4      Plugin Name: Fuvar.HU Szállítási módok
     5      Plugin URI: https://app.fuvar.hu
     6      description: Bővítmény segítségével hozzáadhatod a fuvar.hu által kínált szolgáltatásokat a webshopodhoz
     7      Version: 2
    88      Author: Fuvar.hu
    99      License: GPL2
     
    1414    include('inc/error_handler.php');
    1515    include('inc/variables.php');
    16     include('inc/settings.php');
    1716    include('inc/product.php');
    18     include('inc/single_action.php');
    19     include('inc/group_action.php');
    20     include('inc/export.php');
    2117    include('inc/shipping_method.php');
    22 
    23     function fuvarhu_message_sender(){
    24 
    25         if (isset($_GET["fuvar_message_sender"]) && !empty(sanitize_text_field($_GET['fuvar_message_sender']))){
    26 
    27             $message = sanitize_text_field($_GET['fuvar_message_sender']);
    28 
    29             switch ($message["type"]) {
    30                 case 'updated':
    31                     $fuvar_sender_message ='<div class="updated notice"><p>'.$message["message"].'</p></div>';
    32                     break;
    33 
    34                 case 'error':
    35                     $fuvar_sender_message = '<div class="error notice"><p>'.$message["message"].'</p></div>';
    36                     break;
    37                
    38                 default:
    39                     $fuvar_sender_message = '<div class="update-nag notice"><p>'.$message["message"].'</p></div>';
    40                     break;
    41             }
    42 
    43             echo $fuvar_sender_message;
    44         }
    45 
    46         if(isset($_GET["download_meta_hash"]) && !empty(sanitize_text_field($_GET["download_meta_hash"]))){
    47             echo'<div class="error notice"><p>CSV exportálás sikertelen! Kérlek ellenörizd a beállításokat.</p></div>';
    48             fuvarhu_exportOrdersToCsv(sanitize_text_field($_GET["download_meta_hash"]));
    49         }
    50     }
    51 
    52     add_action( 'admin_notices', 'fuvarhu_message_sender');
    53 
    54     function fuvarhu_register_awaiting_shipment_order_status() {
    55         register_post_status( 'wc-awaiting-shipment', array(
    56             'label'                     => 'Átadva a fuvar.hu-nak',
    57             'public'                    => true,
    58             'exclude_from_search'       => false,
    59             'show_in_admin_all_list'    => true,
    60             'show_in_admin_status_list' => true,
    61             'label_count'               => _n_noop( 'Átadva a fuvar.hu-nak', 'Átadva a fuvar.hu-nak' )
    62         ) );
    63     }
    64     add_action( 'init', 'fuvarhu_register_awaiting_shipment_order_status' );
    65 
    66     function fuvarhu_add_awaiting_shipment_to_order_statuses( $order_statuses ) {
    67  
    68         $new_order_statuses = array();
    69      
    70         // add new order status after processing
    71         foreach ( $order_statuses as $key => $status ) {
    72      
    73             $new_order_statuses[ $key ] = $status;
    74      
    75             if ( 'wc-processing' === $key ) {
    76                 $new_order_statuses['wc-awaiting-shipment'] = 'Átadva a fuvar.hu-nak';
    77             }
    78         }
    79      
    80         return $new_order_statuses;
    81     }
    82     add_filter( 'wc_order_statuses', 'fuvarhu_add_awaiting_shipment_to_order_statuses' );
    83 
    84 
    8518}
    8619
  • fuvar-hu-api/trunk/inc/shipping_method.php

    r3051056 r3110987  
    33add_filter( 'woocommerce_shipping_methods', 'fuvarhu_registerfuvarhu_method' );
    44function fuvarhu_registerfuvarhu_method( $methods ) {
    5     $methods[ 'fuvarhu_hazhozdpd' ] = 'WC_Shipping_fuvarhu_HAZ_DPD';
    65    $methods[ 'fuvarhu_hazhoz' ] = 'WC_Shipping_fuvarhu_HAZ';
     6    $methods[ 'fuvarhu_hazhoz_dpd' ] = 'WC_Shipping_fuvarhu_HAZ_DPD';
    77    $methods[ 'fuvarhu_pop' ] = 'WC_Shipping_fuvarhu_POP';
    88    $methods[ 'fuvarhu_pos' ] = 'WC_Shipping_fuvarhu_POS';
    99    $methods[ 'fuvarhu_csp' ] = 'WC_Shipping_fuvarhu_CSP';
     10    $methods[ 'fuvarhu_aut_dpd' ] = 'WC_Shipping_fuvarhu_AUT_DPD';
     11    $methods[ 'fuvarhu_aut_pck' ] = 'WC_Shipping_fuvarhu_AUT_PCK';
     12
    1013    return $methods;
    1114}
     
    2124
    2225    if( $value = $order->get_meta( '_store_pickup_data' ) ) {
    23         echo'<p><strong>' . __( 'MPL Pont megnevezése', "woocommerce" ) . ':<br></strong> '.$value.'</p>';
     26        echo'<p><strong>' . __( 'Átvételi pont', "woocommerce" ) . ':<br></strong> '.$value.'</p>';
    2427    }
    2528    echo'</div>';
     
    3538        if( $key ==  'order_status' ){
    3639            $reordered_columns['fuvarhu-shipping'] = __( 'Szállítási mód','fuvarhu');
    37             $reordered_columns['fuvarhu-mpl-point'] = __( 'MPL Pont','fuvarhu');
     40            $reordered_columns['fuvarhu-mpl-point'] = __( 'Átvételi Pont','fuvarhu');
    3841        }
    3942    }
     
    156159    }
    157160
     161    if(!class_exists("WC_Shipping_fuvarhu_AUT_DPD")){
     162            class WC_Shipping_fuvarhu_AUT_DPD extends WC_Shipping_Method {
     163                public function __construct( $instance_id = 0 ) {
     164                    $this->id                    = 'fuvarhu_aut_dpd';
     165                    $this->instance_id           = absint( $instance_id );
     166                    $this->method_title          = __( 'Fuvar.hu - Automata & Csomagpont (DPD)' );
     167                    $this->method_description    = __( 'DPD Automata & Csomagpont a Fuvar.hu szerződött partnere által' );
     168                    $this->supports              = array(
     169                        'shipping-zones',
     170                        'instance-settings',
     171                    );
     172                    $this->instance_form_fields = array(
     173                        'enabled' => array(
     174                            'title'         => __( 'Engedélyezve' ),
     175                            'type'          => 'checkbox',
     176                            'label'         => __( 'Szállítási mód engedélyezése' ),
     177                            'default'       => 'yes',
     178                        ),
     179                        'shipping_fee' => array(
     180                            'title'         => __( 'Szállítás összege' ),
     181                            'type'          => 'number',
     182                            'description'   => __( 'A vevőre terhelt szállítási díj' ),
     183                            'default'       => __( '0' ),
     184                            'desc_tip'      => true
     185                        )
     186                    );
     187                    $this->enabled              = $this->get_option( 'enabled' );
     188                    $this->title                = 'Automata & Csomagpont (DPD)';
     189
     190                    add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
     191                }
     192
     193                public function calculate_shipping( $package = array() ) {
     194                    $this->add_rate( array(
     195                        'id'    => $this->id . $this->instance_id,
     196                        'label' => $this->title,
     197                        'cost'  => $this->get_option('shipping_fee'),
     198                    ) );
     199                }
     200        }
     201    }
     202
     203    if(!class_exists("WC_Shipping_fuvarhu_AUT_PCK")){
     204            class WC_Shipping_fuvarhu_AUT_PCK extends WC_Shipping_Method {
     205                public function __construct( $instance_id = 0 ) {
     206                    $this->id                    = 'fuvarhu_aut_pck';
     207                    $this->instance_id           = absint( $instance_id );
     208                    $this->method_title          = __( 'Fuvar.hu - Automata & Csomagpont (Packeta)' );
     209                    $this->method_description    = __( 'Packeta Automata & Csomagpont a Fuvar.hu szerződött partnere által' );
     210                    $this->supports              = array(
     211                        'shipping-zones',
     212                        'instance-settings',
     213                    );
     214                    $this->instance_form_fields = array(
     215                        'enabled' => array(
     216                            'title'         => __( 'Engedélyezve' ),
     217                            'type'          => 'checkbox',
     218                            'label'         => __( 'Szállítási mód engedélyezése' ),
     219                            'default'       => 'yes',
     220                        ),
     221                        'shipping_fee' => array(
     222                            'title'         => __( 'Szállítás összege' ),
     223                            'type'          => 'number',
     224                            'description'   => __( 'A vevőre terhelt szállítási díj' ),
     225                            'default'       => __( '0' ),
     226                            'desc_tip'      => true
     227                        )
     228                    );
     229                    $this->enabled              = $this->get_option( 'enabled' );
     230                    $this->title                = 'Automata & Csomagpont (Packeta)';
     231
     232                    add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
     233                }
     234
     235                public function calculate_shipping( $package = array() ) {
     236                    $this->add_rate( array(
     237                        'id'    => $this->id . $this->instance_id,
     238                        'label' => $this->title,
     239                        'cost'  => $this->get_option('shipping_fee'),
     240                    ) );
     241                }
     242        }
     243    }
     244
    158245
    159246    if(!class_exists("WC_Shipping_fuvarhu_POP")){
     
    184271                    );
    185272                    $this->enabled              = $this->get_option( 'enabled' );
    186                     $this->title                = 'MPL PostaPontra (MOL, Coop) a Fuvarral';
     273                    $this->title                = 'PostaPont (MOL, Coop)';
    187274
    188275                    add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
     
    226313                    );
    227314                    $this->enabled              = $this->get_option( 'enabled' );
    228                     $this->title                = 'Postára kézbesítés a Fuvarral';
     315                    $this->title                = 'Postára kézbesítés (MPL)';
    229316
    230317                    add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
     
    268355                    );
    269356                    $this->enabled              = $this->get_option( 'enabled' );
    270                     $this->title                = 'MPL Csomagautomatába a Fuvarral';
     357                    $this->title                = 'Automata (MPL)';
    271358
    272359                    add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
     
    289376function fuvarhu_store_pickup_field_update_order_meta( $order_id ) {
    290377    if ( isset($_POST['pickup_store']) && !empty(sanitize_text_field($_POST['pickup_store'])) ){
    291         $store_pickup = "<h3>Felvételi pont:</h3><br>".sanitize_text_field($_POST['pickup_store']);
     378        $store_pickup = "<h3>Átvételi pont:</h3><br>".sanitize_text_field($_POST['pickup_store']);
    292379        $order = wc_get_order( $order_id );
    293380        $order->update_meta_data( '_store_pickup_data', sanitize_text_field($_POST['pickup_store']) );
     
    316403    }
    317404
    318     if($selected != "haz" && ($selected == "pos" || $selected == "csp" || $selected = "pop")){
     405    if(strpos($chosen_method_id,"fuvarhu_aut_dpd") !== false){
     406        $selected = "aut";
     407    }
     408
     409    if(strpos($chosen_method_id,"fuvarhu_aut_pck") !== false){
     410        $selected = "aut";
     411    }
     412
     413    if($selected != "haz" && ($selected == "pos" || $selected == "csp" || $selected = "pop" || $selected = "aut")){
    319414        if(!isset($_POST['pickup_store']) || empty($_POST['pickup_store'])){
    320415            wc_add_notice( __( 'Kérlek, válassz kézbesítési pontot!' ), 'error' );
     
    327422function fuvarhu_pickup_store_custom_field( $method, $index ) {
    328423
    329     if( is_cart() || !in_array($method->method_id, ["fuvarhu_csp","fuvarhu_pop","fuvarhu_pos"]) )
     424    if( is_cart() || !in_array($method->method_id, ["fuvarhu_csp","fuvarhu_pop","fuvarhu_pos","fuvarhu_aut_dpd","fuvarhu_aut_pck"]) )
    330425        return;
    331426
     
    335430    $options = [];
    336431    $selected = "";
     432    $provider = "";
     433    $show_for = "";
    337434
    338435    if(strpos($chosen_method_id,"fuvarhu_csp") !== false){
    339436        $selected = "csp";
     437        $provider = "mpl";
     438        $show_for = "fuvarhu_csp";
    340439    }
    341440
    342441    if(strpos($chosen_method_id,"fuvarhu_pop") !== false){
    343442        $selected = "pop";
     443        $provider = "mpl";
     444        $show_for = "fuvarhu_pop";
    344445    }
    345446
    346447    if(strpos($chosen_method_id,"fuvarhu_pos") !== false){
    347448        $selected = "pos";
    348     }
    349 
    350     if($method->method_id != "fuvarhu_".$selected){
     449        $provider = "mpl";
     450        $show_for = "fuvarhu_pos";
     451    }
     452
     453    if(strpos($chosen_method_id,"fuvarhu_aut_dpd") !== false){
     454        $selected = "aut";
     455        $provider = "dpd";
     456        $show_for = "fuvarhu_aut_dpd";
     457    }
     458
     459    if(strpos($chosen_method_id,"fuvarhu_aut_pck") !== false){
     460        $selected = "aut";
     461        $provider = "pck";
     462        $show_for = "fuvarhu_aut_pck";
     463    }
     464
     465    if($method->method_id != $show_for){
    351466        return;
    352467    }
    353468
    354     $response   = wp_remote_get("https://uzlet.fuvar.hu/dev/export/mplpoints?type=".$selected);
     469    $response   = wp_remote_post("https://backend.fuvar.hu/graphql/public/",[
     470        'headers' => [
     471            'Accept: application/json',
     472            'Content-Type: application/json'
     473        ],
     474        'body' => ['query' => 'query getMplPoints($type: String! $search: String     $provider: String) {collectorpoints(limit: 0, page: 1, type: $type, search: $search, provider: $provider) {data {id point_id title zip city address}}}', 'variables' => [
     475            'type' => $selected,
     476            'search' => '',
     477            'provider' => $provider
     478        ]]
     479    ]);
     480
     481    $pointserror = '<div class="wrapper-pickup_store" style="margin-top:8px; margin-bottom:16px">A pontok lekérése során hiba lépett fel kérlek próbáld meg késöbb</div><input type="hidden" value="" name="pickup_store">';
     482
    355483    if(wp_remote_retrieve_response_code($response) != 200){
    356         echo '<div class="wrapper-pickup_store" style="margin-top:8px; margin-bottom:16px">Sajnos a pontok betöltése sikertelen volt.</div><input type="hidden" value="" name="pickup_store">';
     484        echo $pointserror;
     485        return;
    357486    }else{
    358487        $mpl_points = wp_remote_retrieve_body( $response );
    359488        $points = json_decode($mpl_points,true);
     489       
     490        if(!isset($points['data']) || !isset($points['data']['collectorpoints']) || !isset($points['data']['collectorpoints']['data'])){
     491            echo $pointserror;
     492            return;
     493        }
     494
     495        $points = $points['data']['collectorpoints']['data'];
     496
    360497        foreach ($points as $key => $value) {
    361498            $options[$value["title"]] = $value["city"]." - ".$value["title"]." (".$value["address"].")";
  • fuvar-hu-api/trunk/inc/variables.php

    r2596076 r3110987  
    1313    ]);
    1414
    15     define('fuvarhu_plugin_setting_maps_api_key', 'fuvarhu_plugin_setting_maps_api_key');
    16 
    1715    define('fuvarhu_plugin_other_setting_weight_measure', 'fuvarhu_plugin_other_setting_weight_measure');
    1816
  • fuvar-hu-api/trunk/readme.txt

    r3051155 r3110987  
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1010
    11 A bővítmény segítségével a Fuvar.hu rendeléskezelő felületén használt struktúrában töltheted le a megrendeléseidet.
     11A mővítmény segítségével hozzáadhatod a fuvar.hu által kínált szolgáltatásokat a webshopodhoz.
    1212
    1313== Description ==
    1414
    15 A bővítmény segítségével a Fuvar.hu rendeléskezelő felületén használt struktúrában töltheted le a megrendeléseidet, melyeket aztán egyszerűen feltölthetsz a felületre.A Plugin működéséhez szükséged van egy Fuvar.hu üzleti fiókra. Ha még nem rendelkezel ilyennel, itt tudsz regisztrálni:
     15Bővítmény segítségével hozzáadhatod a fuvar.hu által kínált szolgáltatásokat a webshopodhoz .A Plugin működéséhez szükséged van egy Fuvar.hu üzleti fiókra. Ha még nem rendelkezel ilyennel, itt tudsz regisztrálni:
    1616https://fuvar.hu/business
    1717
Note: See TracChangeset for help on using the changeset viewer.