Plugin Directory

Changeset 3426105


Ignore:
Timestamp:
12/23/2025 10:48:06 AM (3 months ago)
Author:
torod
Message:

Update the plugin with short address field

Location:
torod
Files:
402 added
4 edited

Legend:

Unmodified
Added
Removed
  • torod/trunk/inc/torod.php

    r3287763 r3426105  
    536536                $this->plugin_log("order_create_torod send custom order status " . $order->get_Status() . " gönderildi ");
    537537            }
     538            $short_address = $order->get_meta('_torod_short_address') ? $order->get_meta('_torod_short_address') : '';
    538539            if ($issetStatusOrder) {
    539540                $country_code = "";
     
    610611                            "address" => $address,
    611612                            "reference_id" => $id,
     613                            "short_address" => $short_address,
    612614                        ];
    613615                        $returndata = $this->order_create($data);
     
    902904                    }
    903905                    $country_data = $this->getCountryEnableData($country_code);
    904 
     906                    $short_address = $order->get_meta('_torod_short_address') ? $order->get_meta('_torod_short_address') : '';
    905907                    if ($country_data["is_country_enable"]) {
    906908                        if ($order->get_billing_address_1() != $order->get_shipping_address_1()) {
     
    974976                                "address" => $address,
    975977                                "order_id" => $id,
     978                                "short_address" => $short_address,
    976979                            ];
    977980                            $returndata = $this->update_order($data);
  • torod/trunk/readme.md

    r3410767 r3426105  
    55Tested up to: 6.9
    66Requires PHP: 7
    7 Stable tag: 2.0
     7Stable tag: 2.1
    88License: MIT
    99License URI: https://opensource.org/licenses/MIT
  • torod/trunk/readme.txt

    r3410767 r3426105  
    55Tested up to: 6.9
    66Requires PHP: 7
    7 Stable tag: 2.0
     7Stable tag: 2.1
    88License: MIT
    99License URI: https://opensource.org/licenses/MIT
  • torod/trunk/torod-mmar.php

    r3410767 r3426105  
    55Plugin URI: https://torod.co
    66Description: A web platform that enables you to compare shipping prices, print shipping labels, track orders, and manage returns from a single place. No Contracting, no coding required.
    7 Version: 2.0
     7Version: 2.1
    88Author: Torod Holding LTD
    99Text Domain: torod
     
    241241if ($torod->checkuser()) {
    242242    require_once plugin_dir_path(__FILE__) . 'inc/adress.php';
     243    require_once plugin_dir_path(__FILE__) . '/inc/torod_short_address.php';
    243244}
    244245
     
    292293    $torod->updateDataFromApi();
    293294}
     295/* ---------------------------- Synced Orders Count - START ---------------------------- */
     296add_action( 'rest_api_init', function () {
     297
     298    register_rest_route( 'torod/v1', '/synced-orders-count', array(
     299        'methods'  => 'GET',
     300        'callback' => 'torod_get_synced_orders_count',
     301        'permission_callback' => 'torod_authenticate_request',
     302    ) );
     303
     304});
     305 function torod_authenticate_request( WP_REST_Request $request ) {
     306
     307    $settings = get_option( 'torod_wp_all_settings' );
     308
     309    if (
     310        empty( $settings['client_id'] ) ||
     311        empty( $settings['client_secret'] )
     312    ) {
     313        return new WP_Error(
     314            'torod_config_missing',
     315            'API credentials are not configured',
     316            array( 'status' => 403 )
     317        );
     318    }
     319
     320    // Read headers
     321    $client_id     = $request->get_header( 'x-client-id' );
     322    $client_secret = $request->get_header( 'x-client-secret' );
     323
     324    if ( empty( $client_id ) || empty( $client_secret ) ) {
     325        return new WP_Error(
     326            'torod_headers_missing',
     327            'Authentication headers are missing',
     328            array( 'status' => 401 )
     329        );
     330    }
     331
     332    if (
     333        $client_id !== $settings['client_id'] ||
     334        $client_secret !== $settings['client_secret']
     335    ) {
     336        return new WP_Error(
     337            'torod_auth_failed',
     338            'Invalid API credentials',
     339            array( 'status' => 401 )
     340        );
     341    }
     342
     343    return true; // ✅ Authorized
     344}
     345function torod_get_synced_orders_count( WP_REST_Request $request ) {
     346    /* Check woocommerce is installed or not */
     347if ( ! class_exists( 'WooCommerce' ) ) {
     348    return array(
     349        'success' => false,
     350        'count'   => 0,
     351        'message' => 'WooCommerce not active',
     352    );
     353}
     354
     355/* Date range handling  */
     356$from = $request->get_param( 'from' );
     357$to   = $request->get_param( 'to' );
     358
     359/* Default fallback */
     360if ( empty( $from ) || empty( $to ) ) {
     361    $from = date( 'Y-m-01 00:00:00' );
     362    $to   = current_time( 'mysql' );
     363}
     364
     365/* Order query */
     366$count = 0;
     367$orders = wc_get_orders( array(
     368    'limit'      => -1,
     369    'status'     => array_keys( wc_get_order_statuses() ),
     370    'date_query' => array(
     371        array(
     372            'after'     => $from,
     373            'before'    => $to,
     374            'inclusive' => true,
     375        ),
     376    ),
     377));
     378
     379foreach ( $orders as $order ) {
     380    $torod_id = get_post_meta( $order->get_id(), 'torod_order_id', true );
     381    if ( ! empty( $torod_id ) ) {
     382        $count++;
     383    }
     384}
     385
     386return rest_ensure_response(array(
     387    'success' => true,
     388    'count'   => $count,
     389    'from'    => $from,
     390    'to'      => $to,
     391));
     392}
Note: See TracChangeset for help on using the changeset viewer.