From 4fc7b4a0785e603b7189e378371f1ad22e342185 Mon Sep 17 00:00:00 2001 From: Jacek Pyziak Date: Wed, 4 Dec 2024 10:54:24 +0100 Subject: [PATCH] =?UTF-8?q?Zmieniono=20logik=C4=99=20przetwarzania=20zam?= =?UTF-8?q?=C3=B3wie=C5=84=20w=20cron.php,=20aby=20pobiera=C4=87=20i=20akt?= =?UTF-8?q?ualizowa=C4=87=20statusy=20dla=20wielu=20zam=C3=B3wie=C5=84=20j?= =?UTF-8?q?ednocze=C5=9Bnie,=20poprawiaj=C4=85c=20efektywno=C5=9B=C4=87=20?= =?UTF-8?q?synchronizacji.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cron.php | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/cron.php b/cron.php index d930e37..06e3d1b 100644 --- a/cron.php +++ b/cron.php @@ -674,30 +674,33 @@ if ( $apilo_settings['enabled'] and $apilo_settings['sync_orders'] and $apilo_se // sprawdzanie statusów zamówień w apilo.com jeżeli zamówienie nie jest zrealizowane, anulowane lub nieodebrane if ( $apilo_settings['enabled'] and $apilo_settings['sync_orders'] and $apilo_settings['access-token'] and $apilo_settings['sync_orders_date_start'] <= date( 'Y-m-d H:i:s' ) ) { - $order = $mdb -> query( 'SELECT id, apilo_order_id, apilo_order_status_date, number FROM pp_shop_orders WHERE apilo_order_id IS NOT NULL AND ( status != 6 AND status != 8 AND status != 9 ) AND ( apilo_order_status_date IS NULL OR apilo_order_status_date <= \'' . date( 'Y-m-d H:i:s', strtotime( '-30 minutes', time() ) ) . '\' ) ORDER BY apilo_order_status_date ASC LIMIT 1' ) -> fetch( \PDO::FETCH_ASSOC ); - if ( $order['apilo_order_id'] ) + $orders = $mdb -> query( 'SELECT id, apilo_order_id, apilo_order_status_date, number FROM pp_shop_orders WHERE apilo_order_id IS NOT NULL AND ( status != 6 AND status != 8 AND status != 9 ) AND ( apilo_order_status_date IS NULL OR apilo_order_status_date <= \'' . date( 'Y-m-d H:i:s', strtotime( '-10 minutes', time() ) ) . '\' ) ORDER BY apilo_order_status_date ASC LIMIT 5' ) -> fetchAll( \PDO::FETCH_ASSOC ); + foreach ( $orders as $order ) { - $access_token = \admin\factory\Integrations::apilo_get_access_token(); - $url = 'https://projectpro.apilo.com/rest/api/orders/' . $order['apilo_order_id'] . '/'; - - $ch = curl_init( $url ); - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); - curl_setopt( $ch, CURLOPT_HTTPHEADER, [ - "Authorization: Bearer " . $access_token, - "Accept: application/json" - ] ); - - $response = curl_exec( $ch ); - $responseData = json_decode( $response, true ); - - if ( $responseData['id'] and $responseData['status'] ) + if ( $order['apilo_order_id'] ) { - $shop_status_id = \front\factory\ShopStatuses::get_shop_status_by_integration_status_id( 'apilo', $responseData['status'] ); + $access_token = \admin\factory\Integrations::apilo_get_access_token(); + $url = 'https://projectpro.apilo.com/rest/api/orders/' . $order['apilo_order_id'] . '/'; - $order_tmp = new Order( $order['id'] ); - $order_tmp -> update_status( $shop_status_id, false ); - $order_tmp -> update_aplio_order_status_date( date( 'Y-m-d H:i:s' ) ); - echo '

Zaktualizowałem status zamówienia ' . $order['number'] . '

'; + $ch = curl_init( $url ); + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $ch, CURLOPT_HTTPHEADER, [ + "Authorization: Bearer " . $access_token, + "Accept: application/json" + ] ); + + $response = curl_exec( $ch ); + $responseData = json_decode( $response, true ); + + if ( $responseData['id'] and $responseData['status'] ) + { + $shop_status_id = \front\factory\ShopStatuses::get_shop_status_by_integration_status_id( 'apilo', $responseData['status'] ); + + $order_tmp = new Order( $order['id'] ); + $order_tmp -> update_status( $shop_status_id, false ); + $order_tmp -> update_aplio_order_status_date( date( 'Y-m-d H:i:s' ) ); + echo '

Zaktualizowałem status zamówienia ' . $order['number'] . '

'; + } } } }