Plugin Directory

Changeset 1895913


Ignore:
Timestamp:
06/20/2018 03:21:51 PM (8 years ago)
Author:
digitalissimo
Message:

1.3.1

  • Controllo per verificare la correttezza dei dati inseriti e la visibilità dei messaggi di errore.
  • Eliminati i messaggi di warning in php
Location:
fermopoint-for-woocommerce/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • fermopoint-for-woocommerce/trunk/README.txt

    r1811711 r1895913  
    55Tags: woocommerce, fermopoint, shipping
    66
    7 Version: 1.3
     7Version: 1.3.1
    88
    99Requires at least: 3.0.1
    1010
    11 Tested up to:4.7.4
     11Tested up to:4.9.6
    1212
    13 Stable tag: 4.7.4
     13Stable tag: 4.9.6
    1414
    1515License: GPLv2 or later
     
    142142* Migliorata la gestione della creazione Ticket
    143143
     144= 1.3.1 =
     145
     146* Controllo  per verificare la correttezza dei dati inseriti e la visibilità dei messaggi di errore.
     147* Eliminati i messaggi di warning in php
     148
  • fermopoint-for-woocommerce/trunk/admin/class-fermopoint-admin.php

    r1811711 r1895913  
    450450
    451451                       
    452 
    453452                        $this->enabled            = "yes"; // This can be added as an setting but for this example its forced enabled
    454453
     
    501500                        $this->cost = $this->get_option( 'cost' );
    502501
     502
     503
    503504                        $this->enabled = $this->get_option( 'enabled' );
    504 
     505                       
     506                       
    505507                        $this->visibile = $this->get_option( 'FERMOPOINT_MODALITAVISIBILE' );
    506508
  • fermopoint-for-woocommerce/trunk/admin/includes/settings-fermopoint.php

    r1811711 r1895913  
    11<?php
     2
     3
    24
    35
     
    57if ( ! defined( 'ABSPATH' ) ) {
    68
     9
    710    exit;
     11
    812
    913}
     
    1519
    1620
     21
     22
     23
     24
    1725/**
     26
    1827
    1928 * Settings for flat rate shipping.
    2029
     30
    2131 */
     32
    2233
    2334$settings = array(
    2435
     36
    2537        'enabled' => array(
     38
    2639
    2740            'title'         => __( 'Enable/Disable', 'fermopoint' ),
    2841
     42
    2943            'type'          => 'checkbox',
     44
    3045
    3146            'label'         => __( 'Enable Fermo!Point', 'fermopoint' ),
    3247
    33             'default'       => 'yes'
     48
     49            'default'       => 'false'
     50
    3451
    3552        ),
    3653
     54
    3755   
     56
    3857
    3958        'title' => array(
    4059
     60
    4161            'title' => __( 'Title', 'fermopoint' ),
     62
    4263
    4364            'type' => 'text',
    4465
     66
    4567            'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
     68
    4669
    4770            'default' => __( 'Fermo!Point', 'fermopoint' )
    4871
     72
    4973        ),
     74
    5075
    5176       
    5277
     78
    5379        'description' => array(
     80
    5481
    5582            'title' => __( 'Description', 'fermopoint' ),
    5683
     84
    5785            'type' => 'textarea',
     86
    5887
    5988            'description' => __( 'This controls the description which the user sees during checkout.', 'fermopoint' ),
    6089
     90
    6191            'default' => __("Ricevi il tuo acquisto in uno dei punti di ritiro Fermo!Point (www.fermopoint.it)", 'fermopoint')
     92
    6293
    6394        ),
    6495
     96
    6597       
     98
    6699
    67100        'cost' => array(
    68101
     102
    69103            'title'         => __( 'Cost per order', 'fermopoint' ),
     104
    70105
    71106            'type'          => 'price',
    72107
     108
    73109       
     110
    74111
    75112            'description'   => __( 'Enter a cost (excluding tax) per order, e.g. 5.00. Default is 0.', 'fermopoint' ),
    76113
     114
    77115            'default'       => '0',
     116
    78117
    79118            'desc_tip'      => true,
    80119
     120
    81121            'placeholder'   => wc_format_localized_price( 2.50 ),
     122
    82123
    83124        ),
    84125
    85    
    86126
    87127   
    88128
     129
    89130   
     131
     132
     133   
     134
    90135
    91136       
    92137
     138
    93139   
     140
    94141
    95142);
     
    99146
    100147
     148
     149
     150
    101151return $settings;
    102152
     153
  • fermopoint-for-woocommerce/trunk/admin/includes/settings-general-fermopoint.php

    r1811711 r1895913  
    11<?php
    22
     3
     4
    35add_action( 'admin_menu', 'FERMOPOINT_add_admin_menu' );
    46
     7
     8
    59add_action( 'admin_init', 'FERMOPOINT_settings_init' );
    610
     11
     12
    713 add_action( 'admin_init', 'fermopoint_mysettings' );
    814
     
    1117
    1218
     19
     20
     21
     22
     23
     24
    1325function fermopoint_add_admin_menu(  ) {
    1426
    1527
    16 
    1728    add_submenu_page( 'woocommerce', 'Fermo!Point', 'Fermo!Point', 'manage_options', 'fermopoint_settings_init', 'fermopoint_options_page' );
    1829
     30
     31
    1932}
    2033
     
    2336
    2437
     38
     39
     40
     41
     42
     43
    2544function fermopoint_settings_init(  ) {
    2645
    27    
     46
     47
     48   
     49
     50
    2851
    2952    add_option( 'FERMOPOINT_ACCOUNT_ID', "" );
    3053
     54
     55
    3156    add_option( 'FERMOPOINT_ACCOUNT_SECRET', "" ); 
    3257
     58
     59
    3360    add_option( 'FERMOPOINT_ACCOUNT_NICKNAME', "" );
    3461
     62
     63
    3564    add_option( 'FERMOPOINT_ACCOUNT_BORNDATE', "" );   
    3665
    37    
    38 
    39     /*RECUPERO I DATI DELLA VERSIONE 1.0 del PLUGIN*/
    40 
    41     $shippings_wc = new WC_Shipping ;
    42 
    43     $shippings = $shippings_wc->load_shipping_methods();
    44 
    45    
    46 
    47     $fermopoint = $shippings["Fermo!Point"];
    48 
    49     if (isset($fermopoint)){
    50 
    51         $fermopoint_settings = $fermopoint->settings;
     66
     67
     68   
     69
     70
     71
     72    add_settings_section(
     73
     74
     75
     76        'fermopoint_pluginPage_section',
     77
     78
     79
     80        __( 'Configura Fermo!Point', 'fermopoint' ),
     81
     82
     83
     84        'fermopoint_settings_section_callback',
     85
     86
     87
     88        'pluginPage'
     89
     90
     91
     92        );
     93
     94
     95
     96
     97
     98
     99
     100
     101
     102
     103
     104    add_settings_field(
     105
     106
     107
     108        'fermopoint_sandbox', '',
     109
     110
     111
     112        'fermopoint_hidden_field_0_render',
     113
     114
     115
     116        'pluginPage',
     117
     118
     119
     120        'fermopoint_pluginPage_section'
     121
     122
     123
     124    );
     125
     126
     127
     128
     129
     130
     131
     132    add_settings_field(
     133
     134
     135
     136        'FERMOPOINT_ACCOUNT_ID',
     137
     138
     139
     140            __( 'Client ID', 'fermopoint' ) . ":" . __( 'The user code received at the time of the service', 'fermopoint' ),
     141
     142
     143
     144        'fermopoint_text_field_2_render',
     145
     146
     147
     148        'pluginPage',
     149
     150
     151
     152        'fermopoint_pluginPage_section'
     153
     154
     155
     156    );
     157
     158
     159
     160
     161
     162
     163
     164    add_settings_field(
     165
     166
     167
     168        'FERMOPOINT_ACCOUNT_SECRET',
     169
     170
     171
     172        __( 'Client Secret', 'fermopoint' ) . ":" . __( 'The password received when registering for the service', 'fermopoint' ),
     173
     174
     175
     176        'fermopoint_text_field_3_render',
     177
     178
     179
     180        'pluginPage',
     181
     182
     183
     184        'fermopoint_pluginPage_section'
     185
     186
     187
     188    );
     189
     190
     191
     192   
     193
     194
     195
     196   
     197
     198
     199
     200        add_settings_field(
     201
     202
     203
     204        'FERMOPOINT_ACCOUNT_NICKNAME',
     205
     206
     207
     208        __( 'Nickname merchant', 'fermopoint' ),
     209
     210
     211
     212        'fermopoint_text_field_4_render',
     213
     214
     215
     216        'pluginPage',
     217
     218
     219
     220        'fermopoint_pluginPage_section'
     221
     222
     223
     224    );
     225
     226
     227
     228   
     229
     230
     231
     232   
     233
     234
     235
     236    add_settings_field(
     237
     238
     239
     240        'FERMOPOINT_ACCOUNT_BORNDATE',
     241
     242
     243
     244            __( 'Date', 'fermopoint' ),
     245
     246
     247
     248        'fermopoint_text_field_5_render',
     249
     250
     251
     252        'pluginPage',
     253
     254
     255
     256        'fermopoint_pluginPage_section'
     257
     258
     259
     260    );
     261
     262
     263
     264   
     265
     266
     267
     268   
     269
     270
     271
     272   
     273
     274
     275
     276   
     277
     278
     279
     280
     281
     282
     283
     284
     285
     286
     287
     288}
     289
     290
     291
     292
     293
     294
     295
     296function fermopoint_hidden_field_0_render(  ) {
     297
     298
     299
     300   
     301
     302
     303
     304    $options = get_option( 'fermopoint_sandbox' );
     305
     306
     307
     308    ?>
     309
     310
     311
     312    <input type='hidden' name='fermopoint_sandbox' value='<?php echo $options; ?>' />
     313
     314
     315
     316    <?php
     317
     318
     319
     320
     321
     322
     323
     324}
     325
     326
     327
     328
     329
     330
     331
     332
     333
     334
     335
     336
     337
     338
     339
     340function fermopoint_text_field_2_render(  ) {
     341
     342
     343
     344   
     345
     346
     347
     348    $options = get_option( 'FERMOPOINT_ACCOUNT_ID' );
     349
     350
     351
     352    ?>
     353
     354
     355
     356    <input type='text' name='FERMOPOINT_ACCOUNT_ID' value='<?php echo $options; ?>' style='width: 40%' />
     357
     358
     359
     360    <?php
     361
     362
     363
     364
     365
     366
     367
     368}
     369
     370
     371
     372
     373
     374
     375
     376
     377
     378
     379
     380function fermopoint_text_field_3_render(  ) {
     381
     382
     383
     384
     385
     386
     387
     388    $options = get_option( 'FERMOPOINT_ACCOUNT_SECRET' );
     389
     390
     391
     392    ?>
     393
     394
     395
     396    <input type='text' name='FERMOPOINT_ACCOUNT_SECRET' value='<?php echo $options; ?>'  style='width: 40%' />
     397
     398
     399
     400    <?php
     401
     402
     403
     404
     405
     406
     407
     408}
     409
     410
     411
     412
     413
     414
     415
     416
     417
     418
     419
     420function fermopoint_text_field_4_render(  ) {
     421
     422
     423
     424
     425
     426
     427
     428    $options = get_option( 'FERMOPOINT_ACCOUNT_NICKNAME' );
     429
     430
     431
     432    ?>
     433
     434
     435
     436    <input type='text' name='FERMOPOINT_ACCOUNT_NICKNAME' value='<?php echo $options; ?>'  style='width: 40%' />
     437
     438
     439
     440    <?php
     441
     442
     443
     444
     445
     446
     447
     448}
     449
     450
     451
     452
     453
     454
     455
     456function fermopoint_text_field_5_render(  ) {
     457
     458
     459
     460
     461
     462
     463
     464    $options = get_option( 'FERMOPOINT_ACCOUNT_BORNDATE' );
     465
     466
     467
     468    ?>
     469
     470
     471
     472    <input type='text' name='FERMOPOINT_ACCOUNT_BORNDATE' value='<?php echo $options; ?>'  style='width: 40%' />
     473
     474
     475
     476    <?php
     477
     478
     479
     480
     481
     482
     483
     484}
     485
     486
     487
     488
     489
     490
     491
     492function fermopoint_settings_section_callback(  ) {
     493
     494
     495
     496
     497
     498
     499
     500    echo "<a href='https://www.fermopoint.it/contatti-ecommerce' target='new'>" . __( 'Iscriviti a Fermo!Point se non lo hai ancora fatto', 'fermopoint' ) . "</a>  |  <a href='https://www.fermopoint.it/business/vantaggi-ecommerce' target='new'>" . __( 'Scropri i vantaggi', 'fermopoint' ) . "</a>";
     501
     502
     503
     504
     505
     506
     507
     508}
     509
     510
     511
     512
     513
     514
     515
     516
     517
     518
     519
     520function fermopoint_mysettings() { // whitelist options
     521
     522
     523
     524  register_setting( 'pluginPage', 'fermopoint_sandbox' );
     525
     526
     527
     528  register_setting( 'pluginPage', 'FERMOPOINT_MODALITAVISIBILE' );
     529
     530
     531
     532  register_setting( 'pluginPage', 'FERMOPOINT_ACCOUNT_ID' );
     533
     534
     535
     536  register_setting( 'pluginPage', 'FERMOPOINT_ACCOUNT_SECRET' );
     537
     538
     539
     540 
     541
     542
     543
     544  register_setting( 'pluginPage', 'FERMOPOINT_ACCOUNT_NICKNAME' );
     545
     546
     547
     548  register_setting( 'pluginPage', 'FERMOPOINT_ACCOUNT_BORNDATE' );
     549
     550
     551
     552 
     553
     554
     555
     556}
     557
     558
     559
     560
     561
     562
     563
     564
     565
     566
     567
     568function fermopoint_options_page(  ) {
     569
     570
     571
     572
     573
     574
     575
     576    $array =  array("nickname"=> get_option("FERMOPOINT_ACCOUNT_NICKNAME"), "born_date"=>  get_option("FERMOPOINT_ACCOUNT_BORNDATE"). "T00:00:00");
     577
     578
     579
     580    $verify= callfermopointcurl("/public/users/check",$array);
     581
     582
     583
     584
     585
     586
     587
     588
     589
     590
     591
     592
     593
     594
     595
     596   
     597
     598
     599
     600    echo "<a href='https://www.fermopoint.it/' target='new'><img src='https://www.fermopoint.it/Content/images/logo/logo.png'/></a>";
     601
     602
     603
     604    echo "<hr/>";
     605
     606
     607
     608   
     609
     610
     611
     612    if (!$verify){?>
     613
     614
     615
     616        <div class="notice notice-error">
     617
     618
     619
     620        <h2>FERMO!POINT: Attenzione! L'utente è inesistente, verificare correttamente i dati, il metodo di pagamento Fermo!Point non funzionerà sul sito</h2>
     621
     622
     623
     624        </div>
     625
     626
     627
     628       
     629
     630
     631
     632    <?php
     633   
     634           
     635
     636
     637
     638   
     639
     640
     641
     642    } ?>
     643
     644
     645
     646    <form action='options.php' method='post'>
     647
     648
     649
     650        <?php
     651
     652
     653
     654        settings_fields( 'pluginPage' );
     655
     656
     657
     658        do_settings_sections( 'pluginPage' );
     659
     660
     661
     662        submit_button();
     663
     664
     665
     666        ?>
     667
     668
     669
     670    </form>
     671
     672
     673
     674   
     675
     676
     677
     678    <?php
     679
     680
     681
     682   
     683
     684
    52685
    53686       
    54687
    55         //Check if is correct
     688
    56689
    57690       
    58691
    59         $account_id = get_option("FERMOPOINT_ACCOUNT_ID");
    60 
    61         $account_secret = get_option("FERMOPOINT_ACCOUNT_SECRET");
     692
     693
     694        if ($verify){
     695
     696
     697
     698   
     699
     700
     701
     702            echo "<hr/><h2>Riepilogo ticket Fermo!Point</h2>";
     703
     704
     705
     706           
     707
     708            global $wpdb;
     709
     710            $return_array = array();
     711
     712            $total_discount = 0;
    62713
    63714       
    64715
    65         $request = json_encode(array(
    66 
    67             "client_id" => $account_id,
    68 
    69             "auth_token" =>$auth_token,
    70 
    71             "ts" => $ts,
    72 
    73         ));
    74 
    75         $ret= callfermopointcurl("/merchant",$request);
     716            $query = "SELECT
     717
     718                p.ID AS order_id
     719
     720                FROM
     721
     722                {$wpdb->prefix}posts AS p
     723
     724                INNER JOIN {$wpdb->prefix}woocommerce_order_items AS woi ON p.ID = woi.order_id
     725
     726                WHERE
     727
     728                p.post_type = 'shop_order' AND
     729
     730                p.post_status IN ('" . implode("','", array_keys(wc_get_order_statuses())) . "')";
    76731
    77732       
    78733
    79         //if ()
     734            $orders = $wpdb->get_results($query);
    80735
    81736       
    82737
    83         $account_id = $fermopoint_settings["FERMOPOINT_ACCOUNT_ID"];
    84 
    85         $account_secret = $fermopoint_settings["FERMOPOINT_ACCOUNT_SECRET"];
    86 
    87         if (get_option( 'FERMOPOINT_ACCOUNT_ID' )=="") update_option( 'FERMOPOINT_ACCOUNT_ID', $account_id  );
    88 
     738            if (!empty($orders)) {
     739
     740                $dp = ( isset($filter['dp']) ? intval($filter['dp']) : 2 );
     741
     742                //looping throught all the order_id
     743
     744                foreach ($orders as $key => $order) {
     745
     746                    $order_id = $order->order_id;
     747
     748                    //getting order object
     749
     750                    $objOrder = wc_get_order($order_id);
     751
     752                    $idpoint = get_post_custom_values("idpoint",$order_id);
     753
     754                    $fermopoint_ticketid = get_post_custom_values("fermopoint_ticketid",$order_id);
     755
     756                   
     757
     758                    if ($idpoint && ((!$fermopoint_ticketid))){
     759
     760                        $fermopointorder[$order_id] = $idpoint[0];
     761
     762                    }
     763
     764                   
     765
     766                    if ($idpoint && (($fermopoint_ticketid==""))){
     767
     768                        $fermopointorder[$order_id] = $idpoint[0];
     769
     770                    }
     771
     772                   
     773
     774                }
     775
     776        //        echo '<pre>';
     777
     778        //        print_r($return_array);
     779
     780            }
     781
     782            //var_dump($fermopointorder);
    89783       
    90 
    91         if (get_option( 'FERMOPOINT_ACCOUNT_SECRET' )=="")  update_option( 'FERMOPOINT_ACCOUNT_SECRET', $account_secret ); 
    92 
    93784       
     785            if (isset($fermopointorder)){
     786                foreach ($fermopointorder as $order_id=>$idpoint){
     787   
     788                   
     789   
     790                   
     791   
     792                    $order = new WC_Order($order_id);
     793   
     794                    $email=$order->get_billing_email();
     795   
     796                    $phone_number=$order->get_billing_phone();
     797   
     798                   
     799   
     800                    $customer = new WC_Customer ($order->user_id);
     801   
     802   
     803   
     804   
     805   
     806                    $account_id = get_option("FERMOPOINT_ACCOUNT_ID");
     807   
     808   
     809   
     810                    $account_secret = get_option("FERMOPOINT_ACCOUNT_SECRET");
     811   
     812   
     813   
     814                   
     815   
     816   
     817   
     818                    $nickname = get_option("FERMOPOINT_ACCOUNT_NICKNAME");
     819   
     820   
     821   
     822                    $borndate = get_option("FERMOPOINT_ACCOUNT_BORNDATE");
     823   
     824   
     825   
     826                   
     827   
     828   
     829   
     830                    $sandbox =get_option('fermopoint_sandbox');
     831   
     832   
     833   
     834                   
     835   
     836   
     837   
     838                    $url = API_SERVER_PRODUCTION . "/booking/book";
     839   
     840   
     841   
     842                   
     843   
     844   
     845   
     846                   
     847   
     848   
     849   
     850                   
     851   
     852                   
     853   
     854                   
     855   
     856   
     857   
     858                    $request = json_encode(array(
     859   
     860   
     861   
     862                        "client_id" => $account_id,
     863   
     864   
     865   
     866                        "auth_token" =>$auth_token,
     867   
     868   
     869   
     870                        "ts" => $ts,
     871   
     872   
     873   
     874                        "data" => array(
     875   
     876   
     877   
     878                            "point_id" => $idpoint,
     879   
     880   
     881   
     882                            "merchant_id" =>$order_id,
     883   
     884   
     885   
     886                            "merchant_notes" => 'Ordine web n.' . $order_id,
     887   
     888   
     889   
     890                            "existing_user" => true,
     891   
     892   
     893   
     894                            "nickname" =>trim($nickname),
     895   
     896   
     897   
     898                            "born_date" =>trim($borndate) . "T00:00:00",
     899   
     900   
     901   
     902                            "email" => $email,
     903   
     904   
     905   
     906                            "phone_number" =>$phone_number
     907   
     908   
     909   
     910                        )
     911   
     912   
     913   
     914                    ));
     915   
     916   
     917   
     918               
     919   
     920   
     921   
     922                    $httpHeader = array(
     923   
     924   
     925   
     926                    "Content-Type: application/json; charset=\"utf-8\"",
     927   
     928   
     929   
     930                    "Accept: text/json"
     931   
     932   
     933   
     934                    );
     935   
     936   
     937   
     938                   
     939   
     940   
     941   
     942                    $ch = curl_init();
     943   
     944   
     945   
     946                    $url = API_SERVER_PRODUCTION . "/booking/book";
     947   
     948   
     949   
     950                    curl_setopt($ch, CURLOPT_URL, $url );
     951   
     952   
     953   
     954                   
     955   
     956   
     957   
     958                    curl_setopt($ch, CURLOPT_POST, 1);
     959   
     960   
     961   
     962                    curl_setopt($ch, CURLOPT_POSTFIELDS, $request );
     963   
     964   
     965   
     966                   
     967   
     968   
     969   
     970                    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     971   
     972   
     973   
     974                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     975   
     976   
     977   
     978                    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);rl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
     979   
     980   
     981   
     982                    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
     983   
     984   
     985   
     986   
     987   
     988                   
     989   
     990   
     991   
     992                   
     993   
     994   
     995   
     996                   
     997   
     998   
     999   
     1000                    $result = curl_exec($ch);
     1001   
     1002   
     1003   
     1004                    $info = curl_getinfo($ch);
     1005   
     1006   
     1007   
     1008                    if (!isset($info['http_code'])) {
     1009   
     1010   
     1011   
     1012                        $info['http_code'] = '';
     1013   
     1014   
     1015   
     1016                    }
     1017   
     1018   
     1019   
     1020                   
     1021   
     1022   
     1023   
     1024           
     1025   
     1026   
     1027   
     1028                    if (curl_errno($ch)) {
     1029   
     1030   
     1031   
     1032                        $result= array(
     1033   
     1034   
     1035   
     1036                        'http_code' => $info['http_code'],
     1037   
     1038   
     1039   
     1040                        'status' => 'ERROR1',
     1041   
     1042   
     1043   
     1044                        'errno' => $curl_errno,
     1045   
     1046   
     1047   
     1048                        'error' => $curl_error,
     1049   
     1050   
     1051   
     1052                        'result' => NULL
     1053   
     1054   
     1055   
     1056                        );
     1057   
     1058   
     1059   
     1060                    } else {
     1061   
     1062   
     1063   
     1064                        $ret = json_decode($result);
     1065   
     1066   
     1067   
     1068                       
     1069   
     1070   
     1071   
     1072                        $ticketid = $ret->ticketId;
     1073   
     1074   
     1075   
     1076                        update_post_meta( $order_id, 'fermopoint_ticketid', $ticketid );
     1077   
     1078   
     1079   
     1080                        update_post_meta( $order_id, 'fermopoint_state',"NEW");
     1081   
     1082   
     1083   
     1084                        update_post_meta( $order_id, '_shipping_first_name',trim($nickname));
     1085   
     1086   
     1087   
     1088                        echo 'Ordine web n.' . $order_id . ") id POINT " . $idpoint . "  TICKET GENERATO:" . $ticketid;
     1089   
     1090                        $order= callfermopointcurl("/booking/approve/" . $ticketid , "base");
     1091   
     1092                        echo "<br/>";
     1093   
     1094                       
     1095   
     1096                    }   
     1097   
     1098                   
     1099   
     1100               
     1101   
     1102                }
     1103
     1104            }
     1105
     1106            $ch3 = curl_init();
     1107
     1108
     1109
     1110
     1111            $orders = callfermopointcurl("/orders/last?take=100","base");
     1112
     1113
     1114
     1115            $ret = callfermopointcurl("/merchant","base");
     1116
     1117    ?>
    941118
    951119       
    961120
    97         $nickname = $fermopoint_settings["FERMOPOINT_ACCOUNT_NICKNAME"];
    98 
    99         $borndate = $fermopoint_settings["FERMOPOINT_ACCOUNT_BORNDATE"];
    100 
    101         if (get_option( 'FERMOPOINT_ACCOUNT_NICKNAME' )=="") update_option( 'FERMOPOINT_ACCOUNT_NICKNAME', $nickname  );
     1121       
     1122
     1123       
     1124
     1125           
     1126
     1127           
     1128
     1129
     1130
     1131            <h2>Crediti restati: <?php echo $ret->credits;?></h2>
     1132
     1133
     1134
     1135            <h2>Ordini totali: <?php echo $ret->orders_count;?></h2>
     1136
     1137
     1138
     1139           
     1140
     1141
     1142
     1143           
     1144
     1145
     1146
     1147            <table>
     1148
     1149
     1150
     1151           
     1152
     1153
     1154
     1155            <?php
     1156
     1157
     1158
     1159
     1160
     1161           
     1162
     1163
     1164
     1165                foreach ($orders as $order){
     1166
     1167
     1168
     1169           
     1170
     1171
     1172
     1173                    ?><hr/>
     1174
     1175                    <h3><?php echo $order->ticketId;?></h3>
     1176
     1177                    <table>
     1178
     1179                   
     1180
     1181                    <tr>
     1182
     1183
     1184
     1185                    <td><b><?php echo $order->merchant_id;?></b></td>
     1186
     1187                    <td><?php echo $order->merchant_notes;?></td>
     1188
     1189                    <td><?php echo $order->email;?></td>
     1190
     1191                    <td><?php echo $order->phone_number;?></td>
     1192
     1193                   
     1194
     1195                   
     1196
     1197                   
     1198
     1199                    </tr>
     1200
     1201                   
     1202
     1203                    <?php foreach ($order->notes as $note){?>
     1204
     1205                        <tr>
     1206
     1207                            <td><?php echo $note->date;?></td>
     1208
     1209                            <td><?php echo $note->note;?></td>
     1210
     1211                        </tr>
     1212
     1213                    <?php }?>
     1214
     1215                   
     1216
     1217<?php  //$cancellaticket = /booking/cancel/{ticketId} ?>
     1218
     1219
     1220
     1221                    </table>
     1222
     1223                    <?php
     1224
     1225
     1226
     1227           
     1228
     1229
     1230
     1231                }
     1232
     1233
     1234
     1235           
     1236
     1237
     1238
     1239            ?>
     1240
     1241
     1242
     1243           
     1244
     1245
    1021246
    1031247       
    1041248
    105         if (get_option( 'FERMOPOINT_ACCOUNT_BORNDATE' )=="")  update_option( 'FERMOPOINT_ACCOUNT_BORNDATE', $borndate );   
    106 
    107        
    108 
    109     }
    110 
    111     /**/
    112 
    113    
    114 
    115     register_setting( 'fermopointoption', 'fermopoint_settings' );
    116 
    117    
    118 
    119     add_settings_section(
    120 
    121         'fermopoint_pluginPage_section',
    122 
    123         __( 'Configura Fermo!Point', 'fermopoint' ),
    124 
    125         'fermopoint_settings_section_callback',
    126 
    127         'pluginPage'
    128 
    129         );
    130 
    131 
    132 
    133 
    134 
    135     add_settings_field(
    136 
    137         'fermopoint_sandbox', '',
    138 
    139         'fermopoint_hidden_field_0_render',
    140 
    141         'pluginPage',
    142 
    143         'fermopoint_pluginPage_section'
    144 
    145     );
    146 
    147 
    148 
    149     add_settings_field(
    150 
    151         'FERMOPOINT_ACCOUNT_ID',
    152 
    153             __( 'Client ID', 'fermopoint' ) . ":" . __( 'The user code received at the time of the service', 'fermopoint' ),
    154 
    155         'fermopoint_text_field_2_render',
    156 
    157         'pluginPage',
    158 
    159         'fermopoint_pluginPage_section'
    160 
    161     );
    162 
    163 
    164 
    165     add_settings_field(
    166 
    167         'FERMOPOINT_ACCOUNT_SECRET',
    168 
    169         __( 'Client Secret', 'fermopoint' ) . ":" . __( 'The password received when registering for the service', 'fermopoint' ),
    170 
    171         'fermopoint_text_field_3_render',
    172 
    173         'pluginPage',
    174 
    175         'fermopoint_pluginPage_section'
    176 
    177     );
    178 
    179    
    180 
    181    
    182 
    183         add_settings_field(
    184 
    185         'FERMOPOINT_ACCOUNT_NICKNAME',
    186 
    187         __( 'Nickname merchant', 'fermopoint' ),
    188 
    189         'fermopoint_text_field_4_render',
    190 
    191         'pluginPage',
    192 
    193         'fermopoint_pluginPage_section'
    194 
    195     );
    196 
    197    
    198 
    199    
    200 
    201     add_settings_field(
    202 
    203         'FERMOPOINT_ACCOUNT_BORNDATE',
    204 
    205             __( 'Date', 'fermopoint' ),
    206 
    207         'fermopoint_text_field_5_render',
    208 
    209         'pluginPage',
    210 
    211         'fermopoint_pluginPage_section'
    212 
    213     );
    214 
    215    
    216 
    217    
    218 
    219    
    220 
    221    
     1249
     1250
     1251        <?php
     1252
     1253
     1254
     1255        }
     1256
     1257
    2221258
    2231259
     
    2291265
    2301266
    231 function fermopoint_hidden_field_0_render(  ) {
    232 
    233    
    234 
    235     $options = get_option( 'fermopoint_sandbox' );
    236 
    237     ?>
    238 
    239     <input type='hidden' name='fermopoint_sandbox' value='<?php echo $options; ?>' />
    240 
    241     <?php
    242 
    243 
    244 
    245 }
    246 
    247 
    248 
    249 
    250 
    251 
    252 
    253 function fermopoint_text_field_2_render(  ) {
    254 
    255    
    256 
    257     $options = get_option( 'FERMOPOINT_ACCOUNT_ID' );
    258 
    259     ?>
    260 
    261     <input type='text' name='FERMOPOINT_ACCOUNT_ID' value='<?php echo $options; ?>' style='width: 40%' />
    262 
    263     <?php
    264 
    265 
    266 
    267 }
    268 
    269 
    270 
    271 
    272 
    273 function fermopoint_text_field_3_render(  ) {
    274 
    275 
    276 
    277     $options = get_option( 'FERMOPOINT_ACCOUNT_SECRET' );
    278 
    279     ?>
    280 
    281     <input type='text' name='FERMOPOINT_ACCOUNT_SECRET' value='<?php echo $options; ?>'  style='width: 40%' />
    282 
    283     <?php
    284 
    285 
    286 
    287 }
    288 
    289 
    290 
    291 
    292 
    293 function fermopoint_text_field_4_render(  ) {
    294 
    295 
    296 
    297     $options = get_option( 'FERMOPOINT_ACCOUNT_NICKNAME' );
    298 
    299     ?>
    300 
    301     <input type='text' name='FERMOPOINT_ACCOUNT_NICKNAME' value='<?php echo $options; ?>'  style='width: 40%' />
    302 
    303     <?php
    304 
    305 
    306 
    307 }
    308 
    309 
    310 
    311 function fermopoint_text_field_5_render(  ) {
    312 
    313 
    314 
    315     $options = get_option( 'FERMOPOINT_ACCOUNT_BORNDATE' );
    316 
    317     ?>
    318 
    319     <input type='text' name='FERMOPOINT_ACCOUNT_BORNDATE' value='<?php echo $options; ?>'  style='width: 40%' />
    320 
    321     <?php
    322 
    323 
    324 
    325 }
    326 
    327 
    328 
    329 function fermopoint_settings_section_callback(  ) {
    330 
    331 
    332 
    333     echo "<a href='https://www.fermopoint.it/contatti-ecommerce' target='new'>" . __( 'Iscriviti a Fermo!Point se non lo hai ancora fatto', 'fermopoint' ) . "</a>  |  <a href='https://www.fermopoint.it/business/vantaggi-ecommerce' target='new'>" . __( 'Scropri i vantaggi', 'fermopoint' ) . "</a>";
    334 
    335 
    336 
    337 }
    338 
    339 
    340 
    341 
    342 
    343 function fermopoint_mysettings() { // whitelist options
    344 
    345   register_setting( 'pluginPage', 'fermopoint_sandbox' );
    346 
    347   register_setting( 'pluginPage', 'FERMOPOINT_MODALITAVISIBILE' );
    348 
    349   register_setting( 'pluginPage', 'FERMOPOINT_ACCOUNT_ID' );
    350 
    351   register_setting( 'pluginPage', 'FERMOPOINT_ACCOUNT_SECRET' );
    352 
    353  
    354 
    355   register_setting( 'pluginPage', 'FERMOPOINT_ACCOUNT_NICKNAME' );
    356 
    357   register_setting( 'pluginPage', 'FERMOPOINT_ACCOUNT_BORNDATE' );
    358 
    359  
    360 
    361 }
    362 
    363 
    364 
    365 
    366 
    367 function fermopoint_options_page(  ) {
    368 
    369 
    370 
    371     $array =  array("nickname"=> get_option("FERMOPOINT_ACCOUNT_NICKNAME"), "born_date"=>  get_option("FERMOPOINT_ACCOUNT_BORNDATE"). "T00:00:00");
    372 
    373     $verify= callfermopointcurl("/public/users/check",$array);
    374 
    375 
    376 
    377 
    378 
    379 
    380 
    381    
    382 
    383     echo "<a href='https://www.fermopoint.it/' target='new'><img src='https://www.fermopoint.it/Content/images/logo/logo.png'/></a>";
    384 
    385     echo "<hr/>";
    386 
    387    
    388 
    389     if (!$verify){?>
    390 
    391         <div class="notice notice-error is-dismissible">
    392 
    393         <p>FERMO!POINT: Attenzione! L'utente è inesistente, verificare correttamente i dati</p>
    394 
    395         </div>
    396 
    397        
    398 
    399     <?php
    400 
    401    
    402 
    403     } ?>
    404 
    405     <form action='options.php' method='post'>
    406 
    407         <?php
    408 
    409         settings_fields( 'pluginPage' );
    410 
    411         do_settings_sections( 'pluginPage' );
    412 
    413         submit_button();
    414 
    415         ?>
    416 
    417     </form>
    418 
    419    
    420 
    421     <?php
    422 
    423    
    424 
    425        
    426 
    427        
    428 
    429         if ($verify){
    430 
    431    
    432 
    433             echo "<hr/><h2>Riepilogo ticket Fermo!Point</h2>";
    434 
    435            
    436             global $wpdb;
    437             $return_array = array();
    438             $total_discount = 0;
    439        
    440             $query = "SELECT
    441                 p.ID AS order_id
    442                 FROM
    443                 {$wpdb->prefix}posts AS p
    444                 INNER JOIN {$wpdb->prefix}woocommerce_order_items AS woi ON p.ID = woi.order_id
    445                 WHERE
    446                 p.post_type = 'shop_order' AND
    447                 p.post_status IN ('" . implode("','", array_keys(wc_get_order_statuses())) . "')";
    448        
    449             $orders = $wpdb->get_results($query);
    450        
    451             if (!empty($orders)) {
    452                 $dp = ( isset($filter['dp']) ? intval($filter['dp']) : 2 );
    453                 //looping throught all the order_id
    454                 foreach ($orders as $key => $order) {
    455                     $order_id = $order->order_id;
    456                     //getting order object
    457                     $objOrder = wc_get_order($order_id);
    458                     $idpoint = get_post_custom_values("idpoint",$order_id);
    459                     $fermopoint_ticketid = get_post_custom_values("fermopoint_ticketid",$order_id);
    460                    
    461                     if ($idpoint && ((!$fermopoint_ticketid))){
    462                         $fermopointorder[$order_id] = $idpoint[0];
    463                     }
    464                    
    465                     if ($idpoint && (($fermopoint_ticketid==""))){
    466                         $fermopointorder[$order_id] = $idpoint[0];
    467                     }
    468                    
    469                 }
    470         //        echo '<pre>';
    471         //        print_r($return_array);
    472             }
    473             //var_dump($fermopointorder);
    474             foreach ($fermopointorder as $order_id=>$idpoint){
    475                
    476                
    477                 $order = new WC_Order($order_id);
    478                 $email=$order->get_billing_email();
    479                 $phone_number=$order->get_billing_phone();
    480                
    481                 $customer = new WC_Customer ($order->user_id);
    482 
    483 
    484                 $account_id = get_option("FERMOPOINT_ACCOUNT_ID");
    485 
    486                 $account_secret = get_option("FERMOPOINT_ACCOUNT_SECRET");
    487 
    488                
    489 
    490                 $nickname = get_option("FERMOPOINT_ACCOUNT_NICKNAME");
    491 
    492                 $borndate = get_option("FERMOPOINT_ACCOUNT_BORNDATE");
    493 
    494                
    495 
    496                 $sandbox =get_option('fermopoint_sandbox');
    497 
    498                
    499 
    500                 $url = API_SERVER_PRODUCTION . "/booking/book";
    501 
    502                
    503 
    504                 $ts = gmdate('Y-m-d\TH:i:s.u\Z');
    505 
    506                
    507                
    508                 $auth_token = hash_hmac("sha256", (string) $ts, (string) $account_id . $account_secret, false);
    509 
    510                 $request = json_encode(array(
    511 
    512                     "client_id" => $account_id,
    513 
    514                     "auth_token" =>$auth_token,
    515 
    516                     "ts" => $ts,
    517 
    518                     "data" => array(
    519 
    520                         "point_id" => $idpoint,
    521 
    522                         "merchant_id" =>$order_id,
    523 
    524                         "merchant_notes" => 'Ordine web n.' . $order_id,
    525 
    526                         "existing_user" => true,
    527 
    528                         "nickname" =>trim($nickname),
    529 
    530                         "born_date" =>trim($borndate) . "T00:00:00",
    531 
    532                         "email" => $email,
    533 
    534                         "phone_number" =>$phone_number
    535 
    536                     )
    537 
    538                 ));
    539 
    540            
    541 
    542                 $httpHeader = array(
    543 
    544                 "Content-Type: application/json; charset=\"utf-8\"",
    545 
    546                 "Accept: text/json"
    547 
    548                 );
    549 
    550                
    551 
    552                 $ch = curl_init();
    553 
    554                 $url = API_SERVER_PRODUCTION . "/booking/book";
    555 
    556                 curl_setopt($ch, CURLOPT_URL, $url );
    557 
    558                
    559 
    560                 curl_setopt($ch, CURLOPT_POST, 1);
    561 
    562                 curl_setopt($ch, CURLOPT_POSTFIELDS, $request );
    563 
    564                
    565 
    566                 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    567 
    568                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    569 
    570                 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);rl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
    571 
    572                 curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
    573 
    574 
    575                
    576 
    577                
    578 
    579                
    580 
    581                 $result = curl_exec($ch);
    582 
    583                 $info = curl_getinfo($ch);
    584 
    585                 if (!isset($info['http_code'])) {
    586 
    587                     $info['http_code'] = '';
    588 
    589                 }
    590 
    591                
    592 
    593        
    594 
    595                 if (curl_errno($ch)) {
    596 
    597                     $result= array(
    598 
    599                     'http_code' => $info['http_code'],
    600 
    601                     'status' => 'ERROR1',
    602 
    603                     'errno' => $curl_errno,
    604 
    605                     'error' => $curl_error,
    606 
    607                     'result' => NULL
    608 
    609                     );
    610 
    611                 } else {
    612 
    613                     $ret = json_decode($result);
    614 
    615                    
    616 
    617                     $ticketid = $ret->ticketId;
    618 
    619                     update_post_meta( $order_id, 'fermopoint_ticketid', $ticketid );
    620 
    621                     update_post_meta( $order_id, 'fermopoint_state',"NEW");
    622 
    623                     update_post_meta( $order_id, '_shipping_first_name',trim($nickname));
    624 
    625                     echo 'Ordine web n.' . $order_id . ") id POINT " . $idpoint . "  TICKET GENERATO:" . $ticketid;
    626                     $order= callfermopointcurl("/booking/approve/" . $ticketid , "base");
    627                     echo "<br/>";
    628                    
    629                 }   
    630                
    631            
    632             }
    633            
    634             $ch3 = curl_init();
    635 
    636             $fermopoint = $shippings["Fermo!Point"];
    637 
    638 
    639 
    640             $orders = callfermopointcurl("/orders/last?take=100","base");
    641 
    642             $ret = callfermopointcurl("/merchant","base");
    643     ?>
    644        
    645        
    646        
    647            
    648            
    649 
    650             <h2>Crediti restati: <?php echo $ret->credits;?></h2>
    651 
    652             <h2>Ordini totali: <?php echo $ret->orders_count;?></h2>
    653 
    654            
    655 
    656            
    657 
    658             <table>
    659 
    660            
    661 
    662             <?php
    663 
    664 
    665            
    666 
    667                 foreach ($orders as $order){
    668 
    669            
    670 
    671                     ?><hr/>
    672                     <h3><?php echo $order->ticketId;?></h3>
    673                     <table>
    674                    
    675                     <tr>
    676 
    677                     <td><b><?php echo $order->merchant_id;?></b></td>
    678                     <td><?php echo $order->merchant_notes;?></td>
    679                     <td><?php echo $order->email;?></td>
    680                     <td><?php echo $order->phone_number;?></td>
    681                    
    682                    
    683                    
    684                     </tr>
    685                    
    686                     <?php foreach ($order->notes as $note){?>
    687                         <tr>
    688                             <td><?php echo $note->date;?></td>
    689                             <td><?php echo $note->note;?></td>
    690                         </tr>
    691                     <?php }?>
    692                    
    693 <?php  //$cancellaticket = /booking/cancel/{ticketId} ?>
    694 
    695                     </table>
    696                     <?php
    697 
    698            
    699 
    700                 }
    701 
    702            
    703 
    704             ?>
    705 
    706            
    707 
    708        
    709 
    710         <?php
    711 
    712         }
    713 
    714 
    715 
    716 }
     1267
     1268
     1269
    7171270
    7181271
  • fermopoint-for-woocommerce/trunk/fermopoint-for-woocommerce.php

    r1811711 r1895913  
    4343
    4444
    45  * @since             1.3.0
     45 * @since             1.3.1
    4646
    4747
  • fermopoint-for-woocommerce/trunk/function.php

    r1811711 r1895913  
    77
    88
     9
     10
     11
     12
     13
     14
     15
     16
    917// Add scripts to wp_head()
    1018
     19
     20
    1121/*
    1222
     23
     24
    1325add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    1426
     27
     28
    1529 
    1630
     31
     32
    1733function custom_override_checkout_fields( $fields ) {
    1834
     35
     36
    1937    $current_shipping_fermopoint = currentmethodshipping();
    2038
     39
     40
    2141    if ($current_shipping_fermopoint !== false) {
    2242
     43
     44
    2345        add_filter( 'woocommerce_ship_to_different_address_checked', '__return_true' );
    2446
     47
     48
    2549    }
    2650
     51
     52
    2753    return $fields;
    2854
     55
     56
    2957}
    3058
     59
     60
    3161*/
    3262
    3363
    3464
     65
     66
     67
     68
    3569add_action( 'woocommerce_before_order_notes', 'fermopoint_maps_cart' );
    3670
     71
     72
    3773function fermopoint_maps_cart( $checkout ) {
    3874
    39    
     75
     76$array =  array("nickname"=> get_option("FERMOPOINT_ACCOUNT_NICKNAME"), "born_date"=>  get_option("FERMOPOINT_ACCOUNT_BORNDATE"). "T00:00:00");
     77
     78
     79
     80    $verify= callfermopointcurl("/public/users/check",$array);
     81   
     82   
     83    if ($verify){
     84
    4085
    4186    $current_shipping_fermopoint = currentmethodshipping();
    4287
     88
     89
    4390    echo '<div class="fermopointchoise"><h4>' . __('Cerca un punto ritiro Fermo!Point') . '</h4>';
    4491
     92
     93
    4594    echo '<div id="fp-map" style="width: 100%; height: 400px; overflow: hidden;"></div>';
    4695
     96
     97
    4798    echo '<div id="result"></div>';
    4899
    49    
     100
     101
     102   
     103
     104
    50105
    51106    echo woocommerce_form_field( 'idpoint', array(
    52107
     108
     109
    53110        'type'          => 'text',
    54111
     112
     113
    55114        'class'         => array('hidden')
    56115
     116
     117
    57118        ), $checkout->get_value( 'idpoint' ));
    58119
    59    
    60 
    61    
     120
     121
     122   
     123
     124
     125
     126   
     127
     128
    62129
    63130    echo '</div>';
     
    65132
    66133
     134
     135
     136
     137
    67138        echo '<script src="//embed.fermopoint.it/embeds/1.0/jquery/search-map.js?clientId=' . get_option( 'FERMOPOINT_ACCOUNT_ID') . '"></script>';
    68139
     140
     141
    69142        echo '<script>
    70143
     144
     145
    71146            jQuery( function( $ ) {
    72147
     148
     149
    73150                ';
    74151
     152
     153
    75154                if ($current_shipping_fermopoint !== false) {
    76155
     156
     157
    77158                    echo ' $("#woocommerce-shipping-fields").hide();
    78159
     160
     161
    79162                    $(".woocommerce-shipping-fields").hide();
    80163
     164
     165
    81166                    setVisible();';
    82167
     168
     169
    83170                   
    84171
     172
     173
    85174                } else {
    86175
     176
     177
    87178                echo ' $("#woocommerce-shipping-fields").show();
    88179
     180
     181
    89182                    $(".woocommerce-shipping-fields").show();
    90183
     184
     185
    91186                    $(".fermopointchoise").hide();';
    92187
     188
     189
    93190                }
    94191
     192
     193
    95194           
    96195
     196
     197
    97198                echo ' 
    98199
     200
     201
    99202                   
    100203
     204
     205
    101206                   
    102207
     208
     209
    103210                    function setVisible() {
    104211
     212
     213
    105214                       
    106215
     216
     217
    107218                       var $pnlFP = $(".fermopointchoise");
    108219
     220
     221
    109222                        var $fpmap = $pnlFP.find("#fp-map");
    110223
     224
     225
    111226                       
    112227
     228
     229
    113230                        var $result = $pnlFP.find("#result");
    114231
     232
     233
    115234                        var $differentAddress = $("#ship-to-different-address-checkbox");
    116235
     236
     237
    117238                        var $pnlAddress = $(".woocommerce-shipping-fields");
    118239
     240
     241
    119242                       
    120243
     244
     245
    121246                        // reset
    122247
     248
     249
    123250                        $pnlAddress.find("#shipping_first_name").val("");
    124251
     252
     253
    125254                        $pnlAddress.find("#shipping_last_name").val("");
    126255
     256
     257
    127258                        $pnlAddress.find("#shipping_company").val("");
    128259
     260
     261
    129262                        $pnlAddress.find("#shipping_address_1").val("");
    130263
     264
     265
    131266                        $pnlAddress.find("#shipping_postcode").val("");
    132267
     268
     269
    133270                        $pnlAddress.find("#shipping_state").val(null);
    134271
     272
     273
    135274                        $pnlAddress.find("#shipping_city").val("");
    136275
    137    
     276
     277
     278   
     279
     280
    138281
    139282                        var centerAddress = null;
    140283
     284
     285
    141286                        if ($("#billing_address_1").val().length != 0) {
    142287
     288
     289
    143290                            centerAddress = {
    144291
     292
     293
    145294                                s: $("#billing_address_1").val(),
    146295
     296
     297
    147298                                z: $("#billing_postcode").val(),
    148299
     300
     301
    149302                                p: $("#billing_state").val(),
    150303
     304
     305
    151306                                c: $("#billing_city").val()
    152307
     308
     309
    153310                            };
    154311
     312
     313
    155314                        }
    156315
    157    
     316
     317
     318   
     319
     320
    158321
    159322                       
    160323
     324
     325
    161326                            $differentAddress.prop("checked", true);
    162327
     328
     329
    163330                           
    164331
    165    
     332
     333
     334   
     335
     336
    166337
    167338                            $result.html("");
    168339
     340
     341
    169342                            $fpmap.html("");
    170343
    171    
     344
     345
     346   
     347
     348
    172349
    173350                            $fpmap.fpmap({
    174351
     352
     353
    175354                                width: "100%",
    176355
     356
     357
    177358                                height: "400px",
    178359
     360
     361
    179362                                centerAddress: centerAddress,
    180363
     364
     365
    181366                                hideButtons: false,
    182367
     368
     369
    183370                                success: function (p) {
    184371
     372
     373
    185374                                    console.log(p.id);
    186375
     376
     377
    187378                                    $pnlAddress.find("#shipping_first_name").val("Ospite");
    188379
     380
     381
    189382                                    $pnlAddress.find("#shipping_last_name").val(p.n + " - FP");
    190383
     384
     385
    191386                                    $pnlAddress.find("#shipping_company").val();
    192387
     388
     389
    193390                                    $pnlAddress.find("#shipping_address_1").val(p.a.s);
    194391
     392
     393
    195394                                    $pnlAddress.find("#shipping_postcode").val(p.a.z);
    196395
     396
     397
    197398                                    $pnlAddress.find("#shipping_state").val(p.a.p);
    198399
     400
     401
    199402                                    $pnlAddress.find("#shipping_city").val(p.a.c);
    200403
     404
     405
    201406                                   
    202407
     408
     409
    203410                                    jQuery("#idpoint").val(p.id);
    204411
     412
     413
    205414                                   
     415
    206416                                    $result.html("<b>Fermo!Point Selezionato: </b>" + p.n + "<br/>" + p.a.s + " " + p.a.c + " (" + p.a.c + ") " + p.a.z);
    207417
     418
     419
    208420                                },
    209421
     422
     423
    210424                                error: function (err) {
    211425
     426
     427
    212428                                    alert("ERROR: "+ err);
    213429
     430
     431
    214432                                }
    215433
     434
     435
    216436                            });
    217437
     438
     439
    218440                       
    219441
     442
     443
    220444                    };
    221445
    222    
    223 
    224    
     446
     447
     448   
     449
     450
     451
     452   
     453
     454
    225455
    226456                    $(document).on("change", "#shipping_method input:radio", function() {   
    227457
     458
     459
    228460                        val = $(this).val();
    229461
     462
     463
    230464                        console.log(val);
    231465
     466
     467
    232468                        if (val.indexOf("Fermo!Point") >= 0) {
    233469
     470
     471
    234472                            $("#woocommerce-shipping-fields").hide();
    235473
     474
     475
    236476                            $(".woocommerce-shipping-fields").hide();
    237477
     478
     479
    238480                            $(".fermopointchoise").show();
    239481
     482
     483
    240484                            setVisible();
    241485
     486
     487
    242488                        } else {
    243489
     490
     491
    244492                            // reset
    245493
     494
     495
    246496                            var $pnlAddress = $(".woocommerce-shipping-fields");
    247497
     498
     499
    248500                            $pnlAddress.find("#shipping_first_name").val("");
    249501
     502
     503
    250504                            $pnlAddress.find("#shipping_last_name").val("");
    251505
     506
     507
    252508                            $pnlAddress.find("#shipping_company").val("");
    253509
     510
     511
    254512                            $pnlAddress.find("#shipping_address_1").val("");
    255513
     514
     515
    256516                            $pnlAddress.find("#shipping_postcode").val("");
    257517
     518
     519
    258520                            $("#idpoint").val("");
    259521
     522
     523
    260524                            $pnlAddress.find("#shipping_state").val(null);
    261525
     526
     527
    262528                            $pnlAddress.find("#shipping_city").val("");
    263529
     530
     531
    264532                            $("#woocommerce-shipping-fields").show();
    265533
     534
     535
    266536                            $(".woocommerce-shipping-fields").show();
    267537
     538
     539
    268540                            $(".fermopointchoise").hide();
    269541
     542
     543
    270544                        }
    271545
     546
     547
    272548                    });
    273549
     550
     551
    274552                   
    275553
     554
     555
    276556                   
    277557
     558
     559
    278560                   
    279561
     562
     563
    280564               
    281565
     566
     567
    282568           
    283569
     570
     571
    284572            });
    285573
     574
     575
    286576        </script>';
    287577
     578
     579
    288580        //$return = fp_curl_call("/points/search");
    289581
     582
     583
    290584        //var_dump ($return);
    291585
     
    294588
    295589
    296    
     590
     591
     592
     593    } else {
     594       
     595       
     596        echo "  <div class='notice notice-error'><h2>Fermo!Point non avviato,  impostazioni del negozio non corrette. Scegliere un altro metodo di spedizioni. Ci scusiamo per il disagio.</h2></div>";
     597   
     598    }
     599
     600
     601   
     602
     603
    297604
    298605}
     
    300607
    301608
     609
     610
     611
     612
    302613function currentmethodshipping(){
    303614
     615
     616
    304617    $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
    305618
     619
     620
    306621    $method_shipping = $chosen_shipping_methods[0];
    307622
     623
     624
    308625    return strpos($method_shipping, 'Fermo!Point');
    309626
     627
     628
    310629}
    311630
     
    314633
    315634
     635
     636
     637
     638
     639
     640
    316641function callfermopointcurl($url,$array){
    317642
    318    
     643
     644
     645   
     646
     647
    319648
    320649    $url = API_SERVER_PRODUCTION . $url;
    321650
     651
     652
    322653    $account_id = get_option("FERMOPOINT_ACCOUNT_ID");
    323654
     655
     656
    324657    $account_secret = get_option("FERMOPOINT_ACCOUNT_SECRET");
    325658
     659
     660
    326661    $ts = gmdate('Y-m-d\TH:i:s.u\Z');
    327662
     663
     664
    328665    $auth_token = hash_hmac("sha256", (string) $ts, (string) $account_id . $account_secret, false);
    329666
    330    
    331 
    332    
     667
     668
     669   
     670
     671
     672
     673   
     674
     675
    333676
    334677    if (is_array($array)){
    335678
     679
     680
    336681        $request = $array;
    337682
     683
     684
    338685    } else{
    339686
     687
     688
    340689        if ($array=="base"){
    341690
     691
     692
    342693            $request = array(
    343694
     695
     696
    344697                "client_id" => $account_id,
    345698
     699
     700
    346701                "auth_token" =>$auth_token,
    347702
     703
     704
    348705                "ts" => $ts,
    349706
     707
     708
    350709            );
    351710
     711
     712
    352713        } else {
    353714
     715
     716
    354717            $request ="";
    355718
     719
     720
    356721        }
    357722
     723
     724
    358725       
    359726
     727
     728
    360729    }
    361730
    362    
     731
     732
     733   
     734
     735
    363736
    364737    $httpHeader = array(
    365738
     739
     740
    366741    "Content-Type: application/json; charset=\"utf-8\"",
    367742
     743
     744
    368745    "Accept: text/json"
    369746
     747
     748
    370749    );
    371750
    372    
     751
     752
     753   
     754
     755
    373756
    374757    $ch = curl_init();
     
    376759
    377760
     761
     762
     763
     764
    378765    curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
    379766
     767
     768
    380769    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
    381770
     771
     772
    382773    curl_setopt($ch, CURLOPT_URL, $url );
    383774
    384    
     775
     776
     777   
     778
     779
    385780
    386781    if (is_array($request)){
    387782
     783
     784
    388785        curl_setopt($ch, CURLOPT_POST, 1);
    389786
     787
     788
    390789        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request) );
    391790
     791
     792
    392793    }
    393794
     795
     796
    394797    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    395798
     799
     800
    396801    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    397802
     803
     804
    398805    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    399806
    400807
    401808
     809
     810
     811
     812
    402813    $result = curl_exec($ch);
    403814
     815
     816
    404817    $info = curl_getinfo($ch);
    405818
     819
     820
    406821    if (!isset($info['http_code'])) {
    407822
     823
     824
    408825        $info['http_code'] = '';
    409826
     827
     828
    410829    }
    411830
    412831
    413832
     833
     834
     835
     836
    414837    if (curl_errno($ch)) {
    415838
     839
     840
    416841        $result= array(
    417842
     843
     844
    418845        'http_code' => $info['http_code'],
    419846
     847
     848
    420849        'status' => 'ERROR1',
    421850
     851
     852
    422853        'errno' => $curl_errno,
    423854
     855
     856
    424857        'error' => $curl_error,
    425858
     859
     860
    426861        'result' => NULL
    427862
     863
     864
    428865        );
    429866
     867
     868
    430869       
    431870
     871
     872
    432873    } else {
    433874
     875
     876
    434877        $ret = json_decode($result);
    435878
     879
     880
    436881    }   
    437882
    438883
    439884
     885
     886
     887
     888
    440889    return $ret;
    441890
     891
     892
    442893    curl_close($ch);
    443894
     895
     896
    444897}
    445898
    446899
    447900
     901
     902
     903
     904
    448905?>
Note: See TracChangeset for help on using the changeset viewer.