Plugin Directory

Changeset 2409719


Ignore:
Timestamp:
10/30/2020 12:10:16 PM (5 years ago)
Author:
hfddev
Message:

הוספת אפשרות לסנכרון מיידי של הזמנות ללא צורך בפעולה כל פעם

Location:
hfd-integration/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • hfd-integration/trunk/class/Admin.php

    r2393139 r2409719  
    6262        $cancel_shipment_url = get_option( 'betanet_epost_hfd_cancel_shipment_url' );
    6363        $print_label_url = get_option( 'betanet_epost_hfd_print_label_url' );
     64        $hfd_order_auto_sync = get_option( 'hfd_order_auto_sync' );
    6465        if( empty( $track_shipment_url ) ){
    6566            update_option( 'betanet_epost_hfd_track_shipment_url', 'https://run.hfd.co.il/RunCom.Server/Request.aspx?APPNAME=run&PRGNAME=ship_locate_random&ARGUMENTS=-A{RAND}' );
     
    7071        if( empty( $print_label_url ) ){
    7172            update_option( 'betanet_epost_hfd_print_label_url', 'https://run.hfd.co.il/RunCom.Server/Request.aspx?APPNAME=run&PRGNAME=ship_print_ws&ARGUMENTS=-N{RAND}' );
     73        }
     74        if( empty( $hfd_order_auto_sync ) ){
     75            update_option( 'hfd_order_auto_sync', 'no' );
    7276        }
    7377    }
     
    327331                'betanet_epost_hfd_sender_name',
    328332                'betanet_epost_hfd_customer_number',
    329                 'betanet_epost_hfd_debug'
     333                'betanet_epost_hfd_debug',
     334                'hfd_order_auto_sync',
     335                'hfd_auto_sync_status',
     336                'hfd_auto_sync_time'
    330337            );
    331338
  • hfd-integration/trunk/class/App.php

    r2393139 r2409719  
    6666        //flush reqrite rules
    6767        add_filter( 'admin_init', array( $this, 'flushRewriteUrls' ) );
    68     }
     68       
     69        //add wordpress ron for auto sync
     70        add_filter( 'cron_schedules', array( $this, 'hfdAutoSyncOrderCron' ) );
     71       
     72        add_action( 'hfd_schedule_auto_sync', array( $this, 'hfdScheduleAutoSyncOrder' ) );
     73       
     74        // Schedule an action if it's not already scheduled
     75        if( !wp_next_scheduled( 'hfd_schedule_auto_sync' ) ){
     76            wp_schedule_event( time(), 'hfd_auto_sync', 'hfd_schedule_auto_sync' );
     77        }
     78    }
     79   
     80    public function hfdScheduleAutoSyncOrder(){
     81        $hfd_auto_sync_time = get_option( 'hfd_auto_sync_time' );
     82        $hfd_auto_sync_status = get_option( 'hfd_auto_sync_status' );
     83       
     84        if( empty( $hfd_auto_sync_time ) || empty( $hfd_auto_sync_status ) )
     85            return;
     86       
     87        $orderIds = get_posts( array(
     88            'numberposts' => - 1,
     89            'post_type'   => array( 'shop_order' ),
     90            'post_status' => array( $hfd_auto_sync_status ),
     91            'date_query' => array(
     92                'after' => date( 'Y-m-d H:i:s', strtotime( '-'.$hfd_auto_sync_time.' minutes' ) ),
     93                'before' => date( 'Y-m-d H:i:s', time() )
     94            ),
     95            'meta_query' => array(
     96                array(
     97                    'key' => 'hfd_ship_number',
     98                    'compare' => 'NOT EXISTS' // this should work...
     99                )
     100            ),
     101            'fields' => 'ids'
     102        ) );
     103       
     104        if( $orderIds ){
     105            /* @var \Hfd\Woocommerce\Helper\Hfd $hfdHelper */
     106            $hfdHelper = Container::create('Hfd\Woocommerce\Helper\Hfd');
     107            $result = $hfdHelper->sendOrders( $orderIds );
     108            $filesystem = Container::get('Hfd\Woocommerce\Filesystem');
     109            $filesystem->writeSession( serialize($result), 'sync_to_hfd' );
     110        }
     111    }
     112   
     113    public function hfdAutoSyncOrderCron( $schedules ){
     114        $hfd_auto_sync_time = get_option( 'hfd_auto_sync_time' );
     115        $hfd_order_auto_sync = get_option( 'hfd_order_auto_sync' );
     116        if( !empty( $hfd_auto_sync_time ) && $hfd_order_auto_sync == "yes" ){
     117            $schedules['hfd_auto_sync'] = array(
     118                'interval'  => 60,
     119                'display'   => sprintf( __( 'Every %s Minute', HFD_WC_EPOST ), 1 )
     120            );
     121        }
     122        return $schedules;
     123    }
    69124   
    70125    public function flushRewriteUrls(){
  • hfd-integration/trunk/class/Setting.php

    r2393139 r2409719  
    4545            'betanet_epost_hfd_track_shipment_url' => 'https://run.hfd.co.il/RunCom.Server/Request.aspx?APPNAME=run&PRGNAME=ship_locate_random&ARGUMENTS=-A{RAND}',
    4646            'betanet_epost_hfd_cancel_shipment_url' => 'https://run.hfd.co.il/RunCom.Server/Request.aspx?APPNAME=run&PRGNAME=bitul_mishloah&ARGUMENTS=-A{shipping_number},-A,-A,-A,-N',
    47             'betanet_epost_hfd_print_label_url' => 'https://run.hfd.co.il/RunCom.Server/Request.aspx?APPNAME=run&PRGNAME=ship_print_ws&ARGUMENTS=-N{RAND}'
     47            'betanet_epost_hfd_print_label_url' => 'https://run.hfd.co.il/RunCom.Server/Request.aspx?APPNAME=run&PRGNAME=ship_print_ws&ARGUMENTS=-N{RAND}',
     48            'hfd_order_auto_sync' => 'no',
    4849        );
    4950
  • hfd-integration/trunk/hfd-woocommerce-epost.php

    r2393145 r2409719  
    44Plugin URI:
    55Description: Add shipping method of ePost, allowing the user on the checkout, to select the pickup location point from a google map popup. Also allows to synch the order to HFD API after the order is created.
    6 Version: 1.1.0
     6Version: 1.2.0
    77Author: HFD
    88Author URI: https://www.hfd.co.il
  • hfd-integration/trunk/readme.txt

    r2393145 r2409719  
    7575
    7676== Changelog ==
     77= 1.2 =
     78* הוספת אפשרות לסנכרון מיידי של הזמנות ללא צורך בפעולה כל פעם
    7779= 1.1 =
    7880* Bug fixes
  • hfd-integration/trunk/templates/admin/setting.php

    r2393139 r2409719  
    66 */
    77/* @var \Hfd\Woocommerce\Setting $setting */
     8
     9$order_auto_sync = $setting->get( 'hfd_order_auto_sync' );
     10$hfd_auto_sync_status = $setting->get( 'hfd_auto_sync_status' );
     11$hfd_auto_sync_time = $setting->get( 'hfd_auto_sync_time' );
     12if( empty( $order_auto_sync ) ){
     13    $order_auto_sync = 'no';
     14}
    815?>
    916<div id="ch2pho-general" class="wrap">
     
    105112                    </td>
    106113                </tr>
     114                <tr valign="top">
     115                    <th scope="row"><?php _e('Order auto sync', HFD_WC_EPOST); ?></th>
     116                    <td>
     117                        <div>
     118                            <input type="radio" name="hfd_order_auto_sync" value="yes" <?php checked( $order_auto_sync, 'yes' ); ?> /> <?php _e( 'Yes', HFD_WC_EPOST ); ?>
     119                        </div>
     120                        <div>
     121                            <input type="radio" name="hfd_order_auto_sync" value="no" <?php checked( $order_auto_sync, 'no' ); ?> /> <?php _e( 'No', HFD_WC_EPOST ); ?>
     122                        </div>
     123                    </td>
     124                </tr>
     125                <tr valign="top">
     126                    <th scope="row"><?php _e('Auto sync status', HFD_WC_EPOST); ?></th>
     127                    <td>
     128                        <select name="hfd_auto_sync_status" class="regular-text">
     129                            <option value=""><?php _e( '--Select--', HFD_WC_EPOST ); ?></option>
     130                            <?php
     131                            if( function_exists( 'wc_get_order_statuses' ) ){
     132                                $statuses = wc_get_order_statuses();
     133                                if( $statuses ){
     134                                    foreach( $statuses as $statusCode => $status ){
     135                                        echo '<option value="'.$statusCode.'" ';
     136                                        echo selected( $hfd_auto_sync_status, $statusCode );
     137                                        echo '>'.$status.'</option>';
     138                                    }
     139                                }
     140                            }
     141                            ?>
     142                        </select>
     143                    </td>
     144                </tr>
     145                <tr valign="top">
     146                    <th scope="row"><?php _e( 'Auto sync time', HFD_WC_EPOST ); ?></th>
     147                    <td>
     148                        <select name="hfd_auto_sync_time" class="regular-text">
     149                            <option value=""><?php _e( '--Select--', HFD_WC_EPOST ); ?></option>
     150                            <option value="15" <?php selected( $hfd_auto_sync_time, 15 ); ?>>15</option>
     151                            <option value="30" <?php selected( $hfd_auto_sync_time, 30 ); ?>>30</option>
     152                            <option value="60" <?php selected( $hfd_auto_sync_time, 60 ); ?>>60</option>
     153                        </select>
     154                    </td>
     155                </tr>
    107156            </tbody>
    108157        </table>
Note: See TracChangeset for help on using the changeset viewer.