Dodano obsługę duplikatów zamówień w Apilo oraz zaktualizowano dokumentację i wersję do 0.236
This commit is contained in:
66
cron.php
66
cron.php
@@ -672,14 +672,66 @@ if ( $apilo_settings['enabled'] and $apilo_settings['sync_orders'] and $apilo_se
|
||||
}
|
||||
elseif ( $response['message'] == 'Validation error' )
|
||||
{
|
||||
echo '<pre>';
|
||||
echo print_r( $response, true );
|
||||
echo print_r( $postData, true );
|
||||
echo '</pre>';
|
||||
// sprawdzanie czy błąd dotyczy duplikatu idExternal
|
||||
$is_duplicate_idexternal = false;
|
||||
if ( isset( $response['errors'] ) and is_array( $response['errors'] ) )
|
||||
{
|
||||
foreach ( $response['errors'] as $error )
|
||||
{
|
||||
if ( isset( $error['field'] ) and $error['field'] == 'idExternal' and
|
||||
( strpos( $error['message'], 'już wykorzystywana' ) !== false or
|
||||
strpos( $error['message'], 'already' ) !== false ) )
|
||||
{
|
||||
$is_duplicate_idexternal = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$email_data = print_r( $response, true );
|
||||
$email_data .= print_r( $postData, true );
|
||||
\S::send_email( 'biuro@project-pro.pl', 'Błąd wysyłania zamówienia do apilo.com', $email_data );
|
||||
if ( $is_duplicate_idexternal )
|
||||
{
|
||||
// próba pobrania zamówienia z Apilo na podstawie idExternal
|
||||
$ch_get = curl_init();
|
||||
curl_setopt( $ch_get, CURLOPT_URL, "https://projectpro.apilo.com/rest/api/orders/?idExternal=" . $order['id'] );
|
||||
curl_setopt( $ch_get, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch_get, CURLOPT_HTTPHEADER, array(
|
||||
"Authorization: Bearer " . $access_token,
|
||||
"Accept: application/json"
|
||||
));
|
||||
$get_response = curl_exec( $ch_get );
|
||||
curl_close( $ch_get );
|
||||
|
||||
$get_response_data = json_decode( $get_response, true );
|
||||
|
||||
if ( isset( $get_response_data['list'] ) and count( $get_response_data['list'] ) > 0 )
|
||||
{
|
||||
$apilo_order_id = $get_response_data['list'][0]['id'];
|
||||
$mdb -> update( 'pp_shop_orders', [ 'apilo_order_id' => $apilo_order_id ], [ 'id' => $order['id'] ] );
|
||||
echo '<p>Zamówienie już istnieje w Apilo. Zaktualizowano ID zamówienia: ' . $apilo_order_id . '</p>';
|
||||
}
|
||||
else
|
||||
{
|
||||
echo '<pre>';
|
||||
echo print_r( $response, true );
|
||||
echo print_r( $postData, true );
|
||||
echo '</pre>';
|
||||
|
||||
$email_data = print_r( $response, true );
|
||||
$email_data .= print_r( $postData, true );
|
||||
\S::send_email( 'biuro@project-pro.pl', 'Błąd wysyłania zamówienia do apilo.com - nie znaleziono zamówienia', $email_data );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo '<pre>';
|
||||
echo print_r( $response, true );
|
||||
echo print_r( $postData, true );
|
||||
echo '</pre>';
|
||||
|
||||
$email_data = print_r( $response, true );
|
||||
$email_data .= print_r( $postData, true );
|
||||
\S::send_email( 'biuro@project-pro.pl', 'Błąd wysyłania zamówienia do apilo.com', $email_data );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user