Zmieniono logikę przetwarzania zamówień w cron.php, aby pobierać i aktualizować statusy dla wielu zamówień jednocześnie, poprawiając efektywność synchronizacji.

This commit is contained in:
2024-12-04 10:54:24 +01:00
parent 7a4cb842ff
commit 4fc7b4a078

View File

@@ -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 '<p>Zaktualizowałem status zamówienia <b>' . $order['number'] . '</b></p>';
$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 '<p>Zaktualizowałem status zamówienia <b>' . $order['number'] . '</b></p>';
}
}
}
}